xxxxxxxxxx
76
let ang = 0;
let dark = true;
let circlePosDivider = 3;
let d = 10;
let up = true;
let osc, playing;
let redValue = 0.95;
let midiNotes = [50, 52, 53, 55, 57, 59, 60, 62, 64, 65, 67];
// let midiNotes = [50,52,53,55,57,59,60,62];
let env;
let backCol = 0;
function setup() {
let cnv = createCanvas(windowWidth, windowHeight);
angleMode(DEGREES);
background(66, 50);
osc = new p5.TriOsc();
env = new p5.Envelope();
}
function draw() {
background(backCol, d);
for (let i = 0; i < 100; i += 1) {
push();
translate(width / 2, height / 2);
rotate(ang);
ang += 0.01;
let redIt = random();
if (round(ang, 2) % 5 === 0) {
// lines
strokeWeight(1);
if (round(ang, 2) % 360 === 0) {
dark = dark ? false : true;
if (circlePosDivider < 9) {
circlePosDivider += 0.2;
} else {
circlePosDivider = 3;
}
}
dark ? stroke(255, 100) : stroke(150);
redIt > redValue ? stroke(250, 0, 0, 100) : null;
let x = width / random(2.95, 6);
line(x, 0, 0, 20);
line(x, 0, 100, 20);
// circles
fill(255);
redIt > redValue ? fill(250, 0, 0) : null;
noStroke();
circle(width / circlePosDivider, 0, 5);
// sound
if (redIt > redValue) {
osc.start();
for (let i = 0; i < 500; i += 0.5) {
noStroke();
fill(250, 0, 0, 2+i/20);
circle(width / circlePosDivider+i*2, random(-5,5), 5+i/5);
}
midiVal = random(midiNotes);
freq = midiToFreq(midiVal);
osc.freq(freq);
env.ramp(osc, 0, random(10, 50), 0);
backCol += random(-5, 5);
}
}
pop();
}
d += dark ? -0.05 : +0.05;
}