Initial commit of Python gauge cluster implementation
This commit is contained in:
parent
bbe6f2cd5c
commit
353ece7390
2 changed files with 46 additions and 0 deletions
0
py/hexagram/__init__.py
Normal file
0
py/hexagram/__init__.py
Normal file
46
py/hexagram/cluster.py
Normal file
46
py/hexagram/cluster.py
Normal file
|
@ -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()
|
Loading…
Add table
Reference in a new issue