cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

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.

            
              <canvas id="c" height="600" width="600"></canvas>
<svg version="1.1" id="brush" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
	 width="441.182px" height="122.827px" viewBox="0 0 441.182 122.827" enable-background="new 0 0 441.182 122.827"
	 xml:space="preserve">
<path d="M363,3.827c-6.3,2-12.7,4-19,6c-2.2-4.8,3.6-7.1,6-9C354.8,2.027,362.1-3.374,363,3.827z"/>
<path d="M196,24.827c1.8,7.9-2.3,13.2-8,18c-7.3,0.8-13.9,3.2-20-2c0.7-7.8-12.2-18.3,1-23l1-3
	C179.8,15.327,190.3,16.626,196,24.827z"/>
<path d="M216,50.827c0.3,1.3-0.8,3.3,1,4c1.2-2.7,10.3-6.3,5-10c-0.9-2.8,1.3-4.9,4-4c5.4-0.6,8.6,4.4,14,4l3,3
	c16.1,4.4,33.6,5.3,50,9c4.3,0,9.3-4.5,13,0l1-1c3.2,6.7,11.1,6.2,18,6l-15,6c-1.9-1.5,0.1-6.5-4-8c-4.4,0.4-8.7,2.8-11,6
	c-2.3,0.3-5.3-0.8-7,1c-1.1,2.6,2,3.3,3,5h3c-5,0-11.5,4.5-15,0c-1.2,0.6-0.9,1.9-1,3c6.7,4,16.3,5,20,12c-1.4,3.7-5.3,1.3-8,2l-1-1
	c-1.1,1.8-3.3,0.7-5,1l-1-1c0.3,5.5-8.6,4.6-6,11c-2.4,0.6-4,3.3-6,5c7.6,0.8,1.3,9.1,6,12c-9.8,2.8-22.7,2.7-34,4
	c-2.1-5.2,10.1-11.3,0-13c-6.2-0.4-15.1-3.4-20,2c-0.5,4.6,5,6.7,3,12l-42,2c-3.4-2.1-1.3-7.3-6-8c-13.5,2.3-20.1-11.8-33-11
	c-2.4-0.8-8.9,3.9-11-2c-8.6,4-9.8-10-18-7c-0.6-3.3,1.2-6.8,0-9c-1.9,4.8-8.8,4.6-13,3l-12-7c-1.4,4.7-4.4,7.1-10,6l-4-4
	c-4.1,4.3-10.1,4.2-16,4c-10.8-1.9-21.1-8.1-31,0c-10.6,4.8-11.2-8.3-20-8l-10-1c14.5-7.3,31.5-11.5,48-11c1.4-3.7,5.3-1.3,8-2
	c1,1.7,0.9,3.7,3,5c7.5,1.2,5.9-11.1,15-8c9.5,0.6,17.4-5.7,27-2c-0.4,1.4,1.3,2,2,3c4.4-1.7,3.2-5.5,9-4c1.8,4.7,4-0.8,7,1
	c4.9,0.6,7.6,0.4,12-1c2.4-7.8,13.5-5.2,18-10c12.6-6.2,26.6,16.3,35-3c6.1-3.5,18.2,3.5,20-6C215.7,35.626,208.2,49.527,216,50.827
	z"/>
<path d="M440,61.827c-5.4,4.6,5.6,9.9-1,15c-2.9-0.1-5.8,0.7-6-3c1.6-6.9-7.6-2.7-8-9C429.6,62.727,434.6,61.727,440,61.827z"/>
<path d="M419,65.827c0.3,5.3-5.7,3.6-8,7c-2-0.3-4.6,0.8-6-1C406.1,65.327,414.3,67.827,419,65.827z"/>
</svg>

            
          
