Rocker Support

ae63592 · gmorell · 2023-01-02 16:34

6 files +25 -14

Files changed

modified README.md
+2 −2
@@ -22,9 +22,9 @@ A Reimplementation of Lambent Aether 4, in Elixir
22 22 - Solid (RGB/HSV)
23 23 - Rainbow (Cycling/Solid)
24 24 - Chaser (Single, Multi)
25 +- Rocker
25 26 - ##### TODO
26 27 - Growth
27 −- Rocker
28 28 - Scapes
29 29 - Twinkles
30 30 - GSI Receiver
@@ -36,7 +36,7 @@ A Reimplementation of Lambent Aether 4, in Elixir
36 36 ## Running
37 37 ```
38 38 docker pull lambentri/lambentex
39 −docker run --net=host -d --restart always --mount type=bind,source"$(pwd)"/lex_metadata,target=/opt/app/lex_metadata lambentri/lambentex
39 +docker run --net=host -d --restart always --mount type=bind,source="$(pwd)"/meta,target=/opt/app/meta lambentri/lambentex
40 40 ```
41 41
42 42 Then load host:4000 in your web browser
modified lib/lambent_ex/machine/steps/rocker.ex
+23 −12
@@ -1,6 +1,6 @@
1 1 defmodule LambentEx.Machine.Steps.Rocker.Cfg do
2 2 # @enforce_keys [:h]
3 − defstruct [h: [0, 128], l: 1000, d: true, s: 255, v: 255, id: 0, status: 0, hues: []]
3 + defstruct h: [0, 128], l: 1000, d: true, s: 255, v: 255, id: 0, status: 0, hues: []
4 4 end
5 5
6 6 defmodule LambentEx.Machine.Steps.Rocker do
@@ -14,23 +14,33 @@ defmodule LambentEx.Machine.Steps.Rocker do
14 14 alias LambentEx.Machine.Steps.Rocker.Cfg
15 15 alias LambentEx.Utils.Color
16 16
17 + # TODO. pass in the cfg here, destructured to grab the s/v instead of hardcoding 255
17 18 def generate_status_hsvs(hues, linger, true) do
18 19 # dark
19 − hues |> Enum.map(fn h ->
20 − 0..255 |> Enum.map(fn x -> [h, 255, x] end) ++
21 − 0..linger |> Enum.map(fn x -> [h, 255, 255] end) ++
22 − 255..0 |> Enum.map(fn x -> [h, 255, x] end)
20 + hues
21 + |> Enum.map(fn h ->
22 + [
23 + 0..255 |> Enum.map(fn x -> [h, 255, x] end),
24 + 0..linger |> Enum.map(fn _x -> [h, 255, 255] end),
25 + 255..0 |> Enum.map(fn x -> [h, 255, x] end)
26 + ]
27 + |> Enum.concat()
23 28 end)
24 −
29 + |> Enum.concat()
25 30 end
26 31
27 32 def generate_status_hsvs(hues, linger, false) do
28 33 # light
29 − hues |> Enum.map(fn h ->
30 − 0..255 |> Enum.map(fn x -> [h, x, 255] end) ++
31 − 0..linger |> Enum.map(fn x -> [h, 255, 255] end) ++
34 + hues
35 + |> Enum.map(fn h ->
36 + [
37 + 0..255 |> Enum.map(fn x -> [h, x, 255] end),
38 + 0..linger |> Enum.map(fn _x -> [h, 255, 255] end),
32 39 255..0 |> Enum.map(fn x -> [h, x, 255] end)
40 + ]
41 + |> Enum.concat()
33 42 end)
43 + |> Enum.concat()
34 44 end
35 45
36 46 defp n(opts) do
@@ -44,8 +54,8 @@ defmodule LambentEx.Machine.Steps.Rocker do
44 54 def init(opts) do
45 55 opts = opts |> Map.put(:status, opts.id)
46 56 cfg = struct(%LambentEx.Machine.Steps.Rocker.Cfg{}, opts)
47 − cfg.hues = generate_status_hsvs(cfg.h, cfg.l, cfg.v)
48 − {:ok, cfg}
57 + hues = generate_status_hsvs(cfg.h, cfg.l, cfg.d)
58 + {:ok, %{cfg | hues: hues}}
49 59 end
50 60
51 61 defp via_tuple(name) do
@@ -53,13 +63,14 @@ defmodule LambentEx.Machine.Steps.Rocker do
53 63 end
54 64
55 65 defp read(state) do
56 − Color.hsv2rgb(state.hues |> Enum.at(self.status))
66 + Color.hsv2rgb(state.hues |> Enum.at(state.status))
57 67 end
58 68
59 69 def handle_cast(:step, state) do
60 70 state =
61 71 state
62 72 |> Map.put(:status, (state.status + 1) |> Integer.mod(state.hues |> length))
73 +
63 74 {:noreply, state}
64 75 end
65 76

Parents: 5d0f445