xxxxxxxxxx
124
let currentflush;
let song;
let mic;
function setup(){
createCanvas(windowWidth,windowHeight);
angleMode(DEGREES);
rectMode(CENTER);
currentflush = mainpage;
mic = new p5.AudioIn();
mic.start();
song = loadSound('assets/Toilet-flush-sound.mp3');
}
function keyPressed() {
if (key == '1') {
currentflush = mainpage;
} else if (key == '2') {
currentflush = (flush1,toiletflush);
} else if (key == '3') {
currentflush = (flush2,toiletflush);
}else if (key =='4') {
currentflush = reset
} else if (key == 'f') {
let fs = fullscreen();
fullscreen(!fs);
}
}
function draw() {
currentflush();
}
function toiletflush() {
if (song.isPlaying()) {
// .isPlaying() returns a boolean
song.stop();
} else {
song.play();
}
}
function mainpage(){
background(0);
noFill();
translate(width/2,height/2)
for (var i = 0; i<200; i++){
push();
rotate(sin(frameCount+i)*200);
var r = map(sin(frameCount), -1,1,-50,255);
var g = map(sin(frameCount/2), -1,1,-50,255);
var b = map(sin(frameCount/4), -1,1,-50,255);
stroke(r,g,b);
rect(0,0,600 - i*3,600 - i*3, 200-i);
pop();
}
}
function flush1(){
background(0);
noFill();
translate(width/2,height/2)
for (var i = 0; i<200; i++){
push();
rotate(sin(frameCount+i)*900);
var r = map(sin(frameCount), 100,1,-50,255);
var g = map(sin(frameCount/2), -1,1,-50,255);
var b = map(sin(frameCount/4), -1,1,-50,255);
stroke(r,g,b);
rect(0,0,600 - i*6,600 - i*6, 200-i);
pop();
}
}
function flush2(){
background(0);
noFill();
translate(width/2,height/2)
for (var i = 0; i<200; i++){
push();
rotate(sin(frameCount+i)*1000*10);
var r = map(sin(frameCount), 100,1,-50,255);
var g = map(sin(frameCount/2), 100,1,-50,255);
var b = map(sin(frameCount/4), 100,200,-50,255);
stroke(r,g,b);
rect(0,0,600 - i*10,600 - i*10, 200-i);
pop();
}
}