git.s-ol.nu watch-cad / 972a4e8
add input.slider s-ol 15 days ago
2 changed file(s) with 30 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
5050
5151 half_handle = vec2 15, 15
5252 input =
53 slider: (min=0, max=1) =>
54 @init min
55
56 origin = vec2 50, 50
57 length = 200
58 final = origin + vec2 length, 0
59 draw.line origin, final
60
61 if input.point @value, y: origin.y, x: Once min
62 val = math.max origin.x, math.min final.x, @value!.x
63 @value!.x = val
64 @set min + (val - origin.x) / length * max
65 return true
66
5367 point: (fixed={}) =>
54 last = @init random.point!
68 init = if val = is_once fixed
69 val
70 else
71 with random.point!
72 if x = is_once fixed.x
73 .x = x
74 if y = is_once fixed.y
75 .y = y
76 last = @init init
5577 pos = last\clone!
5678
5779 live_x, live_y = (is_live fixed.x), is_live fixed.y
6890
6991 -- handle size (square or rect)
7092 hh = half_handle\clone!
71 hh.x /= 2 if live_x
72 hh.y /= 2 if live_y
93 hh.y /= 2 if live_x
94 hh.x /= 2 if live_y
7395
7496 if 'down' == draw.rect pos - hh, pos + hh
7597 @drag\set true
55 input.circle(S.outer, { center = S.inner().center })
66
77 local inner, outer = S.inner(), S.outer()
8
9 local cnt = 20
8
9 input.slider(S.cnt, 2, 20)
10
11 local cnt = math.floor(S.cnt()) * 2
1012 local step = 2*math.pi/cnt
1113 local lag = inner.center + vec2(inner.radius, 0)
12 for i = 0, 20 do
14 for i = 0, cnt do
1315 local r = (i % 2 == 0) and inner.radius or outer.radius
1416 local pos = inner.center + vec2.from_cartesian(r, step * i)
1517