-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsource.ait
74 lines (63 loc) · 1.88 KB
/
source.ait
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Load some dependencies
@load ait-canvas ;
@load ait-canvas/node ;
@load ./turtle ;
# Convenience words
deg2rad: PI 180 / * ;
dup2: dupd dup rolldown ;
pop2: pop pop ;
centerCanvas: WMax HMax translate ;
clearCanvas: WMin HMin [] cons cons W H fillRect ;
drawAndSave: clearCanvas exec "images/%s.png" replace writeImage ;
# Parts of various shapes
slices: dup PI 2 * swap / swap ;
edge: turn move ;
polygon: [ dup2 edge ] times pop2 ;
spin: slices [ dup2 turn exec ] times pop2 ;
regpoly: slices polygon ;
triangle: 3 regpoly ;
square: 4 regpoly ;
pentagon: 5 regpoly ;
hexagon: 6 regpoly ;
circle: 36 regpoly ;
star: 144 deg2rad 5 polygon ;
petalArcs: [ dup2 turn move ] times pop2 ;
petal:
2 [
28 6 deg2rad 16 petalArcs
7 -6 deg2rad 16 petalArcs
180 deg2rad turn
] times ;
# The main shapes
shapes: begin [250 -425] go 500 triangle 500 square 500 pentagon 500 hexagon show ;
burst: begin 60 [ PI 30 / _i * head [0 0] go W 2 / move ] times show ;
squaril: begin [-425 -225] go 20 [ 850 move 126 deg2rad turn ] times show ;
spiro: begin [ W 25 / circle ] 15 spin show ;
stars: begin [ W 2 / star ] 3 spin show ;
rose: begin 0 102 [ 5 + dup move 84 deg2rad turn ] times pop show ;
flower: begin [ petal ] 15 spin show ;
spiral: begin 1 [ 750 > ] [] [ 5 + dup move 92 deg2rad turn ] tailrec pop show ;
# Configure canvas
nodeCanvas canvasContext pop
1000 1000 canvasDimensions
"#333" fillStyle
"rgba(255, 255, 255, 0.9)" strokeStyle
3 lineWidth
# Save some convenience vars
canvasWidth ->> W
canvasHeight ->> H
W 2 / ->> WMax
H 2 / ->> HMax
WMax neg ->> WMin
HMax neg ->> HMin
# Begin drawing
centerCanvas
# Draw all of the main shapes and save an image
"shapes" [ shapes ] drawAndSave
"burst" [ burst ] drawAndSave
"squaril" [ squaril ] drawAndSave
"spiro" [ spiro ] drawAndSave
"stars" [ stars ] drawAndSave
"rose" [ rose ] drawAndSave
"flower" [ flower ] drawAndSave
"spiral" [ spiral ] drawAndSave