Trippy array Loop Project
- David McDonald
- Nov 19, 2019
- 1 min read

For my array loop project, I used some of my old code with the new array loop functions to make a better version of one of my past projects.
The code:var blocations = [];
var speeds = [];
var rectX
function setup() {
// put setup code here
createCanvas(1260, 600);
blocations[0] = 1;
blocations[1] =100;
blocations[2] =500;
blocations[3] = 50;
speeds[0] = 5;
speeds[1] =3;
speeds[2] =-6
speeds[3] =4
}
function draw() {
// put drawing code here
background('white');
fill('red');
rect(100,mouseY, 80, 80);
fill('magenta');
rect(100,mouseY, 60, 40);
fill('blue');
rect(mouseX,100,80, 80);
fill('cyan');
rect(mouseX,100,60, 35);
fill('green')
rect(500,mouseY,80,80);
fill('pink')
rect(500,mouseY,40,70);
fill('yellow')
rect(mouseX,500,80,80);
fill('silver')
rect(mouseX,500,10,65);
fill('cyan')
rect(mouseX,mouseY,50,50);
fill('pink')
rect(mouseX,mouseY,20,80);
fill('lime')
rect(mouseX,mouseY,70,10);
for(var i=0; i <10; i++){
for(var j=0; j <6; j++)
{
fill('white');
rect(i * 100, j* 100+50, 50, 50);
fill('white')
rect(i * 100+50, j* 100, 50, 50);
}
}
fill('gold');
rect(blocations[0], blocations[1], 35, 35);
rect(blocations[2], blocations[3], 35, 35);
for (var i = 0; i<blocations.length; i++){
blocations[i] = blocations[i] + speeds[i];
}
function keyPressed(){
if (keyCode === LEFT_ARROW){
//this will move my platform left
///console.log('left');
rectX -= 50;
}
else if(keyCode === RIGHT_ARROW){
//this will move my platform right
//console.log('right');
rectX += 50;
}
}
}
Commentaires