最終更新 1 month ago

spriograph.st Raw Playground
1NB[ Spirograph program, done for comparison between StackTalk, Carousel/Lua and Lisp
2Carousel version by akkartik
3StackTalk version by yumaikas
4]
5me. >Lobby
6#game: Canvas .query-ctx-2d do[
7 %w[ blue grey red ] each[ dup curry[ color= ] fn ]
8] >ctx
9RAF: fn[ Lobby frame. Window .requestAnimationFrame ]
10once: fn[ ts. >oldTs once: drop once: fn[ ] ]
11frame: fn[ once
12 ts. oldTs> - >dt
13 ts> >oldTs
14 draw
15 dt: drop RAF
16] RAF
17
18make-spiro: fn[
19 obj[ >color >r >r2 >rotSpeed
20 200 >x 200 >y 0 >T Canvas .new-path-2d >spiro
21 move-rT: fn[ >d >r >y >x
22 y> d. sin r. * + x> d> cos r> * + ]
23 update: fn[ 1000 div T> + >T ]
24 draw: fn[ >ctx
25 x y r ctx .pen[ grey circle ]
26 x y r T move-rT >x2 >y2
27 x2 y2 5 ctx .brush[ red circle ]
28 x2 y2 r2 ctx .pen[ grey circle ]
29 x2 y2 r2 T rotSpeed * move-rT >x3 >y3
30 x3 y3 x2> y2> ctx .pen[ grey moveTo lineTo ]
31 x3 y3 5 ctx .brush[ blue circle ]
32 color ctx .color=
33 spiro ask[ your[ x3> y3> ] line-to your[ ctx> ] to-canvas ]
34 ]
35 ]
36]
37
38[
395 50 100 red: make-spiro
405.2 35 125 green: make-spiro
4110.4 10 40 yellow: make-spiro
4220 10 110 gold: make-spiro
43
445 50 105 red: make-spiro
455.2 35 130 green: make-spiro
4610.4 10 35 yellow: make-spiro
4720 10 140 gold: make-spiro
48
495.2 55 105 red: make-spiro
505.2 40 130 green: make-spiro
5110.3 15 35 yellow: make-spiro
5230 13 140 gold: make-spiro
53
54] Array .of >gears
55
56draw: fn[
57 #111: ctx .clear
58 gears each[ ask[
59 your[ dt. ] update
60 your[ ctx. ] draw
61 ] ]
62]
63