Skip to content
Snippets Groups Projects
Commit b4e138a8 authored by ar's avatar ar Committed by q3k
Browse files

py/nick: support pronouns

parent 21db1238
No related branches found
No related tags found
No related merge requests found
......@@ -13,6 +13,8 @@ class Configuration:
self.name = "flow3r"
self.size: int = 75
self.font: int = 5
self.pronouns: list[str] = []
self.pronouns_size: int = 25
@classmethod
def load(cls, path: str) -> "Configuration":
......@@ -32,6 +34,18 @@ class Configuration:
res.size = data["size"]
if "font" in data and type(data["font"]) == int:
res.font = data["font"]
# type checks don't look inside collections
if (
"pronouns" in data
and type(data["pronouns"]) == list
and set([type(x) for x in data["pronouns"]]) == {str}
):
res.pronouns = data["pronouns"]
if "pronouns_size" in data:
if type(data["pronouns_size"]) == float:
res.pronouns_size = int(data["pronouns_size"])
if type(data["pronouns_size"]) == int:
res.pronouns_size = data["pronouns_size"]
return res
def save(self, path: str) -> None:
......@@ -39,6 +53,8 @@ class Configuration:
"name": self.name,
"size": self.size,
"font": self.font,
"pronouns": self.pronouns,
"pronouns_size": self.pronouns_size,
}
jsondata = json.dumps(d)
with open(path, "w") as f:
......@@ -49,11 +65,13 @@ class Configuration:
class NickApp(Application):
def __init__(self, app_ctx: ApplicationContext) -> None:
super().__init__(app_ctx)
self._scale = 1.0
self._scale_name = 1.0
self._scale_pronouns = 1.0
self._led = 0.0
self._phase = 0.0
self._filename = "/flash/nick.json"
self._config = Configuration.load(self._filename)
self._pronouns_serialized = " ".join(self._config.pronouns)
def draw(self, ctx: Context) -> None:
ctx.text_align = ctx.CENTER
......@@ -66,11 +84,19 @@ class NickApp(Application):
ctx.move_to(0, 0)
ctx.save()
ctx.scale(self._scale, 1)
ctx.scale(self._scale_name, 1)
ctx.text(self._config.name)
ctx.restore()
leds.set_hsv(int(self._led), abs(self._scale) * 360, 1, 0.2)
if self._pronouns_serialized:
ctx.move_to(0, -60)
ctx.font_size = self._config.pronouns_size
ctx.save()
ctx.scale(1, self._scale_pronouns)
ctx.text(self._pronouns_serialized)
ctx.restore()
leds.set_hsv(int(self._led), abs(self._scale_name) * 360, 1, 0.2)
leds.update()
# ctx.fill()
......@@ -82,7 +108,8 @@ class NickApp(Application):
super().think(ins, delta_ms)
self._phase += delta_ms / 1000
self._scale = math.sin(self._phase)
self._scale_name = math.sin(self._phase)
self._scale_pronouns = math.cos(self._phase)
self._led += delta_ms / 45
if self._led >= 40:
self._led = 0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment