xxxxxxxxxx
/*
* Load and Play Sound
* Red screen turns green when the user clicks on it and plays music
* Load sound during preload(). Play a sound when canvas is clicked.
*/
let song;
let angle = 0;
let radius = 75;
let rotateLine = false;
function preload() {
song = loadSound('felakuti.mp3');
}
function setup() {
// song.loop();
createCanvas(720, 200);
background(255, 0, 0);
angleMode(DEGREES);
}
function draw() {
//teken cirkel
noFill();
stroke('white');
strokeWeight(3);
circle(width/2, height/2, 150);
// teken lijn
strokeWeight(1);
// line(width/2, height/2, width/2, height/2 - 80);
// line(0,0, );
if (rotateLine === true) {
// move the origin to the pivot point
translate(width/2, height/2);
// rotate line
angle = angle + 1;
rotate(angle);
stroke('rgba(255,255,255,0.25)');
line(0,0, radius,0);
}
}
function mousePressed() {
if (song.isPlaying()) {
// .isPlaying() returns a boolean
song.stop();
background(255, 0, 0);
rotateLine = false;
} else {
song.play();
background(0, 255, 0);
rotateLine = true;
}
console.log("Rotate line staat op: " + rotateLine);
}