xxxxxxxxxx
224
//BUTTON//
var nextSlideActive = false;
var prevSlideActive = false;
//--------------//----------------
let carX = 0;
let currentLandscape = 1; // Variable to track the current landscape
let birdImg1, birdImg2; // Variables to store the bird images
let birdX, birdY; // Variables to keep track of the bird's position
let sound1, sound2; // Variables to store audio files
function preload() {
// Load the bird images for each landscape
birdImg1 = loadImage('daybird.png');
birdImg2 = loadImage('nightbird.png');
// Load the audio files for each landscape
sound1 = loadSound('daybirdsound.mp3');
sound2 = loadSound('owl.wav');
}
function setup() {
createCanvas(600, 400);
landscape(); // Initial landscape
// // var landscapeButton = createButton("Generate a Landscape");
// landscapeButton.mousePressed(landscape);
var saveButton = createButton("Save Image");
saveButton.mousePressed(saveImage);
var switchButton = createButton("Switch Landscape");
switchButton.mousePressed(switchLandscape);
}
function saveImage(){
save("Landscape.png");
}
function switchLandscape(){
currentLandscape = (currentLandscape === 1) ? 2 : 1; // Toggle between landscape 1 and 2
landscape(); // Redraw the landscape
}
function draw(){
if (frameCount % 10 === 0) {
landscape();
}
// Update bird's position based on mouse
birdX = mouseX;
birdY = mouseY;
// Draw bird image at the updated position based on the current landscape
if (currentLandscape === 1) {
image(birdImg1, birdX, birdY, 150, 150);
textAlign(CENTER)
textSize(40);
textFont("Jersey 10");
fill("#FFEB3B")
text("Morning Vibes", width/2 , height/2 + 30);
} else {
image(birdImg2, birdX, birdY, 150 ,150);
textAlign(CENTER)
textSize(40);
textFont("Jersey 10");
fill("#D1DCE1")
text("Night Vibes", width/2 , height/2 + 30);
}
}
function landscape() {
if (currentLandscape === 1) {
// First landscape scenario
background("#E6A039");
// Play the audio for landscape 1
if (!sound1.isPlaying()) {
sound1.play();
}
//----------------------------------function calls:
cloud(100, 100, "white");
// building(0, 60, 150);
tree(100, 210, 100);
// Rest of the code for landscape 1...
//-------------------------------------------
//sun
noStroke();
fill("yellow");
circle(300, 130, 250);
//street
fill("#028000");
noStroke();
rect(0, 300, width, 100);
//asfalt
fill("#3F3838");
noStroke();
rect(0, 330, width, 100);
//clouds
fill("white");
circle(100,100,50);
circle(120,120,50);
circle(80,120,50);
//clouds & trees LOOP
for (var x = 0; x <= width; x += 50) {
var y = random(20, 140);
cloud(x, y, 'white');
var s = random(50, 100);
tree(x, 220, s);
}
//moving truck
drawCar(carX, 200);
carX += 10;
if (carX > width) {
carX = -200;
}
function drawCar(x, y) {
fill("black");
circle(x + 20, y + 160, 40);
circle(x + 180, y + 160, 40);
fill("#1B4D74");
rect(x, y + 80, 200, 80);
fill("#E91E63");
rect(x + 200, y + 100, 50, 60, 5);
fill("#FCFCFC");
rect(x + 220, y + 100, 30, 25, 5);
}
} else {
// Second landscape scenario
background("#4B2E6B");
// Play the audio for landscape 2
if (!sound2.isPlaying()) {
sound2.play();
}
//----------------------------------function calls:-------------------------------------------
//moon
noStroke();
fill("rgba(251,251,243,0.93)");
circle(300, 130, 250);
//street
fill("#028000");
noStroke();
rect(0, 300, width, 100);
//asfalt
fill("rgb(31,31,31)");
noStroke();
rect(0, 330, width, 100);
//clouds
fill("rgba(255,255,255,0.7)");
circle(100,100,50);
circle(120,120,50);
circle(80,120,50);
//clouds & trees LOOP
for (var x = 0; x <= width; x += 75) {
var y = random(20, 140);
cloud(x, y, 'rgba(255,255,255,0.86)');
var s = random(50, 100);
tree(x, s);
}
//moving truck
drawCar(carX, 200);
carX += 15;
if (carX > width) {
carX = -200;
}
function drawCar(x, y) {
fill("rgb(232,223,223)");
circle(x + 20, y + 160, 40);
circle(x + 180, y + 160, 40);
fill("#1B745A");
rect(x, y + 80, 200, 80);
fill("#FFC107");
rect(x + 200, y + 100, 50, 60, 5);
fill("#FCFCFC");
rect(x + 220, y + 100, 30, 25, 5);
}
}
}
//-----------------------------------function declarations
//trees
function tree(x, s) {
fill('brown');
rect(x, 100, 20, 210, 5);
fill('#4A664B');
triangle(x - 50, 270, x +10, 50, x + 70, 270);
triangle(x - 40, 200, x + 10, 50, x + 60, 200);
triangle(x - 30, 130, x + 10, 50, x + 50, 130);
}
//cloud
function cloud(x, y, c) {
fill(c);
noStroke();
circle(x, y, 50);
circle(x + 20, y + 20, 50);
circle(x - 20, y + 20, 50);
}