Sick! A repeating pattern!

This commit is contained in:
XANTRONIX Development 2023-12-29 23:45:46 -05:00
parent 069a492180
commit 305e13d49a

View file

@ -1,10 +1,13 @@
import math
import cairo
from typing import Iterable
from typing import Iterable, List
from hexagram.pattern import HexagonPattern
class Gauge():
pass
def draw_bg(self, cr: cairo.Context):
raise NotImplementedError
class Dial(Gauge):
__slots = 'x', 'y', 'radius',
@ -108,7 +111,7 @@ class Cluster():
__slots__ = 'gauges',
def __init__(self, rpm_redline: float, rpm_max: float):
self.gauges = list()
self.gauges: List[Gauge] = list()
for x in (self.HEIGHT / 2, self.WIDTH - self.HEIGHT / 2):
self.gauges.append(Dial(x, self.HEIGHT / 2, self.HEIGHT / 2))
@ -119,11 +122,19 @@ class Cluster():
rpm_max))
def draw_bg(self, cr: cairo.Context):
cr.set_source_rgb(0, 0, 0)
surface = cairo.RecordingSurface(cairo.Content.COLOR_ALPHA,
cairo.Rectangle(0, 0, 100, 88))
surface_cr = cairo.Context(surface)
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()
for gauge in self.gauges:
gauge.draw_bg(cr)