Danny Cho – Generative Landscape

For this project, I was inspired by some of the previous works done in the past 15-104 classes. Especially the ones that were done regarding the concepts of the shooting stars and lamps inspired me. I tried to replicate the frame of the lamps with the detail feature of the sphere function as well as showing the glow by creating multiple translucent sphere in and out of them.

It takes some time for the lamps to start appearing unless you drag around the screen to look for them.

landscape

//Danny Cho
//Project 11
//changjuc@andrew.cmu.ed
//section A
var lampNumber = 20;
var lampXlimit;
var lampZlimit;
var lampYlimit;
var lamps = []; //containing objects
var lampScale = 60; //scale of the lamp exterior
var renderer;



function setup() {
	renderer = createCanvas(480, 480, WEBGL);
	for (var i = 0; i < lampNumber; i++) {
        lampXlimit = random(-100, 600);
        lampXlimit = random(-1000, 1000);
        lampZlimit = random(-50, 1000);
        lamps[i] = makeLamp(lampXlimit, lampYlimit, lampZlimit);
    }
    frameRate(10);

}

function draw() {
	background(28, 37, 65);
	noStroke();
	
	// for (var i = 0; i < lampNumber; i++) {
	// 	push();
	// 	 print("line37")
	// 	translate(lampX[i], lampY[i], lampZ[i]);

	// }
	// pop();
	for (var u = 0; u < lamps.length; u++) {
		lamps[u].draw();
	}

	var keepLamps = []; 
	//would delete the lamps that go beyond a certain height
		for (var j = 0; j < lamps.length; j++) {
			if (lamps[j].y > 500) {
				keepLamps.push(lamps[j]);
			}
		}

	orbitControl();
	fill(255);

	

}

function makeLamp(lx, ly, lz) {
	print("lamp make")
	var lamp = {x: lx, y: ly, z: lz, draw: lampDraw}
	return lamp;
}

function lampDraw() {
	print("lampdraw")
	push();
	print("line59")
	//location of the lamp
	translate(this.x, this.y, this.z);
	fill(218, 45, 28, 200);
	stroke(0);
	//the exterior of the lamp
	sphere(lampScale, 10, 4);
	noStroke();
	//inner lighting of the lamp
	for (var i = 0; i < 5; i++) {
		fill(255, 220, 115, 20 - 4 * i)
		sphere(9 * i + 10);
	}
	//outer glow of the lamp
	for (var i = 0; i < 6; i++) {
		fill(255, 220, 115, 4.5)
		sphere((i * i) + 60);
	}
	//lamp's movement
	this.y -= 45;
	pop();

	//making new lamps
	var newLamp = 0.008; //chances of new lamp being created
	if (random(0, 1) < newLamp) {
		lampXlimit = random(-2000, 6000);
		lampZlimit = random(-5000, 0);
		lamps.push(makeLamp(lampXlimit, (-lampZlimit) / 4, lampZlimit));
	}
	
}

Leave a Reply