xxxxxxxxxx
29
/*
This sketch draws random circles along the X-axis using arrays and a for loop.
Can you add more circles?
Can you also have it fall randomly along the Y-axis?
Can you also randomize the size of the circles?
What about the color?
*/
var starX = []; // creating a blank array
function setup(){
createCanvas(500,500);
background(0);
for(var i = 0; i<=20; i++){ // this for loop will iterate 21 times ...
starX.push(random(10, 500)); // adding a random value to the array
}
}
function draw(){
background(0);
fill(255,255,0);
for(var i = 0; i<=20; i++){ // this loop will iterate 21 times as well
fill(255, 255, 0);
circle(starX[i], 10, 6); // reading the values of the arrays
}
}