git.s-ol.nu alive / editor-support
add vis/rgb s-ol 1 year, 3 months ago
1 changed file(s) with 44 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
0 import Constant, Op, T, Input, sig, evt from require 'alv.base'
0 import Constant, Op, T, Array, Input, sig, evt from require 'alv.base'
11
22 bar = Constant.meta
33 meta:
1616 if not max
1717 min, max = nil, min
1818
19 @out = val.result\fork!
19 @out = if val.result.metatype ~= '!'
20 val\type!\mk_sig!
21 else
22 val\type!\mk_evt!
2023
2124 super
2225 val: Input.hot val
3538 bar: @state
3639 }
3740
41 rgb = Constant.meta
42 meta:
43 name: 'rgb'
44 summary: "visualize an array as an RGB color."
45 examples: { '(vis/rgb val [range])' }
46 description: "
47 Visualizes `val` as an RGB(A) color with each component in range `0 - range`.
48 `val` needs to be a `[3]num~`, `[3]num!`, `[4]num~`, or `[4]num!`.
49 `range` is a `num~` and defaults to `1`."
50
51 value: class extends Op
52 a3 = (Array 3, T.num)
53 a4 = (Array 4, T.num)
54 color = (sig a3) / (sig a4) / (evt a3) / (evt a4)
55 pattern = color + -sig.num
56 setup: (inputs, scope) =>
57 { val, max } = pattern\match inputs
58
59 @out = if val.result.metatype ~= '!'
60 val\type!\mk_sig!
61 else
62 val\type!\mk_evt!
63
64 super
65 val: Input.hot val
66 max: Input.cold max or Constant.num 1
67
68 tick: =>
69 { :val, :max } = @unwrap_all!
70 @out\set val
71 @state = [i/max for i in *val]
72
73 vis: =>
74 {
75 type: 'rgb'
76 rgb: @state
77 }
78
3879 {
3980 :bar
81 :rgb
4082 }