最后活跃于 1 month ago

yumaikas's Avatar yumaikas 修订了这个 Gist 1 month ago. 转到此修订

1 file changed, 0 insertions, 0 deletions

spriograph.stk 重命名为 spriograph.st

文件已重命名,但内容与之前没有差异

yumaikas's Avatar yumaikas 修订了这个 Gist 1 month ago. 转到此修订

没有任何变更

yumaikas's Avatar yumaikas 修订了这个 Gist 1 month ago. 转到此修订

1 file changed, 62 insertions

spriograph.stk(文件已创建)

@@ -0,0 +1,62 @@
1 + NB[ Spirograph program, done for comparison between StackTalk, Carousel/Lua and Lisp
2 + Carousel version by akkartik
3 + StackTalk version by yumaikas
4 + ]
5 + me. >Lobby
6 + #game: Canvas .query-ctx-2d do[
7 + %w[ blue grey red ] each[ dup curry[ color= ] fn ]
8 + ] >ctx
9 + RAF: fn[ Lobby frame. Window .requestAnimationFrame ]
10 + once: fn[ ts. >oldTs once: drop once: fn[ ] ]
11 + frame: fn[ once
12 + ts. oldTs> - >dt
13 + ts> >oldTs
14 + draw
15 + dt: drop RAF
16 + ] RAF
17 +
18 + make-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 + [
39 + 5 50 100 red: make-spiro
40 + 5.2 35 125 green: make-spiro
41 + 10.4 10 40 yellow: make-spiro
42 + 20 10 110 gold: make-spiro
43 +
44 + 5 50 105 red: make-spiro
45 + 5.2 35 130 green: make-spiro
46 + 10.4 10 35 yellow: make-spiro
47 + 20 10 140 gold: make-spiro
48 +
49 + 5.2 55 105 red: make-spiro
50 + 5.2 40 130 green: make-spiro
51 + 10.3 15 35 yellow: make-spiro
52 + 30 13 140 gold: make-spiro
53 +
54 + ] Array .of >gears
55 +
56 + draw: fn[
57 + #111: ctx .clear
58 + gears each[ ask[
59 + your[ dt. ] update
60 + your[ ctx. ] draw
61 + ] ]
62 + ]
上一页 下一页