xxxxxxxxxx
145
/*
Alina Perdomo
Final Project
12/21/22
Vectors taken from Freepik:
https://www.freepik.com/premium-vector/decorated-christmas-room_11146942.htm?query=living+room&collectionId=1768&position=23&from_view=collections
Sound:
Christmas sound by:
https://www.shockwave-sound.com/sound-effects/christmas-sounds/jnglbell.wav
*/
let gifts, livingR, tree, christmasSound, giftsUnder;
let snowflakes = 20;
let snowSlider;
function setup() {
createCanvas(550, 400);
snowSlider = createSlider(0, 400, 200);
snowSlider.position(20, height - 15);
snowSlider.addClass("sliderA")
}
function preload() {
gifts = loadImage("gifts.png");
livingR = loadImage("livingR3.png");
tree = loadImage("tree.png");
christmasSound = loadSound("jnglbell.wav");
}
function keyPressed() {
var x = width / 2;
var y = height / 2;
if (keyCode === 32) {
// space
christmasSound.loop();
}
}
function keyReleased() {
if ( keyCode === 32) {
// space
christmasSound.pause();
}
}
function draw() {
var x = width / 2;
var y = height / 2;
textFont("Arial");
background("rgb(8,8,63)");
/**/
fill('white');
noStroke();
snowflakes = snowSlider.value();
for (let s = 0; s < snowflakes; s++) {
circle(random(width), random(200), random(1, 5));
}
//living room
imageMode(CENTER);
image(livingR, x, y);
//tree mat
var treeP = 75 //tree's position for (x)
noStroke();
fill("rgb(201,176,176)");
ellipse(x + treeP, y + 150, 180, 60);
fill("rgb(125,15,15)");
ellipse(x + treeP, y + 150, 110, 30);
//tree
image(tree, x + treeP, y - 10);
//chritsmas lights
var circleS = 10; //circle Size
var r = random(150, 255);
var g = random(50,255);
var b = random(200, 255);
if (!keyIsDown(32)) {
// space
fill("white");
} else {
// space
fill(r, g, b);
noStroke();
}
var lightsX = 62
var lightsY = 20
circle(x + 150 - lightsX, y - 110 , circleS);
circle(x + 115 - lightsX, y - 50 , circleS);
circle(x + 170 - lightsX, y - 40 , circleS);
circle(x + 95 - lightsX, y, circleS);
circle(x + 135 - lightsX, y + 20, circleS);
circle(x + 180 - lightsX, y + 10 , circleS);
circle(x + 75 - lightsX, y + 65 , circleS);
circle(x + 215 - lightsX, y + 75 , circleS);
circle(x + 150 - lightsX, y + 80, circleS);
if (key === "g") {
//letter g
image(gifts, x + 70, y + 110);
}
else if (key === "a") {
image(gifts, x + 500, y + 500);
}
fill ('rgba(158,158,158,0.66)');
textSize(12);
text ("*Press 'space' to turn on the christmas lights.", 15, height - 55)
text ("*Type 'g' to see the gifts under the tree.", 15, height - 40);
text ("Otherwise, type 'a' to make them dissapear.", 20, height - 25)
text ("Move the slider to change the course of the snow.", 115, height - 8)
}