xxxxxxxxxx
93
var song
function preload() {
soundFormats('wav')
song = loadSound('music/im blue_mixdown.wav');
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
// this function needs to have the same variables as the set up function because this function makes all the variables readjust whenever the screen size changes!
x = windowWidth/2;
y = windowHeight/2;
l = windowHeight;
w = windowWidth;
canvas.mousePressed(canvasPressed);
canvas.mouseReleased(canvasReleased);
}
function setup() {
let canvas = createCanvas(windowWidth, windowHeight);
//this stuff i learned in the coding lab, it makes it so that p5 knows that if your mouse is in the canvas, so it will activate only inside that space, in this sketch it doesn't do anythign because the canvas in windowWidth, but it will be cleaner if we do something that tracks
//notice that to do it you have to call the canvas a variable for the function mouseOut to know the area it's moving out of. Console logged for safety.
canvas.mousePressed(canvasPressed);
canvas.mouseReleased(canvasReleased);
canvas.mouseOut(function (){
// console.log("mouse left canvas");
canvasHovered = false;
})
canvas.mouseOver(function (){
// console.log("mouse over canvas");
canvasHovered = true;
})
//these variables are the white square that covers the surprise text
x = windowWidth/2;
y = windowHeight/2;
l = windowHeight;
w = windowWidth;
}
function draw() {
// color randomizer for reveal background
rparty = random(0, 255);
gparty = random(0, 255);
bparty = random(0, 255);
aparty = random(0, 255);
background(rparty,gparty,bparty,aparty);
//these are the three phrases. the last one is revealed on a click, with the party background.
let click = 'Click ME, you coward!';
let scared = 'You are too scared. I can tell.';
let daba = 'I am blue daba dee daba die';
if (mouseIsPressed) { // if the variable that start out as false becomes true, then show dabadee phrase
textAlign(CENTER);
textFont('Comic Sans MS');
textSize(width/20);
fill ('blue');
text(daba, width/2,height/3);
//background of this bit
fill(rparty,gparty,bparty,aparty);
rectMode(CENTER);
rect(x,y,w,l);
}
else { // if not, if the variable that starts out as false is false then show me cover screen
rectMode(CENTER);
fill ('white');
rect(x,y,w,l);
textFont('Georgia');
textSize(width/12);
fill ('red');
textAlign(CENTER,CENTER);
text(click, width/2,height/6);
textSize(width/50);
text(scared, width/2,height/3);
}
}
function canvasPressed() {
// playing a sound file on a user gesture
// is equivalent to `userStartAudio()`
song.play();
song.setVolume (1);
}
function canvasReleased (){
song.pause();
// song.stop();
}