This is a bit better I guess?
This commit is contained in:
parent
305e13d49a
commit
f6af45109f
2 changed files with 41 additions and 12 deletions
|
@ -122,19 +122,10 @@ class Cluster():
|
|||
rpm_max))
|
||||
|
||||
def draw_bg(self, cr: cairo.Context):
|
||||
surface = cairo.RecordingSurface(cairo.Content.COLOR_ALPHA,
|
||||
cairo.Rectangle(0, 0, 100, 88))
|
||||
|
||||
surface_cr = cairo.Context(surface)
|
||||
cr.rectangle(0, 0, self.WIDTH, self.HEIGHT)
|
||||
|
||||
pattern = HexagonPattern()
|
||||
pattern.draw(surface_cr)
|
||||
surface_cr.stroke()
|
||||
|
||||
cr.set_source_surface(surface, 0, 0)
|
||||
cr.get_source().set_extend(cairo.EXTEND_REPEAT)
|
||||
cr.rectangle(0, 0, self.WIDTH, self.HEIGHT)
|
||||
cr.fill()
|
||||
pattern.fill(cr)
|
||||
|
||||
for gauge in self.gauges:
|
||||
gauge.draw_bg(cr)
|
||||
|
|
|
@ -1,6 +1,19 @@
|
|||
import cairo
|
||||
|
||||
from typing import Iterable
|
||||
|
||||
from hexagram.path import Path
|
||||
|
||||
class HexagonPattern(Path):
|
||||
class Pattern(Path):
|
||||
pass
|
||||
|
||||
class HexagonPattern(Pattern):
|
||||
WIDTH = 100
|
||||
HEIGHT = 87
|
||||
COLOR = (0.3, 0.1, 0.3)
|
||||
MATRIX = (0.21213203, 0.21213203, -0.21213203, 0.21213203, 1, 1)
|
||||
MATRIX_SCALE = (4, 4)
|
||||
|
||||
COMMANDS = [
|
||||
['M', [[23.246093, 0],
|
||||
[ 0, 13.382812]]],
|
||||
|
@ -44,3 +57,28 @@ class HexagonPattern(Path):
|
|||
|
||||
def __init__(self):
|
||||
super().__init__(self.COMMANDS)
|
||||
|
||||
def to_surface(self) -> cairo.RecordingSurface:
|
||||
surface = cairo.RecordingSurface(cairo.Content.COLOR_ALPHA,
|
||||
cairo.Rectangle(0, 0, self.WIDTH, self.HEIGHT))
|
||||
|
||||
cr = cairo.Context(surface)
|
||||
cr.set_source_rgb(*self.COLOR)
|
||||
|
||||
self.draw(cr)
|
||||
cr.stroke()
|
||||
|
||||
return surface
|
||||
|
||||
def fill(self, cr: cairo.Context):
|
||||
matrix = cairo.Matrix(*self.MATRIX)
|
||||
matrix.scale(*self.MATRIX_SCALE)
|
||||
|
||||
surface = self.to_surface()
|
||||
cr.set_source_surface(surface, 0, 0)
|
||||
|
||||
source = cr.get_source()
|
||||
source.set_matrix(matrix)
|
||||
source.set_extend(cairo.EXTEND_REPEAT)
|
||||
|
||||
cr.fill()
|
||||
|
|
Loading…
Add table
Reference in a new issue