RUN HERE: http://phosphorus.github.io/app.html?id=102736846&turbo=false&full-screen=true Expression Calculator: type a numerical expression and it will be calculated, considering operator order, ( expoents are buggy ) 2D https://scratch.mit.edu/projects/102736846/#editorGraph: type a graph equation and it will be ploted on screen, try: x*x+y*y-10000 to make a sphere Random Graph a random equation is selected from a list and cool stuff is ploted HOW IT WORKS: the expression you type, is a String of characters, with leading spaces and the numbers and operators... Step 1: " 10 + 5/2 " turns out in a list like 10 + 5 / 2 Step 2: this is the Infix notation, but to compile it i need Reverse Polish Notation, (wikipedia: https://en.wikipedia.org/wiki/Reverse_Polish_notation) to do this i use the Sunting-yard algrithm (wikipedia: https://en.wikipedia.org/wiki/Shunting-yard_algorithm) so the expression becomes: 5 2 / 10 + Step 3: i need to convert this to bytecode, similar to java bytecode (wikipedia: https://en.wikipedia.org/wiki/Java_bytecode) so the expressin becomes: push 5 push 2 div push 10 add and them this is converted to a numerical representation to be iterated trought switch: push:0 add:1 sub:2 mul:3 div:4 rem:5 pow:6(don't work) so the expression is turned to: 0 5 0 2 4 0 10 1 and this runs in a virtual machine, stack based, like a very very simplified java virtual machine: https://en.wikipedia.org/wiki/Java_virtual_machine
if you find a bug or something you think are wrong, post in coments Nice Functions: checkerboard: (x/20%2-1)*(y/20%2-1) circles: ((x%40-20)*(x%40-20)+(y%40-20)*(y%40-20)-200) waterdrop: (x*x+y*y)%5000-2500 exponencial curve: (x*x*x/40000-y) circular circles: (x%40-20)*(x%40-20)+(y%40-20)*(y%40-20)-200)+(x*x+y*y)/10((x%40-20)*(x%40-20)+(y%40-20)*(y%40-20)-(x*x+y*y)/100