I gots tachometer :3c

This commit is contained in:
XANTRONIX Development 2023-12-31 22:38:05 -05:00
parent 3236d85ab6
commit f8f12f6341

40
py/hexagram/tacho.py Normal file
View file

@ -0,0 +1,40 @@
import enum
import math
import cairo
from hexagram.dial import Dial
class Tacho(Dial):
MIN_ANGLE = 232.0 * (math.pi / 180.0)
MAX_ANGLE = 488.0 * (math.pi / 180.0)
FONT_FACE = "Muli"
__slots__ = 'units',
def __init__(self, x: float, y: float, radius: float, max_value: float):
super().__init__(x, y, radius, self.MIN_ANGLE, self.MAX_ANGLE, max_value)
def draw_number(self, cr: cairo.Context, radius: float, value: float, text: str):
scale = value / self.max_value
angle = self.min_angle + ((self.max_angle - self.min_angle) * scale) - Dial.ANGLE_OFFSET
cr.set_source_rgb(1, 1, 1)
cr.move_to(self.x + radius * self.radius * math.cos(angle) - 8,
self.y + radius * self.radius * math.sin(angle) + 15)
cr.show_text(text)
cr.stroke()
def draw_bg(self, cr: cairo.Context):
super().draw_bg(cr)
cr.select_font_face(self.FONT_FACE,
cairo.FontSlant.ITALIC,
cairo.FontWeight.BOLD)
cr.set_font_size(self.radius * 0.15)
cr.set_source_rgb(1, 1, 1)
for speed in range(0, int(self.max_value)+1, 1000):
self.draw_number(cr, 0.78, speed, "%d" % int(speed / 1000))