diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2019-11-04 14:55:54 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2019-11-04 14:55:54 +0000 |
| commit | 972a4e8b29bbe47f4c04b18b432e2cbe257472c0 (patch) | |
| tree | d4ed5abcee60d4108becb4e643977014e29f8905 | |
| parent | test is_once and is_live (diff) | |
| download | watch-cad-972a4e8b29bbe47f4c04b18b432e2cbe257472c0.tar.gz watch-cad-972a4e8b29bbe47f4c04b18b432e2cbe257472c0.zip | |
add input.slider
| -rw-r--r-- | api.moon | 28 | ||||
| -rw-r--r-- | examples/create_star.lua | 8 |
2 files changed, 30 insertions, 6 deletions
@@ -50,8 +50,30 @@ draw = half_handle = vec2 15, 15 input = + slider: (min=0, max=1) => + @init min + + origin = vec2 50, 50 + length = 200 + final = origin + vec2 length, 0 + draw.line origin, final + + if input.point @value, y: origin.y, x: Once min + val = math.max origin.x, math.min final.x, @value!.x + @value!.x = val + @set min + (val - origin.x) / length * max + return true + point: (fixed={}) => - last = @init random.point! + init = if val = is_once fixed + val + else + with random.point! + if x = is_once fixed.x + .x = x + if y = is_once fixed.y + .y = y + last = @init init pos = last\clone! live_x, live_y = (is_live fixed.x), is_live fixed.y @@ -68,8 +90,8 @@ input = -- handle size (square or rect) hh = half_handle\clone! - hh.x /= 2 if live_x - hh.y /= 2 if live_y + hh.y /= 2 if live_x + hh.x /= 2 if live_y if 'down' == draw.rect pos - hh, pos + hh @drag\set true diff --git a/examples/create_star.lua b/examples/create_star.lua index 520cf07..078f5df 100644 --- a/examples/create_star.lua +++ b/examples/create_star.lua @@ -5,11 +5,13 @@ function draw_star(S) input.circle(S.outer, { center = S.inner().center }) local inner, outer = S.inner(), S.outer() - - local cnt = 20 + + input.slider(S.cnt, 2, 20) + + local cnt = math.floor(S.cnt()) * 2 local step = 2*math.pi/cnt local lag = inner.center + vec2(inner.radius, 0) - for i = 0, 20 do + for i = 0, cnt do local r = (i % 2 == 0) and inner.radius or outer.radius local pos = inner.center + vec2.from_cartesian(r, step * i) |
