xxxxxxxxxx
115
let sound;
let sound2;
let sound3;
let sound4;cmm
function setup() {
createCanvas(400, 400);
sound = loadSound("Jingle-Bells.mp3");
sound2 = loadSound ("Christmas-tree-melody.mp3");
sound3 = loadSound ("We-wish-you-a-merry-christmas-ringtone.mp3");
sound4 = loadSound ("Christmas-ambience-audio-logo.mp3")
}
function draw() {
background(220);
//CHRISTMAS TREE
fill(0,131,86);
noStroke()
triangle(160, 115, 190, 60, 226, 115);
triangle(140, 155, 190, 80, 246, 155);
triangle(120, 210, 190,100, 266, 210);
triangle(100, 260, 190,120, 286, 260);
triangle(80, 325, 190, 140, 306, 325);
//trunk
fill(89, 57, 15);
rect(170,325,40,40);
//ORDAMENTS
//blue
fill(41,56,165);
ellipse(180,180,17,17)
ellipse(240,230,17,17);
ellipse(125,268,17,17)
ellipse(220,300,17,17)
//yellow
fill(239,149,0)
ellipse(183,110,17,17)
ellipse(205,150,17,17)
ellipse(162,155,17,17)
//STAR ORDAMENTS
//STAR
fill(237,155,0);
star(190,27,30,10,6);
}
//STAR CODE
function star(x, y, radius1, radius2, npoints) {
let angle = TWO_PI / npoints;
let halfAngle = angle / 2.0;
beginShape();
for (let a = 0; a < TWO_PI; a += angle) {
let sx = x + cos(a) * radius2;
let sy = y + sin(a) * radius2;
vertex(sx, sy);
sx = x + cos(a + halfAngle) * radius1;
sy = y + sin(a + halfAngle) * radius1;
vertex(sx, sy);
}
endShape(CLOSE);
}
function keyPressed() {
if (sound.isPlaying()) {
}
if (keyCode == 67) {
sound.play();
} else {
sound.stop();
}
if (sound2.isPlaying()) {
}
if (keyCode == 32) {
sound2.play();
} else {
sound2.stop();
}
if (sound3. isPlaying()) {
}
if(keyCode == 77) {
sound3.play();
} else {
sound3.stop();
}
if (sound4. isPlaying()) {
}
if(keyCode == 86) {
sound4.play();
} else {
sound4.stop();
}
}