//Aisha Dev
//adev@adnrew.cmu.edu
//Section E
// Project 10
var frames = [];
var sm1 = - 0.00006;
var sm2 = - 0.000065;
var sm3 = - 0.00005;
var sm4 = - 0.0001;
var sm5 = - 0.0003;
var detail1 = 0.005;
var detail2 = 0.003;
var detail3 = 0.003;
var detail4 = 0.001;
var detail5 = 0.0015;
var trees = [];
var bwTrees = 0;
// var playlist = ["Across The Unverse", "Aint No Sunshine", "All Along The Watchtower", "American Pie", "Anywhere Is", "Bennie and The Jets", "Blackbird", "Blowin in The Wind",
// "Blue Jean Baby", "Bridge Over Troubled Water", "Budapest", "A Case of You", "Comfortably Numb", "Catch the Wind", "Cowgirl in the Sand", "Crazy Love", "Come Together", "Dancing in the Dark",
// "Dont Think Twice Its Alright", "Hallelujah", "Hear of Gold", "Heavenly Day", "Hey Jude", "Ho Hey", "Home", "I See Fire", "Flight Attendant", "Just Like A Woman", "Liar", "Knights in White Satin",
// "Lady Lady Lay", "Layla", "Leave Your Lover", "Lodi", "The Long and Whinding Road", "Long as I Can See The Light", "Losing You", "Sospesa", "Me and Bobby Mcgee", "More Than a Woman",
// "Mr Tambourine Man", "No Woman No Cry", "Oh Sister", "Old Man", "Only Love", "Over The Creek", "Piece of My Heart", "Proud Mary", "Roxanne", "Something", "Song To Woody", "Songbird", "Sound of Silence",
// "Start Over", "Stop This Train", "Take Me to Curch", "The Thrill is Gone", "The Times They Are a Changin", "Fast Cars", "Underneath", "While My Guitar Gently Weeps", "Wholl Stop The Train", "Yesterday",
// "Wish You Were Here", "You Are So Beautiful", "Our House", "Fortunate Son", "Warning Sign", "Like A Rolling Stone", "Jokerman"];
// var index = 0;
function setup() {
createCanvas(480,200);
for (var i = 0; i < 20; i++){
var rx = random(width);
trees[i] = makeTree(rx);
}
frameRate(10);
}
function draw() {
//functions
makeBackground();
makeMountains();
//songs();
drawTree();
addTree();
}
function makeBackground(){
background(30, 50, 100);
}
function makeMountains(){
noStroke();
//highest mountain range
fill(174, 153, 139);
beginShape();
for (var mOne = 0; mOne < width; mOne++) {
var speedOne = (mOne * detail1) + (millis() * sm1);
var peaksOne = map(noise(speedOne), 0,1, 0, height);
vertex(mOne,peaksOne-70);
}
vertex(width,height);
vertex(0,height);
endShape();
//second highest mountain range
fill(128, 121, 113);
beginShape();
for (var mTwo = 0; mTwo < width; mTwo++) {
var speedTwo = (mTwo * detail2) + (millis() * sm2);
var peaksTwo = map(noise(speedTwo), 0,1, 0, height);
vertex(mTwo,peaksTwo-30);
}
vertex(width,height);
vertex(0,height);
endShape();
//middle mountain range
fill(93, 84, 86);
beginShape();
for (var mThree = 0; mThree < width; mThree++) {
var speedThree = (mThree * detail3) + (millis() * sm3);
var peaksThree = map(noise(speedThree), 0,1, 0, height);
vertex(mThree,peaksThree+10);
}
vertex(width,height);
vertex(0,height);
endShape();
//second - lowest mountain range
fill(67, 60, 67);
beginShape();
for (var mFour = 0; mFour < width; mFour++) {
var speedFour = (mFour * detail3) + (millis() * sm4);
var peaksFour = map(noise(speedFour), 0,1, 0, height);
vertex(mFour,peaksFour+30);
}
vertex(width,height);
vertex(0,height);
endShape();
//lowest mountain range
fill(48, 45, 48);
beginShape();
for (var mFive = 0; mFive < width; mFive++) {
var speedFive = (mFive * detail3) + (millis() * sm5);
var peaksFive = map(noise(speedFive), 0,1, 0, height);
vertex(mFive,peaksFive+60);
}
vertex(width,height);
vertex(0,height);
endShape();
}
function drawTree() {
for (var i = 0; i < trees.length; i++){
trees[i].move();
trees[i].display();
}
}
function makeTree(x) {
var tree = {
birth: x,
size: random(10, 30),
speed: 2.0,
move: TreeMove,
display: TreeDisplay,
height: random(30, 60),
color: [120, 150, 100, 90]
}
return tree;
}
function TreeMove() {
this.birth += this.speed;
}
function TreeDisplay() {
var treeHeight = 50;
fill(this.color);
noStroke();
push();
translate(this.birth, height - this.height);
ellipse(0, 0, this.size, this.size);
ellipse(7, 10, this.size, this.size+2);
ellipse(-9, 2, this.size, this.size);
stroke(200, 180, 140);
strokeWeight(2);
line(0, 0, 0, this.height);
line(0, this.size/5, this.size/6, this.size/20);
if (this.size > 30) {
line(0, this.size/3, -this.size/6, this.size/6);
}
pop();
}
function addTree() {
var newTree = 5;
if (random(0,1) < newTree) {
bwTrees = bwTrees + 30;
if (bwTrees == 4) {
trees.push(makeTree(width));
bwTrees = 0; //reset
}
}
}
// function songs(){
// fill(181, 165, 138);
// textSize(10);
// textFont("Times New Roman");
// text(playlist[index],10, 460);
// }
This assignment was a bit challenging for me. I had been missing road trips with my family so I decided to re-create one in the Himalayas, complete with the high mountain ranges and pine trees. I wanted to add running text of the playlist we tend to listen to so I’m still working on that.