// Justin Yook
// jyook@andrew.cmu.edu
// Section C
// Project 10
var milk = [];
var milkCol;
function setup() {
createCanvas(480, 200);
milkCol = [color(255, 0, 0), color(255, 255, 0), color(0, 0, 255), color(0, 255, 0)];
for (var i = 0; i < 10; i++) {
var rx = random(width); // random x location within width
milk[i] = makeMilk(rx);
}
frameRate(60);
}
function draw() {
background(200, 233, 243);
displayFloor();
updateAndDisplayMilk();
removeMilk();
addMilkRandom();
}
function displayFloor(){
stroke(152, 196, 209);
strokeWeight(3);
line(0, height - 30, width, height - 30);
}
function makeMilk(spawnX) {
var mlk = {x: spawnX,
space: 50,
speed: -1.0,
move: milkMove,
col: random(milkCol),
display: milkDisplay}
return mlk;
}
function milkMove() {
this.x += this.speed;
}
function milkDisplay() {
fill(255);
stroke(0);
strokeWeight(1);
rect(this.x, height - 90, 40, 70);
fill(this.col);
rect(this.x, height - 90, 40, 10);
fill(this.col);
rect(this.x, height - 30, 40, 10);
fill(255);
quad(this.x, height - 90, this.x + 5, height - 100, this.x + 35, height - 100, this.x + 40, height - 90);
fill(255);
rect(this.x + 5, height - 105, 30, 5);
}
function addMilkRandom() {
var newMilkProb = .007;
if (random(0, 1) < newMilkProb) {
milk.push(makeMilk(width));
}
}
function removeMilk() {
var milkeep = [];
for (var i = 0; i < milk.length; i++) {
if (milk[i].x + milk[i].space > 0) {
milkeep.push(milk[i]);
}
}
milk = milkeep;
}
function updateAndDisplayMilk() {
for (var i = 0; i < milk.length; i++) {
milk[i].move();
milk[i].display();
}
}
I chose to do a generative landscape of the inside of a refrigerator. The object I defined is the milk quart. Each milk quart has a color that is randomly picked from an array of pre-selected colors. I was inspired when I went to buy some groceries, and I saw that different types of milk had different colors on their packaging. If I were to add to this project, I would include different heights for each milk quart, and other food products (objects) such as eggs, and yogurt. The concept for this project was the hardest to think of by far, because I could not find inspiration for a long time during the week.