xxxxxxxxxx
127
let img; // Declare variable 'img'.
function setup() {
createCanvas(720, 400);
img = loadImage('texture/a.jpg');
}
var heights = [50, 10, 20, 15, 15, 10, 5, 5];
var yOff = 0;
var ingredients = [];
function setup() {
createCanvas(windowWidth, windowHeight);
ingredients.push(new Thing(0));
}
function draw() {
background(255);
for (var i = 0; i < ingredients.length; i++) {
ingredients[i].run();
}
if (mouseIsPressed) {
ingredients.push(new Thing(floor(random(0, 8))));
}
}
class Thing {
constructor(_name) {
this.name = _name;
yOff += heights[this.name];
this.yOff = yOff;
this.pos = createVector(width / 2 + random(-25, 25), -heights[_name]);
this.vel = createVector();
this.acc = createVector();
}
run() {
this.update();
this.show();
}
show() {
noStroke();
if (this.name == 0) {
// Bread
rectMode(CORNER);
fill(255, 200, 0);
//noFill();
//texture(img);
rect(this.pos.x, this.pos.y, 200, 50, 15);
} else if (this.name == 1) {
// Cheese
rectMode(CORNER);
fill(255, 225, 100);
rect(this.pos.x, this.pos.y, 200, 10, 2.5);
} else if (this.name == 2) {
// Meat
rectMode(CORNER);
fill(120, 65, 0);
rect(this.pos.x, this.pos.y, 200, 20, 5);
} else if (this.name == 3) {
// Tomato
rectMode(CORNER);
fill(255, 50, 50);
rect(this.pos.x, this.pos.y, 75, 15, 5);
rect(this.pos.x + 125, this.pos.y, 75, 15, 5);
} else if (this.name == 4) {
// Pickle
rectMode(CORNER);
fill(50, 120, 0);
rect(this.pos.x, this.pos.y, 75, 15, 5);
rect(this.pos.x + 125, this.pos.y, 75, 15, 5);
} else if (this.name == 5) {
// Lettuce
rectMode(CORNER);
fill(100, 200, 0);
rect(this.pos.x, this.pos.y, 200, 10, 2.5);
} else if (this.name == 6) {
// Salt
rectMode(CENTER);
fill(200);
rect(this.pos.x + 20, this.pos.y, 5, 5, 2.5);
rect(this.pos.x + 40, this.pos.y, 5, 5, 2.5);
rect(this.pos.x + 60, this.pos.y, 5, 5, 2.5);
rect(this.pos.x + 80, this.pos.y, 5, 5, 2.5);
rect(this.pos.x + 100, this.pos.y, 5, 5, 2.5);
rect(this.pos.x + 120, this.pos.y, 5, 5, 2.5);
rect(this.pos.x + 140, this.pos.y, 5, 5, 2.5);
rect(this.pos.x + 160, this.pos.y, 5, 5, 2.5);
rect(this.pos.x + 180, this.pos.y, 5, 5, 2.5);
} else if (this.name == 7) {
// Pepper
rectMode(CENTER);
fill(50);
rect(this.pos.x + 20, this.pos.y, 5, 5, 2.5);
rect(this.pos.x + 40, this.pos.y, 5, 5, 2.5);
rect(this.pos.x + 60, this.pos.y, 5, 5, 2.5);
rect(this.pos.x + 80, this.pos.y, 5, 5, 2.5);
rect(this.pos.x + 100, this.pos.y, 5, 5, 2.5);
rect(this.pos.x + 120, this.pos.y, 5, 5, 2.5);
rect(this.pos.x + 140, this.pos.y, 5, 5, 2.5);
rect(this.pos.x + 160, this.pos.y, 5, 5, 2.5);
rect(this.pos.x + 180, this.pos.y, 5, 5, 2.5);
}
}
update() {
this.acc.y++;
this.vel.add(this.acc);
this.acc.mult(0);
if (yOff > height / 2) {
for (var n = 0; n < ingredients.length; n++) {
ingredients[n].yOff -= 1;
}
yOff -= 1;
}
if (this.pos.y >= height - this.yOff) {
this.pos.y = height - this.yOff;
this.vel.mult(0);
this.acc.mult(0);
} else {
this.pos.add(this.vel);
}
}
}