概要
wsl(wsl2じゃない)で、elixirやってみた。
動きがある、vegalite、やってみた。
写真
セットアップ
Mix.install([
{:vega_lite, "~> 0.1.5"},
{:kino_vega_lite, "~> 0.1.7"},
{:kino, "~> 0.10.0"}
])
サンプルコード
import :math
alias VegaLite, as: Vl
f = fn x ->
:math.sin(x * 2) * :math.cos(x)
end
f.(12)
values = for x <- 1..10000, do: (x / 100)
|> (fn x ->
%{x: x, y: f.(x)}
end).()
Vl.new(width: 720, height: 100)
|> Vl.data_from_values(values)
|> Vl.mark(:line)
|> Vl.encode_field(:x, "x", type: :quantitative, title: "x")
|> Vl.encode_field(:y, "y", type: :quantitative, title: "sin(2x)*cos(x)")
interval = 100
kino = Vl.new(width: 400, height: 400)
|> Vl.mark(:line)
|> Vl.encode_field(:x, "x", type: :quantitative)
|> Vl.encode_field(:y, "y", type: :quantitative)
|> Kino.VegaLite.new()
|> Kino.render()
fun = fn _, {kino, x} ->
Kino.VegaLite.push(kino, %{x: x, y: f.(x)}, window: 100)
{:cont, {kino, x + 0.1}}
end
Kino.listen(interval, {kino, 0}, fun)
以上。