!
            
              (function(global,$F){
    /**
     * Adjust these values to alter appearance
     */
    var PATH_SAMPLES = 400,
        BRUSH_SCALE = 35,
        BRUSH_OPACITY = 0.07,
        PATH_WIDTH = 650,
        PATH_HEIGHT = 250,
        PATH_SEGMENTS = 8;

    var doc = global.document,
        serializeXmlNode,
        can = doc.getElementById('c'),
        cH = global.innerHeight || doc.body.scrollHeight,
        cW = global.innerWidth || doc.body.scrollWidth,
        canvas,
        brushSVG = doc.getElementById('brush'),
        loadBrushCB,
        brushObj,
        loadPath,
        strokedPath,
        makeRanPath,
        replaceWithImage;

    /* http://stackoverflow.com/questions/4916327/javascript-replacement-for-xmlserializer-serializetostring/4916895#4916895 */
    serializeXmlNode = function serializeXmlNode(xmlNode){
        if (typeof window.XMLSerializer != "undefined"){
            return (new window.XMLSerializer()).serializeToString(xmlNode);
        } else if (typeof xmlNode.xml != "undefined"){
            return xmlNode.xml;
        }
        return "";
    };

    makeRanPath = function makeRanPath(minX,maxX,minY,maxY,maxPoints){
        var rangeX = maxX - minX,
            rangeY = maxY - minY,
            maxPoints = maxPoints || 20,
            path = document.createElementNS('http://www.w3.org/2000/svg','path'),
            pathPoints = [],
            i, l,
            ranNum,
            ranPoint;

        ranNum = function ranNum(range,base){
            var r = range || 1,
            b = base || 0;
            return b + Math.floor(Math.random()*(r+1));
        };

        ranPoint = function ranPoint(){
            return ranNum(rangeX,minX) + ' ' + ranNum(rangeY,minY);
        };

        pathPoints.push( 'M'+minX+' '+ranNum(rangeY,minY) );

        for(i=0,l=ranNum(maxPoints);i<l;i++){
            pathPoints.push( 'C '+ranPoint()+', '+ranPoint()+', '+ranPoint() );
        }

        pathPoints.push( 'C '+ranPoint()+', '+ranPoint()+', '+maxX+' '+ranNum(rangeY,minY) );

        path.setAttribute('d',pathPoints.join(' ') );

        return path;
    };

    can.setAttribute("height", cH - 20);
    can.setAttribute("width", cW - 20);

    canvas = new $F.Canvas('c',{
        backgroundColor: 'rgb(250,250,250)'
    });

    loadPath = function loadPath( paths, options ){
        var path = makeRanPath(0,PATH_WIDTH,0,PATH_HEIGHT,PATH_SEGMENTS),
            samples = PATH_SAMPLES || 1,
            strokepaths = [],
            len,
            step = 1,
            i,
            p,
            nP;

        len  = path.getTotalLength();
        step = len/samples;
        for(i=0;i<len;i+=step){
            p = path.getPointAtLength(i);
            nP = path.getPointAtLength(i+step);
            strokepaths.push( 
                brushObj.clone().set({ 
                    left: p.x, 
                    top: p.y, 
                    angle: Math.atan2( ( nP.y - p.y ), ( nP.x - p.x ) ) * 180 / Math.PI,
                    
                })
            );
        }
        strokedPath = new $F.Group(strokepaths);
        strokedPath.set({ left: canvas.width/2 , top: canvas.height/2  });
        strokedPath.scaleToHeight(canvas.height-10);
        if(strokedPath.currentWidth > canvas.width){
            strokedPath.scaleToWidth(canvas.width-10);
        }
        canvas.add(strokedPath);
        return strokedPath;
    };
  
    replaceWithImage = function replaceWithImage( obj ){
      var cloneCB,
          ndx = canvas.getObjects().indexOf(obj);
      cloneCB = function replaceWithImage_cloneCB( objAsImage ){
        objAsImage.setLeft( obj.getLeft() );
        objAsImage.setTop( obj.getTop() );
        objAsImage.setVisible( false );
        canvas.add( objAsImage );
        objAsImage.moveTo( ndx );
        objAsImage.setVisible( true );
        canvas.remove( obj );
      }
      obj.setCoords();
      obj.cloneAsImage( cloneCB );
      return this;
    };

    loadBrushCB = function loadBrushCB( paths, options ){
        var red, 
            green, 
            blue;
        brushObj = $F.util.groupSVGElements( paths, options );
        brushObj.scaleToHeight(BRUSH_SCALE);
        brushObj.opacity = BRUSH_OPACITY;
        brushObj.setFill('rgb(255,0,0)');
        red = loadPath();
        brushObj.setFill('rgb(0,255,0)');
        green = loadPath();
        brushObj.setFill('rgb(0,0,255)');
        blue = loadPath();
        
        replaceWithImage(green);
        replaceWithImage(red);
        replaceWithImage(blue);
      console.log(canvas);
    };

    $F.loadSVGFromString( serializeXmlNode(brushSVG), loadBrushCB );

})(this,fabric);
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console