xxxxxxxxxx
33
var cnt =-12;//x-value and counter for each polynomial
var a=1,t=0;//initial a, and reset counter t
function setup() {
createCanvas(400, 400); //create the canvas
background(20,60,90); //black background
strokeWeight(0.1);//thin lines
fill(0, 250, 250,80)//gradient fill
}
function draw() {
translate(width/2,width/2) //translate the canvas for (0,0)middle
x1 = cnt; //set x to counter
y1 = (a*pow((x1),4))/100 //Polynomial y value ax^4
if(y1>-200 && y1 <200){ //only draw circles if it is on the canvas
circle(x1*20,y1,5)//draw a circle for a point on the polynomial
circle(x1*10,y1,5)//draw a circle for a point on the polynomial (modify x)
circle(x1*5,y1,5)//draw a circle for a point on the polynomial(modify x)
circle(x1,y1,5)//draw a circle for a point on the polynomial(modify x)
}
cnt=cnt+0.2; //increase counter for x
if (cnt>12){//draw the next polynomial
newCoeff();// function to change coefficients
}
}
function newCoeff(){
a = random(-5,5)//change a
cnt = -12;//reset cnt
t = t+1; //increment screen reset counter
if (t> 10){
//background(0);//reset canvas
fill(random(255), random(255), random(255),80) //randomize color after 10 rounds
}
}