aboutsummaryrefslogtreecommitdiffstats
path: root/library/create_star.lua
diff options
context:
space:
mode:
Diffstat (limited to 'library/create_star.lua')
-rw-r--r--library/create_star.lua25
1 files changed, 25 insertions, 0 deletions
diff --git a/library/create_star.lua b/library/create_star.lua
new file mode 100644
index 0000000..197180c
--- /dev/null
+++ b/library/create_star.lua
@@ -0,0 +1,25 @@
+local vec2 = (require 'cpml').vec2
+
+function draw_star(S)
+ input.circle(S.inner)
+ input.circle(S.outer, { center = S.inner().center })
+
+ local inner, outer = S.inner(), S.outer()
+
+ 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, cnt do
+ local r = (i % 2 == 0) and inner.radius or outer.radius
+ local pos = inner.center + vec2.from_cartesian(r, step * i)
+
+ op.add(pos, vec2(20, 20))
+ draw.line(pos, lag)
+
+ lag = pos
+ end
+end
+
+return draw_star