-
Notifications
You must be signed in to change notification settings - Fork 9
/
README.txt
202 lines (156 loc) · 7.45 KB
/
README.txt
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
Rose - a programming language for temporal turtle graphics
INTRODUCTION
A Rose program produces an animation drawn by a number of "turtles"
moving around on a canvas. Each turtle has the following state:
- Position (x and y)
- Direction
- Pen size
- Color index, called "tint"
- Random number generator state.
Unless specific otherwise, all numeric values in Rose are 16.16 bits
fixed-point values.
The position and direction are available as global variables x, y and dir.
SYNTAX
Rose is whitespace-agnostic: line breaks can be inserted or omitted anywhere
between tokens.
Comments start with # and extend to the end of the line.
Just for the fun of it, and because I enjoy using a thesaurus, all keywords
in Rose have four letters.
A Rose program consists of a number of top-level declarations. Except where
noted, these are all optional and can appear in any order. The various kinds
of declarations are described in the following:
A part declaration includes the declarations from another file at the
point of the part declaration. The path of the file to be included is
relative to the file into which it is included.
- part <filename>
Where <filename> is the name of the file to be included, in double quotes.
A form declaration has four numbers which specify the width and height in
pixels, the number of layers, and the number of colors in each layer,
respectively:
- form <expression> <expression> <expression> <expression>
The tints are distributed over the layers, so if, for instance, there are 4
colors per layer, tints 0-3 are in the first (backmost) layer, tints 4-7 are
in the next layer and so on.
A program can contain at most one form declaration. If no form declaration
is given, the resolution will be 352x280 (full overscan), and there will be
1 layer with 4 colors.
A fact declaration defines a global constant:
- fact <identifier> = <expression>
The expression cannot contain variables, but the defined fact can be used in
all expressions in the program, even ones that cannot contain variables. A
fact can refer to other facts, but only ones declared earlier in the program.
A plan declaration, along with any number of look declarations, define the
color script:
- plan <event>*
- look <identifier> <event>*
where <event> is one of:
- wait <expression>
Wait a number of frames. The expression cannot contain variables.
- fade <expression>
Fade over a number of frames. The expression cannot contain variables.
- <tint>:<color>
Set the given tint (integer) to the given color (three-digit hex value).
- <identifier>
Insert the events from the look with the given name.
The first tint in each layer except the first is transparent, showing the
layers behind it. Thus, the colors for these tints are ignored.
A procedure declaration defines executable code:
- proc <name> <param>* <statement>*
where <name> and <param> are identifiers, and <statement> is one of:
- move <expression>
Move forward a number of pixels.
- jump <expression> <expression>
Jump to a pixel coordinate position.
- turn <expression>
Turn a number of 256-on-a-circle degrees clockwise.
- face <expression>
Turn to a number of 256-on-a-circle degrees clockwise from horizontal right.
- size <expression>
Set pen radius in pixels (rounded to nearest integer-and-a-half).
- tint <expression>
Set the current tint (rounded down to an integer).
- draw
Draw a circular dot at the current position.
- plot
Draw a square dot at the current position.
- wait <expression>
Wait a number of frames.
- fork <procedure> <expression>*
Branch off a new turtle with a copy of this turtle's state, running the
given procedure with the given arguments. The old turtle continues executing
the rest of the current procedure in parallel.
- temp <variable> = <expression>
Assign a value to a local variable.
- wire <variable> = <expression>
Assign a value to a global variable whose value is inherited through forks.
- seed <expression>
Seed the random number generator.
- when <expression> <statement>* done
Run the block of statements if the expression evaluates to non-zero.
- when <expression> <statement>* else <statement>* done
Run the first block of statements if the expression evaluates to non-zero,
or the second block of statements otherwise.
- defy
Suppress all warnings for the current source line.
An <expression> is one of:
- <digit>+[.<digit>+]
Constant value.
- $<hexdigit>+
Constant value in hexadecimal. The value is used directly as the
32-bit fixed-point representation, i.e. the last four digits are
implicitly fractional.
- <name>
Procedure or value of parameter, temporary variable or global variable.
- <expression> op <expression>
Binary operation, where op can be (precedence from strongest to weakest):
* / multiplication, division (do fixed-point adjustment to
match fixed-point multiplication and division),
<< >> >>> ><< >>< shift left, shift right, unsigned shift right,
rotate left, rotate right (shift value is 6 least
significant integer part bits of second operand),
+ - addition, subtraction,
== != < <= > >= comparisons,
& bitwise and,
| bitwise or.
- ~ <expression>
Negate value. Used instead of - to enable airy, delimiter-sparse syntax.
- sine ( <expression> )
Computes the sine of 2pi * argument.
- rand
Produces a random number between 0 and 1.
- <expression> ? <expression> : <expression>
If the first expression evaulates to non-zero, evaluate the second
expression, otherwise evaluate the third expression.
- ( <expression> )
For grouping.
Procedures can be assigned to temporaries and passed as arguments to
procedures. The procedure part of a fork statement can refer directly to
a procedure or to a parameter or local variable containing a procedure.
A Rose program must contain at least one procedure. The first procedure
in the program is the main procedure, which is the entry point (a single
turtle running this procedure is created at time 0).
And just to mention it one more time, because this could be a common
pitfall: Remember to use ~ and not - for negation, including for
writing negative numbers!
THE VISUALIZER
Run the visualizer with these arguments:
rose <filename> [<scale>] [<framerate> [<music>]]
where <filename> is the name of a file containing a Rose program,
<scale> is a scale factor for the visualizer window (with an 'x' in
front, i.e. 'x3' for a scaling factor of 3), <framerate> is the frame
rate in frames per second (default 50) and <music> is a 16-bit stereo
WAV file containing the music to play to the animation.
The total number of frames for the animation will be inferred from
the length of the music, or set to 10000 if no music is specified.
The visualizer will continuously monitor the file and reload it whenever
its modification time changes.
Keyboard shortcuts:
- SPACE: start/stop animation.
- RIGHT/LEFT: Step one frame forward/backward.
- PGDOWN/PGUP: Step 50 frames forward/backward.
- BACKSPACE: Go back to frame animation was last started.
- HOME: Go to first frame.
- TAB: Toggle statistics overlay.
- ESCAPE: Quit the visualizer.
Clicking or holding the left mouse button sets the time proportionally to
the mouse X position within the window, up to the total number of frames.