luc4leone
2/24/2015 - 8:51 PM

khan intro to js, lesson on modifying arrays

khan intro to js, lesson on modifying arrays

// x positions of baloons and ropes
var xPositions = [100, 200]; 

//when i want more than 1 baloon i need to create
//a variable that grows
var newInd = 2;
var draw = function(){
    if (mouseIsPressed){
        xPosition[newInd] = mouseX;
        newInd++;
    }
}
    noStroke();
    background(212, 254, 255);
    
    stroke(64, 117, 207);
    fill(196, 33, 255);
    for (var i = 0; i < xPositions.length; i++) { 
        line(xPositions[i], 120, 194, 285);
        ellipse(xPositions[i], 104, 32, 46);
    }
    var hopper = getImage("creatures/Hopper-Jumping");
    image(hopper, 189, 227);
};