xxxxxxxxxx
68
var amplitude;
var soundUp, soundDown, soundLeft, soundRight;
function preload() {
soundRight = loadSound("./sounds/forest.m4a");
}
function setup() {
createCanvas(600, 600)
angleMode(DEGREES)
amplitude = new p5.Amplitude()
}
function draw() {
background(0)
noFill()
translate(300, 280)
drawRight()
playRight()
}
function drawRight() {
stroke("white");
for (var count = 0; count < 1; count += 1) {
var radius = 100 + (5 * count)
drawNoisyCircle(0, 0, radius)
}
}
function playRight() {
if (!soundRight.isPlaying()) {
pauseAllSounds()
soundRight.loop()
}
}
function drawNoisyCircle(x, y, radius) {
push()
translate(x, y)
beginShape()
for (var i = 0; i < 2200; i += 2) {
var noiseOffset = map(noise(i * 5.03), 0, 1, -10, 5)
var soundLevel = amplitude.getLevel()
var soundOffset = map(soundLevel, 0, 13, -50, 50)
var timeOffset = map(cos(frameCount * i / 2000), -1, 1, -80, 50)
var px = (radius + noiseOffset + timeOffset) * sin(i + 5 * soundOffset + timeOffset)
var py = (radius + noiseOffset + timeOffset) * cos(i + soundOffset + timeOffset)
vertex(px, py)
}
endShape()
pop()
}
function pauseAllSounds() {
soundRight.pause()
}