xxxxxxxxxx
95
let mug;
let yawn;
let discord;
let door;
let record;
let beat = 200;
let notes = [1, 1.125, 1.25, 1.334, 1.5, 1.667, 1.875, 2];
let x = 0;
let len = 1800;
function preload() {
mug = loadSound('mug.mp3');
yawn = loadSound('yawning.mp3');
discord = loadSound('discord.mp3');
door = loadSound('door.mp3');
record = loadSound('record.mp3');
}
function setup() {
createCanvas(400, 400);
}
function draw() {
if (x > width) {
x = 0;
background(255);
}
if (frameCount > 0 && frameCount < len) {
for (let r = 1; r < 92; r += 30) {
if (frameCount % beat == r) {
mug.play();
mug.amp(0.2);
rect(x, 50, 10, 10);
x += 10;
}
}
}
if (frameCount > 0 && frameCount < len) {
for (let r = 121; r < 181; r += 6) {
if (frameCount % beat == r) {
mug.play();
rect(x, 100, 10, 10);
x += 10;
}
}
}
if (frameCount > len / 6 && frameCount < len) {
for (let y = 100; y < 150; y++) {
if (frameCount % 500 == y) {
//let f = random(notes);
let f = 0;
// Make it random 10% of the time
if (random(1) < 0.1) f = random(notes);
else {
// Use noise to pick an index from the array of notes
let noisyNote = floor(noise(frameCount * 0.1) * notes.length);
f = notes[noisyNote];
}
yawn.rate(f);
yawn.play();
yawn.amp(0.5);
}
}
}
if (frameCount > len / 5 && frameCount < len) {
for (let a = 186; a < 361; a += 180) {
if (frameCount % beat == a) {
discord.play();
rect(x, 150, 10, 10);
x += 10;
}
}
}
if (frameCount > len / 3 && frameCount < 2 * len / 3) {
if (frameCount % 30 == 0) {
door.play();
door.amp(0.2);
rect(x, 200, 10, 10);
x += 10;
}
}
if (frameCount > len / 3 && frameCount < len) {
if (frameCount % 90 == 0) {
record.play();
record.rate(random(0.3, 3));
}
}
}