Difference between revisions of "Simple graphics language"
From ScienceZero
Line 1: | Line 1: | ||
− | A simple graphics language for microcontrollers | + | =A simple graphics language for microcontrollers= |
We start with a very simple reverse polish notation interpreter with a preprocessor stage | We start with a very simple reverse polish notation interpreter with a preprocessor stage |
Revision as of 21:10, 14 April 2011
A simple graphics language for microcontrollers
We start with a very simple reverse polish notation interpreter with a preprocessor stage
Sample code:
360 for 1 forward 1 right next
Registers:
0 X 1 Y 2 Angle 3 Scale 4 Colour 5 Pen up/down 6 Nested If counter 7
Stack diagrams:
( things read from the stack -- things written on the stack ) x - x position y - y position n - number Example: ( n n -- n ) This means that two numbers were read from the stack, then one number was written back. For example a simple addition reads two numbers and writes back the result.
Commands:
Define function:
To <function name> End
Absolute commands
setcolour ( colour -- )
readcolour ( -- colour )
setpos ( x y -- )
readpos ( -- x y )
Relative commands:
penup ( -- )
pendown ( -- )
forward ( length -- )
backward ( length -- )
left ( angle -- )
right ( angle -- )
Loops:
for ( n -- )
next ( -- )
do ( -- )
again ( -- )
Conditionals:
if ( n -- )
else
endif
Data processing:
+ ( n n -- n )
- ( n n -- n )
>> ( n -- n )
<< ( n -- n )
and ( n n -- n )
or ( n n -- n )
eor ( n n -- n )