/* * Simple "graphing calculator" to sketch the cubic function: * y = a * x^3 + b*x^2 + c*x + d */ size(600, 400); background(255); noFill(); float originX = width/2; float originY = height/2; stroke(127); line(0,originY, width, originY); line(originX, 0, originX, height); stroke(0); beginShape(); for (int x=-width/2; x < width/2; x++) { float a = 0.01; float b = -0.5; float c = 4; float d = 20; float y = a * pow(x,3) + b * pow(x,2) + c * x + d; vertex(originX + x, originY - y); } endShape();