xxxxxxxxxx
188
let currentflush
let song;
let mic;
let smoothSizeOfCircle = 0;
let myFont;
function preload(){
currentflush = mainpage;
song = loadSound('assets/salamisound-3780183-toilets-pressure-flushing.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;
;(song.stop());
} else if (key == '2') {
currentflush = flush1;
;(song.play());
} else if (key == '3') {
currentflush = flush2;
;(song.play());
} else if (key =='4') {
currentflush = flush3
;(song.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 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(0);
noFill();
translate(width/2,height/2)
for (var i = 0; i<800; i++){
let intensity = mic.getLevel();
let sizeOfCircle = map(intensity, 0, 2, 20, 2000);
smoothSizeOfCircle += (sizeOfCircle - smoothSizeOfCircle) *2;
push();
rotate(sin(frameCount+i)*1000*smoothSizeOfCircle);
var r = map(sin(frameCount), smoothSizeOfCircle,1,-50,smoothSizeOfCircle);
var g = map(sin(frameCount/2), smoothSizeOfCircle,1,-50,smoothSizeOfCircle);
var b = map(sin(frameCount/4), smoothSizeOfCircle,1,-50,smoothSizeOfCircle);
stroke(r,g,b);
rect(0,0,600 - i*6,600 - i*6, 200-i);
pop();
}
}
function flush2(){
let intensity = mic.getLevel();
background(0);
noFill();
translate(width/2,height/2)
for (var i = 0; i<200; i++){
let intensity = mic.getLevel();
let sizeOfCircle = map(intensity, 0, 1, 10, 2000);
smoothSizeOfCircle += (sizeOfCircle - smoothSizeOfCircle) * 0.2;
push();
rotate(sin(frameCount+i)*1000*smoothSizeOfCircle);
var r = map(sin(frameCount), 100,1,-50,smoothSizeOfCircle);
var g = map(sin(frameCount/2), 100,1,-50,smoothSizeOfCircle);
var b = map(sin(frameCount/4), 100,200,-50,smoothSizeOfCircle);
stroke(r,g,b);
rect(0,0,600 - i*10,600 - i*10, 200-i);
pop();
}
}
function flush3(){
background(0);
noFill(255);
translate(width/2,height/2)
for (var i = 0; i<200; i++){
let intensity = mic.getLevel();
let sizeOfCircle = map(intensity, 0, 1, 10, 9000);
smoothSizeOfCircle += (sizeOfCircle - smoothSizeOfCircle) * 0.2;
push();
rotate(sin(frameCount+i)*900);
var r = map(sin(frameCount), smoothSizeOfCircle,1,-50,255);
var g = map(sin(frameCount/2), smoothSizeOfCircle,1,-50,255);
var b = map(sin(frameCount/4), smoothSizeOfCircle,1,-50,255);
stroke(r,g,b);
rect(0,0,600 - i*6,600 - i*smoothSizeOfCircle, 200-i);
pop();
}
}