diff --git a/py/hexagram/__init__.py b/py/hexagram/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/py/hexagram/cluster.py b/py/hexagram/cluster.py new file mode 100644 index 0000000..ca35bfc --- /dev/null +++ b/py/hexagram/cluster.py @@ -0,0 +1,46 @@ +import math +import cairo + +CLUSTER_WIDTH = 1280 +CLUSTER_HEIGHT = 480 + +class Gauge(): + __slots = 'x', 'y', 'radius', + + BEZEL_WIDTH = 16 + + BEZEL_GRADIENT_STOPS = ( + (0, 1.0, 0.4, 1.0, 1.0), + (1, 0.4, 0.0, 0.4, 0.0) + ) + + def __init__(self, x: float, y: float, radius: float): + self.x = x + self.y = y + self.radius = radius + + def _gradient(self): + gradient = cairo.LinearGradient(0, 0, 2 * self.radius, 2 * self.radius) + + for stop in self.BEZEL_GRADIENT_STOPS: + gradient.add_color_stop_rgba(*stop) + + return gradient + + def _draw_face(self, cr: cairo.Context): + arc = (self.radius, + self.radius, + self.radius - self.BEZEL_WIDTH, + 0, + 2.0 * math.pi) + + # Gauge face + cr.set_source_rgba(0, 0, 0, 1) + cr.arc(*arc) + cr.fill() + + # Gauge bezel + cr.set_source(self._gradient()) + cr.set_line_width(self.BEZEL_WIDTH) + cr.arc(*arc) + cr.stroke()