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.

            
              
<div class="container">
    <div class="menu">
        <div><span>0 ms</span><span><input type="button" value="path"></span></div>
        <div><span>0 ms</span><span><input type="button" value="image"></span></div>
    </div>
    <div class="content">
        <div><canvas width="100" height="100"></canvas></div>
        <div><canvas width="100" height="100"></canvas></div>
    </div>
</div>
            
          
!
            
              
div.container {
    width:230px;
    height:auto;
}
div.container > div.menu{
    display:flex;
    padding:0px 10px;
}
div.container > div.menu > div{
    width:100%;
    text-align:right;
}
div.container > div.menu > div:nth-of-type(1){
    padding:0px 10px 0px 0px;
}
div.container > div.menu > div > span:nth-of-type(1){
    font-size:12px;
    font-family:Consolas;
    display:inline-block;
    width:40px;
    padding:0px 5px 0px 0px;
}
div.container > div.menu > div > span > input[type="button"]{
    font-size:12px;
    font-family:Consolas;
    width:50px;
}
div.container > div.content{ 
    display:flex;
    background-color:#111;
    padding:10px 0px 10px 10px;
}
div.container > div.content > div{
    margin:0px 10px 0px 0px;
}
div.container > div.content > div > canvas{
    display:block;
    background-color:black;
}
            
          
!
            
              

(function(win,doc){


win.addEventListener('load', function(evt){
var d = [
    [{'type':'path','z':true,'mode':'both','x':22.09,'y':-21.76},{'x':20.44,'y':-16.76},{'x':17.98,'y':-13.34},{'x':15.21,'y':-10.05},{'x':10.82,'y':-4.81},{'x':4.36,'y':1.49},{'x':-0.14,'y':-0.03},{'x':-4.38,'y':-1.46},{'x':-6.33,'y':-8.67},{'x':-6.97,'y':-14.96},{'x':-7.43,'y':-19.54},{'x':-7.63,'y':-25.89},{'x':-5.84,'y':-31.36},{'x':-2.5,'y':-41.51},{'x':2.88,'y':-45.93},{'x':8.95,'y':-47.45},{'x':11.51,'y':-48.09},{'x':11.77,'y':-47.49},{'x':8.98,'y':-41.38},{'x':7.47,'y':-38.07},{'x':6.26,'y':-34.08},{'x':6.02,'y':-29.36},{'x':8.55,'y':-36.8},{'x':8.77,'y':-37.62},{'x':10.1,'y':-40.48},{'x':13.43,'y':-47.63},{'x':16.97,'y':-49.78},{'x':19.91,'y':-45.9},{'x':23.37,'y':-40.7},{'x':25.26,'y':-31.46},{'x':22.14,'y':-21.9}]
];

var img = new Image();
var width = 31;
var height = 47;
var container = document.querySelector('div.container');
var menu      = container.querySelector('div.menu');
var spn = menu.querySelectorAll('div > span:nth-of-type(1)');
var content = container.querySelector('div.content');
var btn = menu.querySelectorAll('input[type="button"]');
var canvas = content.querySelectorAll('canvas');
var can = canvas[0];
var dan = canvas[1];
var ctx = can.getContext('2d');
var dtx = dan.getContext('2d');
    ctx.fillStyle   = 'blueviolet';
    ctx.strokeStyle = 'white';
    ctx.lineWidth = 2;
    
function aa(n){
var tx = (dan.width  - width)/2 + (width/2 - 4);
var ty = (dan.height - height)  + height/2 - 2;
    for(var m = 0; m < n; m++){
        ctx.clearRect(0,0,can.width,can.height);
        for(i = 0; i < d.length; i = i + 1){
            ctx.beginPath();
            ctx.moveTo(
                d[i][0].x + tx,
                d[i][0].y + ty
            );
            for(j = 1; j < d[i].length; j = j + 3){
                ctx.bezierCurveTo(
                    d[i][j].x   + tx,
                    d[i][j].y   + ty,
                    d[i][j+1].x + tx,
                    d[i][j+1].y + ty,
                    d[i][j+2].x + tx,
                    d[i][j+2].y + ty
                );
            }
            switch(d[i][0].z){
            case true  :
                ctx.closePath();
            break;
            case false :
            break;
            }
            switch(d[i][0].mode){
            case 'fill'  :
                ctx.fill();
            break;
            case 'stroke' :
                ctx.stroke();
            break;
            case 'both' :
                ctx.fill();
                ctx.stroke();
            break;
            }
        }
   }
}
    
function bb(n){
    for(var i = 0; i < n; i++){
        dtx.clearRect(0,0,dan.width,dan.height);
        dtx.drawImage(img, 0, 0);
   }
}
    
    btn[0].addEventListener('click',function(evt){
    var s = new Date().getTime();
        aa(10000);
    var e = (new Date().getTime()) - s;
        spn[0].textContent = e+' ms';
        console.log('path:',(new Date().getTime()) - s);
    },false);
    
    btn[1].addEventListener('click',function(evt){
    var s = new Date().getTime();
        bb(10000);
    var e = (new Date().getTime()) - s;
        spn[1].textContent = e+' ms';
        console.log('image:',(new Date().getTime()) - s);
    },false);
    
    aa(1);
    img.src = can.toDataURL();
    ctx.clearRect(0,0,can.width,can.height);
    
},false);//onload

})(window,document);


            
          
!
999px
Loading ..................

Console