neiam
/lambent_ex
Lambent Aether 5
public · Issues · Pulls 1 · Labels · Forks · Compare · Actions success · Badges · Packages
⭐
Log in to mark this repository.
Scapes
638b070 · gmorell · 2023-01-02 19:24
Files changed
modified
README.md
+2
−1
@@ -23,9 +23,10 @@ A Reimplementation of Lambent Aether 4, in Elixir
| 23 | 23 | - Rainbow (Cycling/Solid) |
| 24 | 24 | - Chaser (Single, Multi) |
| 25 | 25 | - Rocker |
| 26 | +- Scapes | |
| 26 | 27 | - ##### TODO |
| 28 | +- Firefly | |
| 27 | 29 | - Growth |
| 28 | −- Scapes | |
| 29 | 30 | - Twinkles |
| 30 | 31 | - GSI Receiver |
| 31 | 32 | - FFT Receiver |
modified
lib/lambent_ex/machine/steps/rocker.ex
+29
−29
@@ -14,35 +14,6 @@ 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 | |
| 18 | − def generate_status_hsvs(hues, linger, true) do | |
| 19 | − # dark | |
| 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() | |
| 28 | − end) | |
| 29 | − |> Enum.concat() | |
| 30 | − end | |
| 31 | − | |
| 32 | − def generate_status_hsvs(hues, linger, false) do | |
| 33 | − # light | |
| 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), | |
| 39 | − 255..0 |> Enum.map(fn x -> [h, x, 255] end) | |
| 40 | − ] | |
| 41 | − |> Enum.concat() | |
| 42 | − end) | |
| 43 | − |> Enum.concat() | |
| 44 | − end | |
| 45 | − | |
| 46 | 17 | defp n(opts) do |
| 47 | 18 | "#{@cls}-#{opts[:name]}-#{opts[:id]}" |
| 48 | 19 | end |
@@ -77,4 +48,33 @@ defmodule LambentEx.Machine.Steps.Rocker do
| 77 | 48 | def handle_call(:read, _from, state) do |
| 78 | 49 | {:reply, read(state), state} |
| 79 | 50 | end |
| 51 | + | |
| 52 | + # TODO. pass in the cfg here, destructured to grab the s/v instead of hardcoding 255 | |
| 53 | + def generate_status_hsvs(hues, linger, true) do | |
| 54 | + # dark | |
| 55 | + hues | |
| 56 | + |> Enum.map(fn h -> | |
| 57 | + [ | |
| 58 | + 0..255 |> Enum.map(fn x -> [h, 255, x] end), | |
| 59 | + 0..linger |> Enum.map(fn _x -> [h, 255, 255] end), | |
| 60 | + 255..0 |> Enum.map(fn x -> [h, 255, x] end) | |
| 61 | + ] | |
| 62 | + |> Enum.concat() | |
| 63 | + end) | |
| 64 | + |> Enum.concat() | |
| 65 | + end | |
| 66 | + | |
| 67 | + def generate_status_hsvs(hues, linger, false) do | |
| 68 | + # light | |
| 69 | + hues | |
| 70 | + |> Enum.map(fn h -> | |
| 71 | + [ | |
| 72 | + 0..255 |> Enum.map(fn x -> [h, x, 255] end), | |
| 73 | + 0..linger |> Enum.map(fn _x -> [h, 255, 255] end), | |
| 74 | + 255..0 |> Enum.map(fn x -> [h, x, 255] end) | |
| 75 | + ] | |
| 76 | + |> Enum.concat() | |
| 77 | + end) | |
| 78 | + |> Enum.concat() | |
| 79 | + end | |
| 80 | 80 | end |
added
lib/lambent_ex/machine/steps/scapes.ex
+86
−0
@@ -0,0 +1,86 @@
| 1 | +defmodule LambentEx.Machine.Steps.Scape.Cfg do | |
| 2 | + # @enforce_keys [:h] | |
| 3 | + defstruct h_l: 0, h_h: 128, s: 255, v: 255, id: 0, status: 0, target: 0, hues: [] | |
| 4 | +end | |
| 5 | + | |
| 6 | +defmodule LambentEx.Machine.Steps.Scape do | |
| 7 | + @moduledoc false | |
| 8 | + use GenServer | |
| 9 | + | |
| 10 | + @registry :lambent_steps | |
| 11 | + @cls :scape | |
| 12 | + | |
| 13 | + alias LambentEx.Machine.Steps.Scape.Cfg | |
| 14 | + alias LambentEx.Utils.Color | |
| 15 | + | |
| 16 | + defp n(opts) do | |
| 17 | + "#{@cls}-#{opts[:name]}-#{opts[:id]}" | |
| 18 | + end | |
| 19 | + | |
| 20 | + def start_link(opts) do | |
| 21 | + GenServer.start_link(__MODULE__, opts, name: via_tuple(n(opts))) | |
| 22 | + end | |
| 23 | + | |
| 24 | + def init(opts) do | |
| 25 | + opts = opts |> Map.put(:status, opts.id) | |
| 26 | + cfg = struct(%LambentEx.Machine.Steps.Scape.Cfg{}, opts) | |
| 27 | + hues = generate_hue_range(cfg.h_l, cfg.h_h) | |
| 28 | + | |
| 29 | + {:ok, | |
| 30 | + cfg | |
| 31 | + |> Map.put(:hues, hues) | |
| 32 | + |> Map.put(:target, length(hues) - 1) | |
| 33 | + |> Map.put(:status, Integer.mod(opts.id, length(hues) - 1)) | |
| 34 | + } | |
| 35 | + end | |
| 36 | + | |
| 37 | + defp via_tuple(name) do | |
| 38 | + {:via, Registry, {@registry, name}} | |
| 39 | + end | |
| 40 | + | |
| 41 | + defp read(state) do | |
| 42 | +# if state.id == 0 do | |
| 43 | +# IO.inspect(state.status) | |
| 44 | +# IO.inspect([state.hues |> Enum.at(state.status), state.s, state.v]) | |
| 45 | +# end | |
| 46 | + Color.hsv2rgb([state.hues |> Enum.at(state.status), state.s, state.v]) | |
| 47 | + end | |
| 48 | + | |
| 49 | + defp do_status_step(current, target, size \\ 1) do | |
| 50 | +# IO.inspect({current, target}) | |
| 51 | + if (current - target) |> abs > size do | |
| 52 | + cond do | |
| 53 | + current > target -> current - size | |
| 54 | + current < target -> current + size | |
| 55 | + true -> current | |
| 56 | + end | |
| 57 | + else | |
| 58 | + target | |
| 59 | + end | |
| 60 | + end | |
| 61 | + | |
| 62 | + def handle_cast(:step, state) do | |
| 63 | + state = | |
| 64 | + case state.status == state.target do | |
| 65 | + true -> if state.target == 0 do | |
| 66 | + state |> Map.put(:target, length(state.hues) - 1) | |
| 67 | + else | |
| 68 | + state |> Map.put(:target, 0) | |
| 69 | + end | |
| 70 | + false -> state | |
| 71 | + end | |
| 72 | + |> Map.put(:status, do_status_step(state.status, state.target)) | |
| 73 | + | |
| 74 | + {:noreply, state} | |
| 75 | + end | |
| 76 | + | |
| 77 | + def handle_call(:read, _from, state) do | |
| 78 | + {:reply, read(state), state} | |
| 79 | + end | |
| 80 | + | |
| 81 | + | |
| 82 | + def generate_hue_range(low, high) when low > high, | |
| 83 | + do: Enum.to_list(low..255) ++ Enum.to_list(0..high) |> IO.inspect() | |
| 84 | + def generate_hue_range(low, high), do: low..high |> Enum.to_list() | |
| 85 | + | |
| 86 | +end |
modified
lib/lambent_ex_web/live/links/index.html.heex
+1
−1
@@ -1,4 +1,4 @@
| 1 | −<div class="overflow-x-auto">xx | |
| 1 | +<div class="overflow-x-auto"> | |
| 2 | 2 | <%= if @live_action in [:new, :edit] do %> |
| 3 | 3 | <.modal return_to={~p"/cfg/links"} id="new" |
| 4 | 4 | :if={@live_action in [:new, :edit]} |
Parents: ae63592