// Name: Shariq M. Shah
// Andrew ID: shariqs
// Section: C
// Project 11
//initializing objects as empty arrays
var boxes = [];
var balls = [];
var spikesSpeed = 0.0005;
var spikesDetail = 0.5;
function setup() {
createCanvas(640, 240);
// creating boxes
for (var i = 0; i < 10; i++){
var rx = random(width);
boxes[i] = makebox(rx);
}
frameRate(30);
}
function draw() {
background(235, 183, 52);
noFill();
stroke(1);
beginShape();
for (var x = 0; x < width; x++) {
var t = (x * spikesDetail * 2) + (millis() * 1.3 * spikesSpeed);
var y = map(noise(t), 0, 1, 0, height);
vertex(x, y);
push();
fill(0);
ellipse(x, y, 5, 5);
pop();
}
endShape();
updateAndshowboxes();
removeboxesThatHaveSlippedOutOfView();
addNewboxesWithSomeRandomProbability();
//text that moves in generative landscape
text("//wishyouwerehere", constrain(mouseX, 50, width - 100), height/2 + 50, 5)
}
function updateAndshowboxes(){
// Update the box's positions, and show them.
for (var i = 0; i < boxes.length; i++){
boxes[i].move();
boxes[i].show();
}
}
function removeboxesThatHaveSlippedOutOfView(){
var boxesToKeep = [];
for (var i = 0; i < boxes.length; i++){
if (boxes[i].x + boxes[i].breadth > 0) {
boxesToKeep.push(boxes[i]);
}
}
boxes = boxesToKeep; // remember the surviving boxes
}
function addNewboxesWithSomeRandomProbability() {
// With a very tiny probability, add a new box to the end.
var newboxLikelihood = 0.007;
if (random(0,1) < newboxLikelihood) {
boxes.push(makebox(width));
}
}
// method to update position of box every frame
function boxMove() {
this.x += this.speed;
}
function boxshow() {
var heightUp = 20;
var bHeight = this.nFloors * heightUp;
fill(0);
stroke(5);
push();
translate(this.x, height - 40);
noStroke();
for (var i = 0; i < 50; i++) {
rect(5, -15 - (i * heightUp), this.breadth - 5, 1 + i);
ellipse(-20, -(i * 1.2 * 2 * heightUp), 5 + i, 5 + i);
}
pop();
}
function makebox(birthLocationX) {
var bldg = {x: birthLocationX,
breadth: 50,
speed: -1.0,
nFloors: round(random(2,8)),
move: boxMove,
show: boxshow}
return bldg;
}
In this project, I used objects to generate an abstract and dynamic landscape that interacts with the rectangular geometry objects in the background. The arrays and dynamic objects generate a constantly moving and energetic field.