Difference between revisions of "Simple graphics language"

From ScienceZero
Jump to: navigation, search
Line 21: Line 21:
 
   setpixel      ( x y colour -- )
 
   setpixel      ( x y colour -- )
 
   readpixel    ( x y -- colour )
 
   readpixel    ( x y -- colour )
   colour        (colour -- )
+
   colour        ( colour -- )
   goto          (x y -- )
+
   setpos        ( x y -- )
 +
  readpos      ( -- x y )
 
   
 
   
 
  Relative commands:
 
  Relative commands:
Line 32: Line 33:
 
   right        ( angle -- )
 
   right        ( angle -- )
 
    
 
    
Loops:
+
Loops:
   for
+
   for           ( n -- )
   next
+
   next         ( -- )
 
   
 
   
 
  Conditionals:
 
  Conditionals:
   if
+
   if           ( n -- )
 
   else
 
   else
 
   endif
 
   endif

Revision as of 16:38, 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

Commands:

Absolute commands
  setpixel      ( x y colour -- )
  readpixel     ( x y -- colour )
  colour        ( colour -- )
  setpos        ( x y -- )
  readpos       ( -- x y )

Relative commands:
  penup         ( -- )
  pendown       ( -- )
  forward       ( length -- )
  backward      ( length -- )
  left          ( angle -- )
  right         ( angle -- )
 
Loops:
  for           ( n -- )
  next          ( -- )

Conditionals:
  if            ( n -- )
  else
  endif