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="wrapper">
    <div class="container">
        <div class="content">
            <div>
                <div>canvas</div>
                <div>path</div>
                <canvas width="100" height="100"></canvas>
            </div>
            <div>
                <div>svg</div>
                <div>path</div>
                <svg width="100" height="100" viewBox="0 0 100 100">
                    <g transform="translate(0,0)">
                        <path d="M0,0C0,0 0,0 0,0" fill="red" stroke="orange" stroke-width="1">
                    </g>
                </svg>
            </div>
        </div>
        <div class="content">
            <div>
                <div>toDataURL</div>
                <div class="img_box"></div>
            </div>
            <div>
                <div>Blob</div>
                <div class="img_box"></div>
            </div>
        </div>
    </div>
    <div class="menu"></div>
</div>
            
          
!
            
              
*{
    padding:0;
    margin:0;
    box-sizing:border-box;
    outline:none;
    user-select:none;
    -moz-user-select:none;
    -webkit-user-select:none;
    -ms-user-select:none;
    font-size:14px;
    font-family:Consolas;
}
div.wrapper{
    width:230px;
    height: auto;
    background-color:black;
    padding: 10px 0px 10px;
    margin:20px 20px 0px;
}
div.wrapper > div.container{
    width:100%;
    height:100%;
}
div.wrapper > div.container > div.content{
    display:flex;
    flex-wrap:wrap;
    margin:0px 0px 10px;
}
div.wrapper > div.container > div.content:last-child{
    margin:0;
}
div.wrapper > div.container > div.content > div{
    margin:0px 0px 0px 10px;
    width:100px;
    height:auto;
    color:white;
    text-align:center;
    font-size:11px;
}
div.wrapper > div.container > div.content > div > canvas{
    background-color:#111;
    display:block;
}
div.wrapper > div.container > div.content > div > svg{
    background-color:#111;
    display:block;
}
div.wrapper > div.container > div.content:nth-of-type(1) > div > div:nth-of-type(1),
div.wrapper > div.container > div.content:nth-of-type(1) > div > div:nth-of-type(2){
    font-size:12px;
    padding:2px 0px;
}
div.wrapper > div.container > div.content:nth-of-type(1) > div > div:nth-of-type(1),
div.wrapper > div.container > div.content:nth-of-type(2) > div > div:nth-of-type(1){
    font-size:12px;
    padding:2px 0px;
    background-color:purple;
}
div.wrapper > div.container > div.content:nth-of-type(2) > div > div.img_box{
    width:100px;
    height:100px;
    background-color:#111;
}

            
          
!
            
              
(function(win,doc){
win.addEventListener("load",function(){
var d = [
    {'type':'path','z':true,'mode':'both','x':22.091037,'y':-21.759347},
    {'x':20.440914,  'y':-16.761598}, {'x':17.975372,  'y':-13.340517}, {'x':15.212225,   'y':-10.047177},
    {'x':10.81841,   'y':-4.8102792}, {'x':4.3559515,  'y':1.486586},   {'x':-0.14230935, 'y':-0.03216803},
    {'x':-4.3798038, 'y':-1.462879},  {'x':-6.3342194, 'y':-8.6728403}, {'x':-6.9674177,  'y':-14.95658},
    {'x':-7.4290893, 'y':-19.538114}, {'x':-7.6300469, 'y':-25.893663}, {'x':-5.836871,   'y':-31.355172},
    {'x':-2.5025797, 'y':-41.510487}, {'x':2.8767458,  'y':-45.929578}, {'x':8.9484916,   'y':-47.450943},
    {'x':11.5074,    'y':-48.092114}, {'x':11.767982,  'y':-47.491164}, {'x':8.9771916,   'y':-41.378058},
    {'x':7.4683759,  'y':-38.073062}, {'x':6.255309,   'y':-34.075968}, {'x':6.021074,    'y':-29.355249},
    {'x':8.5521223,  'y':-36.796474}, {'x':8.7678996,  'y':-37.616176}, {'x':10.100286,   'y':-40.479928},
    {'x':13.427037,  'y':-47.630254}, {'x':16.968667,  'y':-49.784182}, {'x':19.912857,   'y':-45.89559},
    {'x':23.365277,  'y':-40.701015}, {'x':25.258142,  'y':-31.459089}, {'x':22.136239,   'y':-21.897019}
];
var wrapper = document.querySelector('div.wrapper');
var container = wrapper.querySelector('div.container');
var contents = container.querySelectorAll('div.content');
var can      = contents[0].querySelector('canvas');
var svg      = contents[0].querySelector('svg');
var img_box      = contents[1].querySelectorAll('div.content > div > div.img_box');
var ctx      = can.getContext('2d');
var g        = svg.querySelector('svg > g');
var path      = g.querySelector('g > path');
    path.setAttribute('d',stringify(d));
var p_box      = path.getBBox();
var fill       = 'red';
var stroke     = 'orange';
var lineWidth  = 1.25;
var linecap    = 'butt';
var linejoin   = 'miter';
//var miterlimit = 8;
    ctx.fillStyle   = fill;
    ctx.strokeStyle = stroke;
    ctx.lineWidth   = lineWidth;
    ctx.lineCap     = linecap;
    ctx.lineJoin    = linejoin;
    //ctx.miterLimit  = miterlimit;
    
    path.setAttribute('fill',fill);
    path.setAttribute('stroke',stroke);
    path.setAttribute('stroke-width',lineWidth);
    path.setAttribute('stroke-linecap',linecap);
    path.setAttribute('stroke-linejoin',linejoin);
    //path.setAttribute('stroke-miterlimit',miterlimit);
    

var g_mx     = g.transform.baseVal.getItem(0).matrix;
    g_mx.e   = (100-p_box.width )/2 + p_box.width/2-8;
    g_mx.f   = (100-p_box.height)/2 + p_box.height;
    drawPoints(ctx,d,g_mx.e,g_mx.f);
var img = new Image();
    img.src = can.toDataURL();
    img_box[0].appendChild(img);
    
    
var data = "<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100'>";
    data = data + "<foreignObject width='100%' height='100%'>";
    data = data + svg.outerHTML;
    data = data + "</foreignObject>";
    data = data + "</svg>";
var DOMURL = self.URL || self.webkitURL || self;
    img = new Image();
    svg = new Blob([data], {type: "image/svg+xml;charset=utf-8"});
var url = DOMURL.createObjectURL(svg);
    img.src = url;
    img.onload = function() {
        img_box[1].appendChild(this);
    };
    
}, false);//onload
    
/* ############################################################### */

function stringify(p){
var d = 'M' + p[0].x + ',' + p[0].y;
    for(var i = 1; i < p.length; i = i + 3){
        d = d + 'C' + p[i].x + ',' + p[i].y + ' ' + p[i+1].x + ',' + p[i+1].y + ' ' + p[i+2].x + ',' + p[i+2].y;
    }
    return d;
}
function drawPoints(ctx,d,left,top){
    ctx.beginPath();
    ctx.moveTo(
        d[0].x + left,
        d[0].y + top 
    );
    for(var i = 1; i < d.length; i = i + 3){
        ctx.bezierCurveTo(
            d[i].x   + left,
            d[i].y   + top ,
            d[i+1].x + left,
            d[i+1].y + top ,
            d[i+2].x + left,
            d[i+2].y + top 
        );
    }
    ctx.fill();
    ctx.stroke();
}

})(window,document);
            
          
!
999px
Loading ..................

Console