xxxxxxxxxx
32
var cnt =-12;//x-value and counter for each polynomial
var a=0.01,t=0;//initial values for coefficients, and reset counter t
function setup() {
createCanvas(400, 400); //create the canvas
background(20); //black background
strokeWeight(0.1);//thin lines
}
function draw() {
translate(width/2,width/2) //translate the canvas for (0,0)middle
fill(200, 250-10*t, 250,40)//gradient fill
x1 = cnt; //set x to counter
y1 = a*pow((x1),3)//Polynomial y value ax^3+bx^2+cx
if(y1>-200 && y1 <200){ //only draw circles if it is on the canvas
circle(x1*15,y1,cnt*3)//draw a circle for a point on the polynomial
}
cnt=cnt+0.3; //increase counter for x
if (cnt>12){//draw the next polynomial
newCoeff();// function to change coefficients
}
}
function newCoeff(){
a = a*1.5//change a
cnt = -12;//reset cnt
t = t+1; //increment screen reset counter
if (t> 20){
//background(0);//reset canvas
//t=0,k = 0, p = 1,h = 0;//initialize variables
noLoop()//stops when done - uncomment previous two lines to loop and comment this one
}
}