Skip to content

Instantly share code, notes, and snippets.

@luc4leone
Created February 24, 2015 20:51
Show Gist options
  • Save luc4leone/7ae02eed9b04ae4df126 to your computer and use it in GitHub Desktop.
Save luc4leone/7ae02eed9b04ae4df126 to your computer and use it in GitHub Desktop.
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);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment