soundFormats('mp3', 'ogg');
song = loadSound('ambient.mp3');
createCanvas(windowWidth, windowHeight);
block = new Bk(createVector(-2,-2), createVector(windowWidth+2, -2), createVector(windowWidth+2,windowHeight+2), createVector(-2, windowHeight+2), 0);
function mousePressed() {
for (var i = 0; i < 1000; i++) {
var p = ((millis() - start) / duration);
block = new Bk(createVector(-2,-2), createVector(windowWidth+2, -2), createVector(windowWidth,windowHeight), createVector(-2, windowHeight), 0);
background(255 - abs(mouseX-windowWidth/2)/2 - abs(mouseY-windowHeight/2)/2);
speed = map(travelSpeed - abs(mouseX-windowWidth/2)/2 - abs(mouseY-windowHeight/2)/2, 0, width, 0, 150);
translate(mouseX, mouseY);
for (var i = 0; i < pieces.length; i++) {
stroke(random(3, 20), random(142, 229), random(23, 49), 20);
line(0, 0, random(-width, width), random(-height, height));
stroke(random(251, 229), random(167, 108), random(4, 0), 15);
line(0, 0, random(-width, width), random(-height, height));
stroke(random(0, 37), random(253, 10), random(244, 237), 30);
line(0, 0, random(-width, width), random(-height, height));
line(0, 0, random(-width, width), random(-height, height));
line(0, 0, random(-width, width), random(-height, height));
function Bk(posA, posB, posC, posD, depth){
this.av = random(-0.1, 0.1);
this.gravity = random(2.5, 3);
var avgX = (posA.x + posB.x + posC.x + posD.x)/4;
var avgY = (posA.y + posB.y + posC.y + posD.y)/4;
this.centerPos = createVector(avgX, avgY);
var r = random(0.3, 0.9);
var startX = ((posD.x - posA.x) * r) + posA.x;
var startY = ((posD.y - posA.y) * r) + posA.y;
this.lineStart = createVector(startX, startY);
var endX = ((posC.x - posB.x) * r) + posB.x;
var endY = ((posC.y - posB.y) * r) + posB.y;
this.lineEndTarget = createVector(endX, endY);
this.lineEnd = this.lineStart.copy();
if(this.depth < maxDepth){
this.drawingDuration = random(500,2000);
this.drawingStart = millis();
if(this.children.length == 0){
translate(this.x, this.y);
translate(this.centerPos.x, this.centerPos.y);
translate(0-this.centerPos.x, 0-this.centerPos.y);
vertex(this.posA.x, this.posA.y);
vertex(this.posB.x, this.posB.y);
vertex(this.posC.x, this.posC.y);
vertex(this.posD.x, this.posD.y);
line(this.lineStart.x, this.lineStart.y, this.lineEnd.x, this.lineEnd.y);
for (var i = 0; i < this.children.length; i++) {
if (!this.children[i].dead) {
for (var i = 0; i < this.children.length; i++) {
handleDrawing:function(){
var p = (millis() - this.drawingStart) / this.drawingDuration;
this.lineEnd = this.lineEndTarget.copy();
var blockA = new Bk(this.posB, this.lineEnd, this.lineStart, this.posA, this.depth+1);
var blockB = new Bk(this.lineEnd, this.posC, this.posD, this.lineStart, this.depth+1);
this.children.push(blockA);
this.children.push(blockB);
this.lineEnd.x = ((this.lineEndTarget.x - this.lineStart.x) * this.sinProgress(p)) + this.lineStart.x;
this.lineEnd.y = ((this.lineEndTarget.y - this.lineStart.y) * this.sinProgress(p)) + this.lineStart.y;
return -0.5 * (cos(PI*p) - 1);
this.x = random(-width, width);
this.y = random(-height, height);
this.update = function() {
this.x = random(-width, width);
this.y = random(-height, height);
this.display = function() {
var sx = map(this.x/this.z, 0, 1, 0, width);
var sy = map(this.y/this.z, 0, 1, 0, height);
var px = map(this.x/this.pz, 0, 1, 0, width);
var py = map(this.y/this.pz, 0, 1, 0, height);
stroke(random(0,100), random(50,200), random(100,250));