Stack |
|
Memory |
RPNDraw is a stack-based language and simulation environment. The language is similar to the HP-41C programming language, but it has a variable length stack and built-in graphics capabilities. The language is not complete at this time.
There are essentially 5 kinds of instructions related to branching or calling:
As an example, this simple program draws a small square:
50 50 move 50 150 draw 150 150 draw 150 50 draw 50 50 draw
This program draws a series of colored segments:
5 thickness 100 0 move 255 16 lshift color 100 20 draw 255 8 lshift color 100 40 draw 255 0 lshift color 100 60 draw 255 16 lshift color 100 80 draw 255 8 lshift color 100 100 draw 255 0 lshift color 100 120 draw 255 16 lshift color 100 140 draw 255 8 lshift color 100 160 draw 255 0 lshift color 100 180 draw
This program draws a single sine wave:
0.0 dup dup sin -80 * 100 + swap 40 * move #1 0.2 + dup dup sin -80 * 100 + swap 40 * draw dup 12 swap - x>0? !1 drop
This program draws a sine in red and cosine in green:
255 16 lshift color 0.0 dup dup sin -80 * 100 + swap 40 * move #top_red 0.2 + dup dup sin -80 * 100 + swap 40 * draw dup 13 swap - x>0? !top_red drop 255 8 lshift color 0.0 dup dup cos -80 * 100 + swap 40 * move #top_green 0.2 + dup dup cos -80 * 100 + swap 40 * draw dup 13 swap - x>0? !top_green drop
This program draws a circle:
0.0 dup dup sin -80 * 100 + swap cos 80 * 200 + move 0.1 + #loop dup dup sin -80 * 100 + swap cos 80 * 200 + draw 0.1 + dup 7 swap - x>0? !loop drop
This program counts down from 5 leaving history on the stack:
clear 5 #Top dup 1 - dup x=0? !End !Top #End
This program multiplies by 3 three times:
clear 1 dup @MulBy3 dup @MulBy3 dup @MulBy3 !end #MulBy3 3 * return #end
This program draws a Hypotrochoid:
200 200 setscreen 4 thickness 100 8 lshift 100 + 8 lshift 255 + color 6 0 store 0.5 1 store 3 2 store 0.02 3 store 316 4 store 0 8 store 0 recall 1 recall - 9 store drop drop drop drop drop drop drop #loop 8 recall 3 recall * 5 store 5 recall sin 9 recall * 5 recall 9 recall * 1 recall / sin 2 recall * - 6 store 5 recall cos 9 recall * 5 recall 9 recall * 1 recall / cos 2 recall * + 7 store 7 recall 10 * 100 + 6 recall 10 * 100 + draw drop drop drop 8 recall 1 + 8 store 4 recall x=y? !done drop !loop #doneBecause RPNDraw is stack based, it can also run many programs that work on the HP-41C. These are a few examples from the HP-41C Owners Handbook and Programming Guide that have been translated to run on RPNDraw:
Page 9: (requires temperature difference in X) 30 * 0.47 *
Page 111: (requires radius in X) dup * 1 atan 4 * *
Page 126: Water Heater uses: h = 50 (Y), r = 11 (X) 50 11 1 store dup * 1 atan 4 * * 2 * x<>y 1 recall * 1 atan 4 * * 2 * + Should produce a result of 4216.017341117503