Halloween
var trees = [];var houset = [];function setup() {
createCanvas(480, 480); strokeJoin(MITER); strokeCap(PROJECT) angleMode(DEGREES); for (var i = 0; i < 10; i++){
var rx = random(width); trees[i] = makeTree(rx); houset[i] = makeHouse(rx); }
}
function draw() {
var run = map(mouseX,0,width,20,60); frameRate(run) noStroke(); background(30); fill(299,149,41,30) rect(0,280,width,height,80); noFill(); fill(0) rect(0,0,width,300); noFill();
displaybackground();
updateAndDisplayobjects(); removeobjects(); addNewobjects(); }
function updateAndDisplayobjects(){
for (var h = 0; h < houset.length; h ++){ houset[h].hmove();
houset[h].hdisplay();
}
for (var i = 0; i < trees.length; i++) trees[i].tmove();
trees[i].tdisplay();
}
}
function removeobjects(){
var treesKeep = []; var housekeep = []; for (var h =0; h < houset.length; h++){
if(houset[h].hx + 50 >0){ housekeep.push(houset[h]);
}
}
houset = housekeep;
for (var i = 0; i < trees.length; i++){ if (trees[i].x>0){
treesKeep.push(trees[i]);
}
}
trees = treesKeep;
}
function addNewobjects() {
var newobjprob = 0.4; var houseprob =0.02; if (random(0,1) < houseprob){ houset.push(makeHouse(width))
}
if (random(0,1) < newobjprob) { trees.push(makeTree(width))
}
}
function treeDisplay(){ var treeheight = 20;
var tHeight = this.nHeight*treeheight;
var bcount = 0;
var branchlen = 60;
fill(10);
stroke(50,19,41);
push();
strokeWeight(1.5);
translate(this.x, height-60);
line(0,0,0,-tHeight);
translate(0,-tHeight);
stroke(120,59,41);
while(bcount < this.branch){
push();
translate(0,branchlen)
bcount+=1;
branchlen *= 0.67
if (branchlen > 4){
push();
rotate(45);
line(0,0,0,-branchlen);
pop();
push();
rotate(-70)
line(0,0,0,-branchlen)
pop();
}
pop();
}
pop();
}
function houseDisplay(){ var houseHeight = 40;
var hwid = this.hwidth;
var hHeight = this.hfloor*houseHeight;
push();
translate(this.hx,height-60);
stroke(127,152,182,180);
strokeWeight(3);
line(0,0,-10*this.flip,-hHeight/2);
line(0,0,30*this.flip,-hHeight/2);
push();
translate(-10*this.flip,-hHeight/3);
line(0,0,15,-height/5)
line(0,0,35,-height/5)
pop();
push();
noStroke();
fill(37,23,3);
translate(-10,-height/5);
beginShape();
vertex(0,0);
vertex(hwid*4,0);
vertex(hwid*3,-hHeight);
vertex(-hwid,-height/6)
endShape();
for( var i =0; i <this.hfloor; i += this.hdiv){
fill(187,121,18,200);
ellipse(20,-20 - (i*houseHeight/2),this.hwidth*2,this.hwinh);
}
pop();
pop();
}
function treeMove(){
this.x += this.speed;
}
function houseMove(){
this.hx += this.hspeed;
}
function makeTree(tx){ var tree = {x: tx,
speed: random(-7.0,-20),
nHeight: floor(random(4,8)),
branch: random(20,30),
tmove: treeMove,
tdisplay: treeDisplay
}
return tree;
}
function makeHouse(hhx){ var house = {hx: hhx,
hspeed: -2.0,
flip: random(-1,1),
hdiv: random(1,3),
hwinh: random(10,20),
hfloor: round(random(2,5)),
hwidth: random(10,20),
hmove: houseMove,
hdisplay: houseDisplay
}
return house;
}
function displaybackground(){ noStroke();
fill(color(255,235,5,190));
ellipse(width-80,110,180,180);
noFill();
noStroke();
fill(255,255,255,20);
ellipse(width-30,70,30,30);
fill(0,0,0,30);
ellipse(width-160,130,10,30);
fill(0,0,0,20);
ellipse(width-20,160,35,25);
noStroke();
stroke(70,130,170,150);
beginShape();
for( var x = 0; x < width; x++){ var t = (x * 0.005)+(millis()*0.0005);
var y = map(noise(t),0,1,20,75);
vertex(x,height-y);
vertex(0,height+70);
vertex(width,height+70) ;
}endShape();
noStroke();
fill(239,234,188) ellipse(100,height-20,130+random(-1,1),5+random(-1,1));
noFill();
fill(239,239,188) ellipse(80,height-15,80+random(-1,1),4+random(-1,1));
noFill();
}
Since it was Halloween, I wanted to create a landscape that is staged at night with tree landscapes and witch houses on river’s edge. I wanted to give depth to the landscape formation. I have decided to create the river’s edge using the noise function in the p5js. When I tried to convey the sense of the 3D, I realized that giving a different in speed of object passage is very effective. I generated trees that differ in speed and height to convey the depth. Almost giving the sense of when someone walks in forest, they pass in different relative speed. I have created abstracted witch houses behind the trees. I created large moon and its reflection on the river to convey another layer of depth. Frame rate interact with the mouse X position giving a feel of running through the landscape vs. walking