xxxxxxxxxx
132
const size = 1;
const moveScale = 800;
const space = 40;
let colors;
let currentColors;
let currentWave;
let mic;
let song;
let smoothSizeOfCircle = 0;
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
strokeWeight(20);
strokeCap(ROUND);
background("#1a0633");
currentWave = bw;
mic = new p5.AudioIn();
mic.start();
song = loadSound('assets/tame_impala_a.mp3');
//createCanvas(windowWidth, windowHeight);
// mic = new p5.AudioIn();
// mic.start();
}
function keyPressed() {
if (key == '1') {
currentWave = bw;
} else if (key == '2') {
currentWave = waves;
} else if (key== '3') {
currentWave = wreck
}
}
function draw() {
translate(-width/2, -height/2);
currentWave();
}
function lerpColors(t, colors) {
let i = Math.floor(t * (colors.length - 1));
if (i < 0) return colors[0];
if (i >= colors.length - 1) return colors[colors.length - 1];
let percent = (t - i / (colors.length - 1)) * (colors.length - 1);
return color(
colors[i]._getRed() + percent * (colors[i + 1]._getRed() - colors[i]._getRed()),
colors[i]._getGreen() + percent * (colors[i + 1]._getGreen() - colors[i]._getGreen()),
colors[i]._getBlue() + percent * (colors[i + 1]._getBlue() - colors[i]._getBlue())
)
}
// function mousePressed() {
// if (mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 100) {
// let fs = fullscreen();
// fullscreen(!fs);
// }
// }
function mousePressed() {
if (song.isPlaying()) {
// .isPlaying() returns a boolean
song.stop();
} else {
song.play();
}
}
function bw() {
colors = [color("#000000"), color("#FFFFFF")];
let time = millis() / 2000
let ini = (time * 100) % space
for (let x = ini; x < width; x += space) {
for (let y = ini; y < height; y += space) {
let angle = noise((x - mouseX) / moveScale, (y - mouseY) / moveScale, time / 10) * TWO_PI * 10;
let xx = sin(angle) * size;
let yy = sin(angle) * size;
stroke(lerpColors(angle % TWO_PI / TWO_PI, colors));
// rect(x-xx, y-yy, x+xx, y+yy);
ellipseMode(CENTER);
ellipse(x,y,15,15);
}
}
}
function waves() {
colors = [color("#5465FF"), color("#788BFF"), color("#9BB1FF"), color("#BFD7FF"), color("#E2FDFF"), color("#FFC30F")];
let time = millis() / 1000
let ini = (time * 100) % space
for (let x = ini; x < width; x += space) {
for (let y = ini; y < height; y += space) {
let angle = noise((x - mouseX) / moveScale, (y - mouseY) / moveScale, time / 10) * TWO_PI * 10;
let xx = cos(angle) * size;
let yy = cos(angle) * size;
fill(lerpColors(angle % TWO_PI / TWO_PI, colors));
// rect(x-xx, y-yy, x+xx, y+yy);
rect(x+xx,y,30+xx,40-yy);
// rect(x,y,40,30);
}
}
}
function wreck() {
colors = [color("#FF5E35"), color("#D1F200"), color("#0095C7"), color("#0B8040"), color("#D918A5"), color("#EA559A")];
let intensity = mic.getLevel();
let sizeOfCircle = map(intensity, 0, 1, 10, 2000);
smoothSizeOfCircle += (sizeOfCircle - smoothSizeOfCircle) * 0.2;
push()
let time = millis() / 2000
let ini = (time * 500) % space
for (let x = ini; x < width; x += space) {
for (let y = ini; y < height; y += space) {
let angle = noise((x - mouseX) / moveScale, (y - mouseY) / moveScale, time / 5) * TWO_PI * 10;
let xx = cos(angle) * smoothSizeOfCircle;
let yy = sin(angle) * smoothSizeOfCircle;
stroke(lerpColors(angle % TWO_PI / TWO_PI, colors));
line(x - xx, y - yy, x + xx, y + yy);
}
}
}
function waveBlue() {
colors = [color("#5465FF"), color("#788BFF"), color("#9BB1FF"), color("#BFD7FF"), color("#E2FDFF"), color("#FFC30F")]
}