add input.slider
s-ol
3 years ago
49 | 49 |
|
50 | 50 |
half_handle = vec2 15, 15
|
51 | 51 |
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 |
|
52 | 66 |
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
|
54 | 76 |
pos = last\clone!
|
55 | 77 |
|
56 | 78 |
live_x, live_y = (is_live fixed.x), is_live fixed.y
|
|
67 | 89 |
|
68 | 90 |
-- handle size (square or rect)
|
69 | 91 |
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
|
72 | 94 |
|
73 | 95 |
if 'down' == draw.rect pos - hh, pos + hh
|
74 | 96 |
@drag\set true
|
4 | 4 |
input.circle(S.outer, { center = S.inner().center })
|
5 | 5 |
|
6 | 6 |
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
|
9 | 11 |
local step = 2*math.pi/cnt
|
10 | 12 |
local lag = inner.center + vec2(inner.radius, 0)
|
11 | |
for i = 0, 20 do
|
|
13 |
for i = 0, cnt do
|
12 | 14 |
local r = (i % 2 == 0) and inner.radius or outer.radius
|
13 | 15 |
local pos = inner.center + vec2.from_cartesian(r, step * i)
|
14 | 16 |
|