cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              * {
  margin:0;
  padding:0;
}
body {
  position:relative;
}
body {
  margin:0;
  padding:0;
}
canvas {
  margin:0;
  padding:0;
  background:red;
  height:800px;
}
            
          
!
            
              canvas = document.getElementById("canvas");
ctx = canvas.getContext('2d');
canv = $("#canvas");
canv.unbind();
getTime = () => (Date.now()-starttime);
canv.attr('width',$('body').width());
ctx.setTransform(1, 0, 0, 1, 0, 0);
ctx.translate(canvas.width/2, canvas.height/2);

triangles = [];

mouse = {x:0, y:0};
$("#canvas").mousemove(function(event) {
	mouse.x = event.pageX-$(this).offset().left;
    mouse.y = event.pageY-$(this).offset().top;
});
drs = [
(scale) => ((time, click) => {
    if(click) return scale*(0.01);
    else return scale*(0.02+0.01*Math.sin(0.1*time));
}),
(scale) => ((time, click) => {
    if(click) return 0.01;
    else {
        if(time % 400 > 200) {
            return scale*(0.01*Math.sqrt(0.1*(time% 400)));
        } else {
            return scale*(-0.01*Math.sqrt(0.1*(time% 400)));
        }
    }
}),
(scale) => ((time, click) => {
    if(click) return 0.01;
    else {
        if(time % 240 < 60) {
            return scale*(0.000666667*(time % 240));
        } else if(time % 240 < 180) {
            return scale*(0.04);
        } else {
            return scale*(0.04-0.000666667*(time % 240 - 180));
        }
    }
}),
];

das = [
(scale, scale2) => ((time, click) => {
    if(click) return 2*scale2;
    else return scale*(1*Math.sin(0.05*time));
}),
(scale, scale2) => ((time, click) => {
    if(click) return scale2*2;
    else {
        if(time % 400 < 200) {
            return scale*(0.1*Math.sqrt(0.1*(time% 400)));
        } else {
            return scale*(-0.1*Math.sqrt(0.1*(time% 400 - 200)));
        }
    }
}),
(scale, scale2) => ((time, click) => {
    if(click) return scale2*2;
    else {
        if(time % 240 < 60) {
            return scale*10*(-0.04+(0.000666667*(time % 240)));
        } else if(time % 240 < 180) {
            return 0;
        } else {
            return scale*10*(0.000666667*(time % 240 - 180));
        }
    }
}),
];

dss = [
(scale, scale2) => ((time, click) => {
    if(click) return 1*scale2;
    else return scale*(1.5*Math.sin(0.05*time));
}),
(scale, scale2) => ((time, click) => {
    if(click) return 0.1*scale2;
    else return scale*(1.5*Math.sin(0.05*time));
}),
(scale, scale2) => ((time, click) => {
    if(click) return scale2*1;
    else {
        if(time % 400 < 200) {
            return scale*(0.1*Math.sqrt(0.1*(time% 400)));
        } else {
            return scale*(-0.1*Math.sqrt(0.1*(time% 400 - 200)));
        }
    }
}),
(scale, scale2) => ((time, click) => {
    if(click) return scale2*1;
    else {
        if(time % 240 < 60) {
            return scale*(0.000666667*(time % 240));
        } else if(time % 240 < 180) {
            return scale*(0.04);
        } else {
            return scale*(0.04-0.000666667*(time % 240 - 180));
        }
    }
}),
]

randomSign = () => (Math.random()>0.5) ? 1 : -1;
$("#canvas").mousedown(function() {
    var petals = Math.floor(Math.random()*10)+3;

    let side = 30+Math.random()*60;
    let color = hslStr(Math.random()*360, 80, 50, 0.7);
    let drf = drs[Math.floor(Math.random()*drs.length)](1*(0.5+Math.random())*randomSign());
    let daf = das[Math.floor(Math.random()*das.length)](1*(0.5+Math.random())*randomSign(), 0.5+Math.random());
    let dsf = dss[Math.floor(Math.random()*dss.length)](1*(0.5+Math.random())*randomSign(), 0.5+Math.random());
    if(Math.random()<0.1) {side = 2; dsf = (time, click) => 0; petals = 20+Math.floor(Math.random()*20)}

    for(let i=0; i<petals; i++) {
        let newtri = new Triangle(mouse.x, mouse.y, 0, side, color, (i/petals)*2*Math.PI);
        newtri.dr= drf;
        newtri.da= daf;
        newtri.ds= dsf;
        newtri.maxLife = 600;
        triangles.push(newtri);
    }
});

function reDraw() {
    canvasDraw();
    window.requestAnimationFrame(reDraw);        
}
window.requestAnimationFrame(reDraw);

$("#canvas").mouseup(function() {
    for(var i=0; i<triangles.length; i++) {
        triangles[i].clicking = false;
    }
});

Triangle = function(x, y, altitude, sidelength, color, rotation) {
    this.x = x; this.y = y;
    this.altitude = altitude; this.sidelength = sidelength; 
    this.color = color; this.rotation = rotation;
    this.lifetime=0; this.clicking = true;
    //each differential is a funciton of lifetime and clicking
    this.da = (a, b) => 0;
    this.ds = (a, b) => 0;
    this.dr = (a, b) => 0;
    this.dead = false;

    this.kill = function() {
        this.dead = true;
        this.da = (a, b) => (-1);
        this.ds = (a, b) => (-1);
    }
}

hslStr = function(h, s, l, a) {
    return "hsla("+h+","+s+"%,"+l+"%,"+a+")";
}

drawTri = function(tri) {
    ctx.fillStyle = tri.color;

    ctx.save();
    ctx.translate(tri.x, tri.y);
    ctx.rotate(tri.rotation);
    ctx.beginPath();
    ctx.moveTo(0, 0);
    ctx.lineTo(tri.sidelength/2, tri.altitude);
    ctx.lineTo(-tri.sidelength/2, tri.altitude);
    ctx.lineTo(0, 0);
    ctx.fill();
    // ctx.strokeStyle="white";
    // ctx.stroke();
    ctx.restore();
}

canvasDraw = function() {

    canv.attr('width',$('#canvas').width());
    canv.attr('height',$('#canvas').height());

    ctx.fillStyle = "#112233";
    ctx.fillRect(0, 0, canvas.width, canvas.height);


    for(let i=0; i<triangles.length; i++) {
        const tri = triangles[i];
        drawTri(tri);

        tri.altitude+=tri.da(tri.lifetime, tri.clicking);
        tri.sidelength+=tri.ds(tri.lifetime, tri.clicking);
        tri.rotation+=tri.dr(tri.lifetime, tri.clicking);

        tri.lifetime++;

        if(tri.lifetime==tri.maxLife) {
            triangles[i].kill();
        }
        if(tri.dead && tri.altitude<5 ) {
            triangles.splice(i, 1);
        }
    }

  

}


//init stuff

    function makeDyingBloom(x, y) {
        let side = 30+Math.random()*60;
        let drf = drs[0](1);
        let daf = (side, click) => (-2);
        let dsf = (side, click) => (-2);

        let color = hslStr(Math.random()*360, 80, 50, 0.7);
        for(let i=0; i<10; i++) {
            let newtri = new Triangle(x, y, 150, 150, color, (i/10)*2*Math.PI);
            newtri.dr= drf;
            newtri.da= daf;
            newtri.ds= dsf;
            newtri.maxLife = 30;
            triangles.push(newtri);
        }
    }
    for(var i=0; i<10; i++) {
        makeDyingBloom(Math.random()*canvas.width,Math.random()*canvas.height);    
    }
    
            
          
!
999px
Loading ..................

Console