Snow Maker(W8)

First time I tried to make a ball when mouse clicked and the ball is bouncing with sound. However, I changed it because I wanted using sound as an input to make it more intuitive.

So I designed this Snow Maker that using breath as an input(actually its sound, but I want to make a feeling like that).

When the user pressed mouse, the mic sensing the level of the breath(sound) and it makes a snow. And also turn on background music. Released mouse, the music is paused and also snow.

 

Link to the editor:
https://editor.p5js.org/Jaekook/sketches/r1qlNs8nX

Link to the fullscreen:
https://editor.p5js.org/Jaekook/full/r1qlNs8nX

References:
https://musiclab.chromeexperiments.com/
https://editor.p5js.org/nick7z/sketches/ryh3Ab157

– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
Code

let mic;
let vol;
let bgm;

let snow = [];

function preload() {
bgm = loadSound(“Let it go.mp3”);
}

function setup() {
createCanvas(windowWidth, windowHeight);

mic = new p5.AudioIn();
mic.start();

for (let i = 0; i < snow.length; i++) {
snow[i] = new Snow();
}
}
//Turn BGM on
function mousePressed() {
bgm.playMode(‘sustain’);
bgm.play();
bgm.setVolume(0.5);
}

//Turn BGM off
function mouseReleased() {
bgm.pause();
}

function draw() {
background(0);
for (let i = 0; i < snow.length; i++) {
snow[i].move();
snow[i].drawBall();
}

if (mouseIsPressed) {
vol = mic.getLevel();
vol = vol * 100;
if (vol > 1) {
let b = new Snow();
snow.push(b);
}
console.log(vol);
}
}

class Snow {
constructor() {
this.x = mouseX;
this.y = mouseY;
this.r = random(1, 20);
this.speed = random(0.2, 0.8);
this.colG = random(150, 255);
this.colB = random(200, 255);
this.colT = random(90, 255);
}

move() {
if (this.y < height) {
this.y = this.y + this.speed;
} else {
this.y = height;
}
}
drawBall() {
noStroke();
fill(0, this.colG, this.colB, this.colT);
ellipse(this.x, this.y, this.r, this.r);
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *