xxxxxxxxxx
23
var y1 = 50, x = 0; //set value of y on canvas and inital exponent
function setup() {
createCanvas(400, 400); //create the canvas
frameRate(1); //draw slow
}
function draw() {
num = pow(2,x); //num = 2^x
fill(random(255),random(255),random(255));//randomize color
circle(200,y1,num)//draw circle with 2^x diameter
text('2',x*20,12);//write 2 and have it move left with each circle
text('x',x*20-10,12);//write x and have it move left with each circle
fill(255)//make a white rectangle diameter text
rect(330,0,100,20)//rectangle for diameter text
fill(0)//make the text black
text(str(num),350,12)//diamter text box
x = x+1;//increase the exponent by 1
y1 = y1+12;//move the center of the circle down 12
if(x == 11){//make sure that the animation loops and doesn't crash
x = 0;//reset x
y1 = 100;//reset y
background(255)//reset background
}
}