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