//Lydia Jin
//Section B
//jialuj@andrew.cmu.edu
//Project 10
var stars = [];
var BacSpd;
var newCloudProbability;
function setup() {
createCanvas(600, 400);
//initialize variables
BacSpd = 0.0003; //background mountain speed
StarProb = 6; //set star appear probability to 6%
//preset 20 stars when launch
for (var i = 0; i < 20; i++) {
stars[i] = new Star(random(width));
}
}
//-----------------------------------------
function draw() {
noStroke();
//Create gradient color for the background
topColor = color(48, 58, 48);
botColor = color(162, 98, 85);
//gradient color steps
var gradientSteps = height;
for (var i = 0; i <= gradientSteps; i++) { //for each gradient strip
fill(lerpColor(topColor, botColor, i/height)); //fill color inerpolation
rect(0, (i/height * height) - (1/height * height), width, 1/height * height); //use the color draw boxes
}
//Generate random mountain landscape by using noise
//The moving speed is controlled by BacSpeed and noise level
for (var j = 0; j < width; j++) {
var t = height - 0.70 * height * noise(j * 0.005 + millis() * BacSpd);
stroke('black');
line(j, height, j, t);
}
//add a new star to canvas in the chance of 6%
if (StarProb > random(0,100)) {
stars.push(new Star(width));
}
for (var i = 0; i < stars.length; i++) {
stars[i].move(); //update star array
stars[i].display();
if (stars[i].x < 0) { //if star goes out of boundary, remove it
stars.splice(i, 1);
}
}
}
//generate stars
function Star(xx){
this.x = xx;
this.y = random(1, 130); //set vertical range for starts
this.speed = (-1.5); //set speed
this.move = function() {
this.x += this.speed;
}
this.display = function() {
push();
stroke('yellow');
point(this.x, this.y);
pop();
}
}
I used the terrain template to create this project. I wanted to create a night view of mountains and stars. I used random function to generate random numbers of stars that appear at random times. Then, because I want to make a contrast between the mountains and night sky, I used lerp color to create a gradient colored sky that looks like a gloomy day right after sunshine and when stars first appear. The product is a moving image that looks like the scenery you would see if you are driving in rural areas at night. The theme is quiet and calming.