// Graph the function y=x^2 - 10, x=-20...20 // Range of function: [-10, 390] // Let's say 400 will appear at screenY = 50 // y=0 will appear at screenY = 450 // y=-10 will appear at screenY=460 // So screenY = 450 - y // Let's put x=-20 at screenX = 50 // x=0 at screenX = 250 // x=20 at screenX = 450 // So screenX = (x+20)*10 + 50 void setup() { float x, prevX; float y, prevY; size (500, 500); // Generate the first (x,y) pair and save it as prev prevY = (-20*-20) - 10; for ( x=-19 ; x<=20 ; x++ ) { y = x*x - 10; drawLine (x-1, prevY, x, y); prevY = y; } } void drawLine (float prevX, float prevY, float x, float y) { line (screenX (prevX), screenY (prevY), screenX (x), screenY (y)); } float screenX (float x) { return ( (x+20)*10 + 50 ); } float screenY (float y) { return ( 450-y ); }