xxxxxxxxxx
207
let currentflush
let song1;
let song2;
let song3;
let mic;
let smoothSizeOfCircle = 0;
let myFont;
function preload(){
currentflush = mainpage;
song1 = loadSound('assets/toilet-flush-1.mp3');
song2 = loadSound('assets/salamisound-3780183-toilets-pressure-flushing.mp3');
song3 = loadSound('assets/salamisound-1020005-flushing-toilets-built-in.mp3');
myFont = loadFont('assets/NeueMontreal-Bold.ttf');
}
function setup(){
createCanvas(windowWidth,windowHeight);
angleMode(DEGREES);
rectMode(CENTER);
mic = new p5.AudioIn();
mic.start();
}
function keyPressed() {
if (key == '1') {
currentflush = mainpage;
;(song1.stop());
} else if (key == '2') {
currentflush = flush1;
;(song1.play());
} else if (key == '3') {
currentflush = flush2;
;(song2.play());
} else if (key =='4') {
currentflush = flush3
;(song3.play());
} else if (key == 'f') {
let fs = fullscreen();
fullscreen(!fs);
}
}
function draw() {
currentflush();
// The text 'The quick brown fox jumped over the lazy dog' displayed.
// text example 1
textSize(25);
let s = 'To flush, press 2,3 or 4. Otherwise press 1 to reset or f-key to enter fullscreen 😊';
fill(255,255,255);
text(s, -630, -350, 400, 90); // Text wraps within text box
}
function toiletflush1() {
if (song.isPlaying()) {
// .isPlaying() returns a boolean
song.stop();
} else {
song.play();
}
}
function toiletflush2() {
if (song.isPlaying()) {
// .isPlaying() returns a boolean
song.stop();
} else {
song.play();
}
}
function mainpage(){
background(0);
//noFill();
fill(0, 102, 153);
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);
ellipse(0,15,600 - i*3,600 - i*3, 200-i);
pop();
}
}
function flush1(){
//background(100);
fill(0, 102, 153);
translate(width/2,height/2)
scale(2);
for (var i = 0; i<200; i++){
let intensity = mic.getLevel();
let sizeOfCircle = map(intensity, 0, 2, 20, 2000);
smoothSizeOfCircle += (sizeOfCircle - smoothSizeOfCircle) * 0.2;
push();
rotate(sin(frameCount+i)*smoothSizeOfCircle);
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 flush2(){
let intensity = mic.getLevel();
//background(0);
fill(0, 102, 153);
translate(width/2,height/2)
scale(4);
for (var i = 0; i<200; i++){
let intensity = mic.getLevel();
let sizeOfCircle = map(intensity, 0, 2, 20, 2000);
smoothSizeOfCircle += (sizeOfCircle - smoothSizeOfCircle) * 0.5;
push();
rotate(sin(frameCount+i)*smoothSizeOfCircle);
var r = map(sin(frameCount), -2,1,-50,255);
var g = map(sin(frameCount/2), -2,1,-50,255);
var b = map(sin(frameCount/4), -2,1,-50,255);
stroke(r,g,b);
rect(0,0,600 - i*3,600 - i*3, 200-i);
pop();
}
}
function flush3(){
background(0);
//noFill();
fill(0, 102, 153);
translate(width/2,height/2)
scale(6);
for (var i = 0; i<200; i++){
let intensity = mic.getLevel();
let sizeOfCircle = map(intensity, 0, 2, 20, 2000);
smoothSizeOfCircle += (sizeOfCircle - smoothSizeOfCircle) * 0.5;
push();
rotate(sin(frameCount+i)*smoothSizeOfCircle);
var r = map(sin(frameCount), -4,1,-50,255);
var g = map(sin(frameCount/2), -4,1,-50,255);
var b = map(sin(frameCount/4), -4,1,-50,255);
stroke(r,g,b);
rect(0,0,600 - i*3,600 - i*3, 200-i);
pop();
}
}