/*
Rishabh Patni
This was intended to be an educational interaction that aims to teach children about seasons. Click on the buttons to select a season and enjoy various interactions across different seasons. Hopefully, I'll add more funtionality soon!
1. Pan your mouse from left to right, day turns into night
2. Control the rain/snow with the movement of your cursor
3. Click on the sky to draw clouds
*/
// var acceleration = 0.0098;
// var nDrops = 1500;
// var drops = [];
//Bird1 starting position//
let bird1X = 400
let bird1Y = 520
//Bird2 starting position//
let bird2X = 520
let bird2Y = 520
//Bird3 starting position//
let bird3X = -20
let bird3Y = 520
//Cloud1 starting position//
let cloud1X=0
let cloud1Y=270
//Cloud2 starting position//
let cloud2X=120
let cloud2Y=160
//Cloud3 starting position//
let cloud3X=220
let cloud3Y=240
//Cloud4 starting position//
let cloud4X=400
let cloud4Y=180
//Cloud5 starting position//
let cloud5X=450
let cloud5Y=260
// A variable to hold the new Snow object
var mySnow;
//Initializing an array to hold multiple Snow objects
var allMySnow = [];
// A variable to hold the new Rain object
var myRain;
//Initializing an array to hold multiple Rain objects
var allMyRain = [];
//Initializing an array to hold multiple cloud objects
var clouds = [];
//Setting starting schene
let pageNum = 1
//Defines the variable that tells us what frame count we are on//
let OddOrEven
function setup() {
createCanvas(500, 600);
frameRate(10); //Speed of loops//
// Creating a new Snow object and assigning it to the variable
mySnow = new Snow();
// For loop to add Snow objects to the array
for (var i = 0; i < 800; i++) {
allMySnow[i] = new Snow();
}
// Creating a new Rain object and assigning it to the variable
myRain = new Rain();
// For loop to add Rain objects to the array
for (var i = 0; i < 800; i++) {
allMyRain[i] = new Rain();
}
noStroke()
}
function mouseClicked() {
if( (mouseX >= 20) && (mouseX <= 120) && (mouseY >=540 ) && (mouseY <= 580) ){
pageNum = 1;
} else if( (mouseX >= 140) && (mouseX <= 240) && (mouseY >=540 ) && (mouseY <= 580) ) {
pageNum = 2;
} else if( (mouseX >= 260) && (mouseX <= 360) && (mouseY >=540 ) && (mouseY <= 580) ) {
pageNum = 3;
} else if( (mouseX >= 380) && (mouseX <= 480) && (mouseY >=540 ) && (mouseY <= 580) ) {
pageNum = 4;
}
if(mouseY < 340){
var newCloud = {
xpos: mouseX,
ypos: mouseY,
size: random(1.2, 2.4),
}
clouds.push(newCloud);
}
}
function draw() {
//This to map the movement of the mouse and change the background color in the shade of blue//
let R1 = map(mouseX, 0, width, 120, 20, true);
let G1 = map(mouseX, 0, width, 180, 20, true);
let B1 = map(mouseX, 0, width, 240, 40, true);
background(R1,G1,B1);
noStroke()
//This defines the OddOrEven variable as 10% of the frame count//
OddOrEven = (frameCount %10)
if (OddOrEven == 1){
flapMotion = -20;
} else {
flapMotion = +20
}
// Change Season //
if (pageNum == 1){
drawFall();
} else if (pageNum == 2){
drawWinter();
drawSnow();
} else if (pageNum == 3){
drawSpring();
drawRain();
} else if (pageNum == 4){
drawSummer();
drawTree(20, 455);
drawTree(60, 455);
drawTree(120, 455);
drawTree(150, 455);
drawTree(200, 455);
drawTree(200, 455);
drawTree(240, 455);
drawTree(300, 455);
drawTree(340, 455);
drawTree(390, 455);
drawTree(440, 455);
drawTree(460, 455);
drawTree(500, 455);
drawTree(40, 465);
drawTree(90, 465);
drawTree(5, 465);
drawTree(170, 465);
drawTree(220, 465);
drawTree(260, 465);
drawTree(280, 465);
drawTree(320, 465);
drawTree(360, 465);
drawTree(420, 465);
drawTree(480, 465);
}
//Draw all tree trunks
noStroke()
drawTrunk(20, 455);
drawTrunk(60, 455);
drawTrunk(120, 455);
drawTrunk(150, 455);
drawTrunk(200, 455);
drawTrunk(200, 455);
drawTrunk(240, 455);
drawTrunk(300, 455);
drawTrunk(340, 455);
drawTrunk(390, 455);
drawTrunk(440, 455);
drawTrunk(460, 455);
drawTrunk(500, 455);
drawTrunk(40, 465);
drawTrunk(90, 465);
drawTrunk(5, 465);
drawTrunk(170, 465);
drawTrunk(220, 465);
drawTrunk(260, 465);
drawTrunk(280, 465);
drawTrunk(320, 465);
drawTrunk(360, 465);
drawTrunk(420, 465);
drawTrunk(480, 465);
// Randomized movement of objects
for (i = 0; i < clouds.length; i++) {
var trippy = clouds[i];
drawCloud(trippy.xpos, trippy.ypos, trippy.size, "white");
trippy.xpos += 2;
trippy.ypos += random(-0.5, 0.5);
}
/* noStroke();
fill('red');
ellipse(mouseX, mouseY, 4, 4);
text(mouseX + ',' + mouseY, width/2, height/2);*/
//Sun / Moon//
let sun = map(mouseX, 0, width, 120, -240, true);
fill(255,255,0,255)
ellipse(120, sun, 80, 80);
fill(255,255,0,80)
ellipse(120, sun, 100, 100);
fill(255,255,0,60)
ellipse(120, sun, 130, 130);
fill(255,255,0,40)
ellipse(120, sun, 160, 160);
fill(255,255,0,20)
ellipse(120, sun, 200, 200);
//Changes color of moon with change in x-axis//
let moon = map(mouseX, 0, width, -240, 120, true);
fill('white')
ellipse(120, moon, 75, 75);
//Stars//
//Increases size of stars with change in x-axis//
let stars = map(mouseX, 0, width, 0, 4, true);
fill('white')
ellipse(370, 50, stars, stars);
ellipse(35, 90, stars, stars);
ellipse(130, 200, stars, stars);
ellipse(190, 30, stars, stars);
ellipse(280, 120, stars, stars);
ellipse(370, 50, stars, stars);
ellipse(440, 150, stars, stars);
ellipse(470, 30, stars, stars);
ellipse(355, 190, stars, stars);
ellipse(20, 165, stars, stars);
ellipse(180, 145, stars, stars);
fill('yellow')
ellipse(440, 80, stars, stars);
ellipse(80, 160, stars, stars);
ellipse(300, 30, stars, stars);
ellipse(350, 120, stars, stars);
ellipse(80, 35, stars, stars);
ellipse(225, 180, stars, stars);
ellipse(190, 90, stars, stars);
//Clouds//
//Changes color of clouds with change in x-axis//
let cloudColor = map(mouseX, 0, width, 255, 60, true);
fill(cloudColor+70);
arc(cloud2X, cloud2Y, 30 * 3, 30 * 2, PI + TWO_PI, TWO_PI);
arc(cloud2X + 10, cloud2Y, 30 * 2, 45 * 2, PI + TWO_PI, TWO_PI);
arc(cloud2X + 40, cloud2Y, 40 * 2, 35 * 2, PI + TWO_PI, TWO_PI);
arc(cloud2X + 50, cloud2Y, 40 * 3, 20 * 2, PI + TWO_PI, TWO_PI);
cloud2X=cloud2X + 2
if(cloud2X > 570){
cloud2X = -110
}
fill(cloudColor+50);
arc(cloud4X, cloud4Y, 30 * 2, 20 * 2, PI + TWO_PI, TWO_PI);
arc(cloud4X + 10, cloud4Y, 25 * 2, 45 * 2, PI + TWO_PI, TWO_PI);
arc(cloud4X + 25, cloud4Y, 25 * 2, 35 * 2, PI + TWO_PI, TWO_PI);
arc(cloud4X + 40, cloud4Y, 30 * 2, 20 * 2, PI + TWO_PI, TWO_PI);
cloud4X=cloud4X + 2
if(cloud4X > 570){
cloud4X = -70
}
fill(cloudColor);
arc(cloud1X, cloud1Y, 30 * 2, 20 * 2, PI + TWO_PI, TWO_PI);
arc(cloud1X + 10, cloud1Y, 25 * 2, 45 * 2, PI + TWO_PI, TWO_PI);
arc(cloud1X + 25, cloud1Y, 25 * 2, 35 * 2, PI + TWO_PI, TWO_PI);
arc(cloud1X + 40, cloud1Y, 30 * 2, 20 * 2, PI + TWO_PI, TWO_PI);
cloud1X=cloud1X + 2
if(cloud1X > 570){
cloud1X = -70
}
fill(cloudColor+20);
arc(cloud3X, cloud3Y, 30 * 3, 30 * 2, PI + TWO_PI, TWO_PI);
arc(cloud3X + 20, cloud3Y, 30 * 2, 45 * 2, PI + TWO_PI, TWO_PI);
arc(cloud3X + 30, cloud3Y, 40 * 2, 35 * 2, PI + TWO_PI, TWO_PI);
arc(cloud3X + 50, cloud3Y, 40 * 3, 20 * 2, PI + TWO_PI, TWO_PI);
cloud3X=cloud3X + 2
if(cloud3X > 570){
cloud3X = -110
}
fill(cloudColor+20);
arc(cloud5X, cloud5Y, 30 * 2, 20 * 2, PI + TWO_PI, TWO_PI);
arc(cloud5X + 10, cloud5Y, 25 * 2, 45 * 2, PI + TWO_PI, TWO_PI);
arc(cloud5X + 25, cloud5Y, 25 * 2, 35 * 2, PI + TWO_PI, TWO_PI);
arc(cloud5X + 40, cloud5Y, 30 * 2, 20 * 2, PI + TWO_PI, TWO_PI);
cloud5X=cloud5X + 2
if(cloud5X > 570){
cloud5X = -70
}
//Bird1//
fill('black')
quad(bird1X, bird1Y, bird1X-25, bird1Y-flapMotion, bird1X, bird1Y-10, bird1X+25, bird1Y-flapMotion)
if(bird1X > 250){
bird1X = bird1X - 2
}
if(bird1Y > 250){
bird1Y = bird1Y - 2
}
//Bird2//
fill('black')
quad(bird2X, bird2Y, bird2X-25, bird2Y-flapMotion, bird2X, bird2Y-10, bird2X+25, bird2Y-flapMotion)
if(bird2X > 140){
bird2X = bird2X - 2.8
}
if(bird2Y > 250){
bird2Y = bird2Y - 2.8
}
//Bird3//
fill('black')
quad(bird3X, bird3Y, bird3X-25, bird3Y-flapMotion, bird3X, bird3Y-10, bird3X+25, bird3Y-flapMotion)
if(bird3X < 360){
bird3X = bird3X + 2.8
}
if(bird3Y > 250){
bird3Y = bird3Y - 2.8
}
// Time of the day
fill(120)
rect(0,0,500,20)
textSize(12)
fill("white")
text("12 PM", 12, 12)
text("2 PM", 84, 12)
text("4 PM", 156, 12)
text("6 PM", 228, 12)
text("8 PM", 300, 12)
text("10 PM", 372, 12)
text("12 AM", 454, 12)
strokeWeight(1.5);
stroke(255);
line(30, 20, 30, 16);
line(100, 20, 100, 16);
line(170, 20, 170, 16);
line(240, 20, 240, 16);
line(310, 20, 310, 16);
line(385, 20, 385, 16);
line(470, 20, 470, 16);
strokeWeight(4)
line(mouseX, 20, mouseX, 25);
// Control Panel //
noStroke()
fill(120)
rect(0,500,500,300)
fill(160)
rect(20, 540, 100, 40)
fill(160)
rect(140, 540, 100, 40)
fill(160)
rect(260, 540, 100, 40)
fill(160)
rect(380, 540, 100, 40)
textFont("sans-serif", 20);
fill(255)
text("Fall", 52, 567)
text("Winter", 157, 567)
text("Spring", 279, 567)
text("Summer", 389, 567)
textSize(18)
fill("white")
text("Click on the season you want to see", 115, 525)
}
// 1. Draw Fall
function drawFall() {
//Mountain 1//
let mR1 = map(mouseX, 0, width, 90, 25, true);
let mG1 = map(mouseX, 0, width, 60, 10, true);
let mB1 = map(mouseX, 0, width, 30, 5, true);
fill(mR1,mG1, mB1);
triangle(100,500, 310, 340, 540,500);
//Mountain 2//
let mR2 = map(mouseX, 0, width, 110, 30, true);
let mG2 = map(mouseX, 0, width, 70, 15, true);
let mB2 = map(mouseX, 0, width, 30, 10, true);
fill(mR2, mG2, mB2);
triangle(0,500, 200, 320, 420,520);
//Mountain 3//
let mR3 = map(mouseX, 0, width, 130, 40, true);
let mG3 = map(mouseX, 0, width, 80, 20, true);
let mB3 = map(mouseX, 0, width, 30, 15, true);
fill(mR3, mG3, mB3);
triangle(180,500, 420, 300, 700,500);
//Mountain 4//
let mR4 = map(mouseX, 0, width, 145, 45, true);
let mG4 = map(mouseX, 0, width, 85, 25, true);
let mB4 = map(mouseX, 0, width, 25, 15, true);
fill(mR4, mG4, mB4);
triangle(-180,500, 40, 290, 280,500);
//Snow Cap 4//
let snowColor = map(mouseX, 0, width, 255, 160, true);
fill(snowColor);
beginShape();
vertex(40,290);
vertex(110,350);
vertex(60,338);
vertex(45,350);
vertex(20,330);
vertex(-10,340);
endShape();
//Snow Cap 3//
fill(snowColor-40);
beginShape();
vertex(200, 320);
vertex(234,352);
vertex(206,346);
vertex(200,356);
vertex(190,342);
vertex(172,346);
endShape();
//Snow Cap 2//
fill(snowColor-30);
beginShape();
vertex(420, 300);
vertex(480,342);
vertex(444,336);
vertex(414,352);
vertex(400,335);
vertex(366,345);
endShape();
//Snow Cap 1//
fill(snowColor-50);
beginShape();
vertex(310, 340);
vertex(330,355);
vertex(320,352);
vertex(310,358);
vertex(306,352);
vertex(292,355);
endShape();
}
// 1.1 Draw tree leaves
function drawTree(x, y) {
let treeR = map(mouseX, 0, width, 60, 20, true);
let treeG = map(mouseX, 0, width, 240, 80, true);
fill(treeR, treeG, 0)
beginShape();
// Vertices of tree are defined relative to (0, 0) point
vertex(x+0, y-35);
vertex(x-12, y-15);
vertex(x-5, y-15);
vertex(x-18, y+2);
vertex(x-10, y+2);
vertex(x-24, y+24);
vertex(x+24, y+24);
vertex(x+10, y+2);
vertex(x+18, y+2);
vertex(x+5, y-15);
vertex(x+12, y-15);
endShape(CLOSE);
}
// 1.2 Draw tree trunks
function drawTrunk(x, y) {
let trunkR = map(mouseX, 0, width, 120, 30, true);
let trunkG = map(mouseX, 0, width, 50, 10, true);
let trunkB = map(mouseX, 0, width, 15, 10, true);
fill(trunkR, trunkG, trunkB)
beginShape();
vertex(x+0, y-35);
vertex(x-3, y);
vertex(x-5, y+45);
vertex(x+5, y+45);
vertex(x+3, y);
endShape(CLOSE);
beginShape();
vertex(x, y-25);
vertex(x-10, y-18);
vertex(x, y-22);
endShape(CLOSE);
beginShape();
vertex(x, y-20);
vertex(x+10, y-18);
vertex(x, y-18);
endShape(CLOSE);
beginShape();
vertex(x, y-12);
vertex(x+15, y);
vertex(x, y-7);
endShape(CLOSE);
beginShape();
vertex(x, y-2);
vertex(x-15, y);
vertex(x, y-7);
endShape(CLOSE);
beginShape();
vertex(x, y+18);
vertex(x+20, y+20);
vertex(x, y+12);
endShape(CLOSE);
beginShape();
vertex(x, y+12);
vertex(x-20, y+20);
vertex(x, y+4);
endShape(CLOSE);
}
// 2. Draw Winter
function drawWinter() {
let snowColor = map(mouseX, 0, width, 255, 160, true);
//Mountain 1//
fill(snowColor-50);
triangle(100,500, 310, 340, 540,500);
//Mountain 2//
fill(snowColor-40);
triangle(0,500, 200, 320, 420,520);
//Mountain 3//
fill(snowColor-30);
triangle(180,500, 420, 300, 700,500);
//Mountain 4//
fill(snowColor);
triangle(-180,500, 40, 290, 280,500);
//Snow Cap 4//
fill(snowColor);
beginShape();
vertex(40,290);
vertex(110,350);
vertex(60,338);
vertex(45,350);
vertex(20,330);
vertex(-10,340);
endShape();
//Snow Cap 3//
fill(snowColor-40);
beginShape();
vertex(200, 320);
vertex(234,352);
vertex(206,346);
vertex(200,356);
vertex(190,342);
vertex(172,346);
endShape();
//Snow Cap 2//
fill(snowColor-30);
beginShape();
vertex(420, 300);
vertex(480,342);
vertex(444,336);
vertex(414,352);
vertex(400,335);
vertex(366,345);
endShape();
//Snow Cap 1//
fill(snowColor-50);
beginShape();
vertex(310, 340);
vertex(330,355);
vertex(320,352);
vertex(310,358);
vertex(306,352);
vertex(292,355);
endShape();
}
// 2.1 Draw Snow
function drawSnow() {
//Loop over array to draw all snow
for (var i = 0; i < allMySnow.length; i++) {
allMySnow[i].display();
allMySnow[i].move();
}
}
// 2.2 Draw Rain
function drawRain() {
//Loop over array to draw all snow
for (var i = 0; i < allMyRain.length; i++) {
allMyRain[i].display();
allMyRain[i].move();
}
}
// 3. Draw Spring
function drawSpring() {
//Mountain 1//
let mR1 = map(mouseX, 0, width, 20, 10, true);
let mG1 = map(mouseX, 0, width, 120, 35, true);
let mB1 = map(mouseX, 0, width, 30, 20, true);
fill(mR1,mG1, mB1);
triangle(100,500, 310, 340, 540,500);
//Mountain 2//
let mR2 = map(mouseX, 0, width, 20, 10, true);
let mG2 = map(mouseX, 0, width, 140, 40, true);
let mB2 = map(mouseX, 0, width, 30, 20, true);
fill(mR2, mG2, mB2);
triangle(0,500, 200, 320, 420,520);
//Mountain 3//
let mR3 = map(mouseX, 0, width, 20, 10, true);
let mG3 = map(mouseX, 0, width, 170, 50, true);
let mB3 = map(mouseX, 0, width, 30, 20, true);
fill(mR3, mG3, mB3);
triangle(180,500, 420, 300, 700,500);
//Mountain 4//
let mR4 = map(mouseX, 0, width, 10, 10, true);
let mG4 = map(mouseX, 0, width, 200, 60, true);
let mB4 = map(mouseX, 0, width, 20, 20, true);
fill(mR4, mG4, mB4);
triangle(-180,500, 40, 290, 280,500);
//Snow Cap 4//
let snowColor = map(mouseX, 0, width, 255, 160, true);
fill(snowColor);
beginShape();
vertex(40,290);
vertex(110,350);
vertex(60,338);
vertex(45,350);
vertex(20,330);
vertex(-10,340);
endShape();
//Snow Cap 3//
fill(snowColor-40);
beginShape();
vertex(200, 320);
vertex(234,352);
vertex(206,346);
vertex(200,356);
vertex(190,342);
vertex(172,346);
endShape();
//Snow Cap 2//
fill(snowColor-30);
beginShape();
vertex(420, 300);
vertex(480,342);
vertex(444,336);
vertex(414,352);
vertex(400,335);
vertex(366,345);
endShape();
//Snow Cap 1//
fill(snowColor-50);
beginShape();
vertex(310, 340);
vertex(330,355);
vertex(320,352);
vertex(310,358);
vertex(306,352);
vertex(292,355);
endShape();
}
// 4. Draw Summer
function drawSummer() {
//Mountain 1//
let mR1 = map(mouseX, 0, width, 20, 10, true);
let mG1 = map(mouseX, 0, width, 120, 35, true);
let mB1 = map(mouseX, 0, width, 30, 20, true);
fill(mR1,mG1, mB1);
triangle(100,500, 310, 340, 540,500);
//Mountain 2//
let mR2 = map(mouseX, 0, width, 20, 10, true);
let mG2 = map(mouseX, 0, width, 140, 40, true);
let mB2 = map(mouseX, 0, width, 30, 20, true);
fill(mR2, mG2, mB2);
triangle(0,500, 200, 320, 420,520);
//Mountain 3//
let mR3 = map(mouseX, 0, width, 20, 10, true);
let mG3 = map(mouseX, 0, width, 170, 50, true);
let mB3 = map(mouseX, 0, width, 30, 20, true);
fill(mR3, mG3, mB3);
triangle(180,500, 420, 300, 700,500);
//Mountain 4//
let mR4 = map(mouseX, 0, width, 10, 10, true);
let mG4 = map(mouseX, 0, width, 200, 60, true);
let mB4 = map(mouseX, 0, width, 20, 20, true);
fill(mR4, mG4, mB4);
triangle(-180,500, 40, 290, 280,500);
}
// Draw cloud
function drawCloud(xpos, ypos, size, rColor) {
fill(rColor);
noStroke();
arc(xpos, ypos, 30 * size, 30 * size, PI + TWO_PI, TWO_PI);
arc(xpos + 10, ypos, 30 * size, 45 * size, PI + TWO_PI, TWO_PI);
arc(xpos + 40, ypos, 40 * size, 35 * size, PI + TWO_PI, TWO_PI);
arc(xpos + 50, ypos, 40 * size, 20 * size, PI + TWO_PI, TWO_PI);
}
//Object: Snow
class Snow {
constructor() {
this.x = round(random(-400, 1000));
this.y = round(random(0, height));
this.size = random(1, 4);
this.speed = random(1, 6);
}
display() {
//Draws the concentric circles
noStroke();
fill("white");
circle(this.x, this.y, this.size);
}
move() {
let dir = map(mouseX, 0, width, -this.speed/5, this.speed/5, true);
let sp = map(mouseY, 0, height, this.speed/5, this.speed, true);
//Moves the circles in different speeds
this.y += sp;
this.x += dir
//Brings the object back to the top of the canvas
if (this.y > height) {
this.y = 0;
}
}
}
//Object: Rain
class Rain {
constructor() {
this.x = round(random(-400, 1000));
this.y = round(random(0, height));
this.z = random(0, 20);
this.len = map(this.z, 0, 20, 2, 5);
this.speed = random(10, 20);
}
display() {
let dropColor = map(mouseX, 0, width, 60, 160, true);
var thick = map(this.z, 0, 20, 0.6, 1.8);
strokeWeight(thick);
stroke(dropColor,dropColor,255);
line(this.x, this.y, this.x, this.y + this.len);
}
move() {
let dir = map(mouseX, 0, width, -this.speed/7, this.speed/5, true);
let sp = map(mouseY, 0, height, this.speed/2, this.speed, true);
//Moves the circles in different speeds
this.y += sp;
this.x += dir
//Brings the object back to the top of the canvas
if (this.y > height) {
this.y = 0;
}
}
}
This Pen doesn't use any external CSS resources.