xxxxxxxxxx
69
let movers = []; // Array to store all movers
let yLim;
let leftNostril;
let rightNostril;
function setup() {
createCanvas(700, 700);
yLim = height/2 - 125;
leftNostril = width/2 - 30;
rightNostril = width/2 + 30;
// Create initial movers
movers.push(new Mover(leftNostril));
movers.push(new Mover(rightNostril));
}
function draw() {
background("white");
textAlign(CENTER, TOP);
fill("black");
noStroke();
text("click to make boogers, hold down for gravity!", width/2, 40);
let gravity = createVector(0, 0.1);
if (mouseIsPressed) {
// Apply gravity to all existing movers
for (let mover of movers) {
mover.applyForce(gravity);
}
}
// Update and show all movers
for (let mover of movers) {
mover.update();
mover.show();
mover.checkEdges();
}
// LINE; TODO delete later
image(img, width/2 - 150, height/2 - 300, 300, 300);
stroke('red');
//line(0, yLim, width, yLim); // top line
//line(0, yLim+90, width, yLim+90);
// TODO apply gravity between these two lines without click
}
// Add this new function to handle mouse clicks
function mousePressed() {
// Create a new mover, 50/50 chance of left or right nostril
let nostril;
let probability = 0.5;
let r = random(1);
if (r < probability) {
nostril = leftNostril;
}
else {
nostril = rightNostril;
}
let newMover = new Mover(x=nostril);
movers.push(newMover);
}
function preload() {
img = loadImage("nosegamenose.png");
}