cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - 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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

            
              <!-- Font Awesome -->
<script src="https://use.fontawesome.com/46af14eb3c.js"></script>

<!-- Bootstrap core CSS -->
<link href="https://v4-alpha.getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet">

<div class="container">
  <div class="row">
    <div class="col-sm-3 p-r-0" style="min-width: 200px;">
      <p>Pen:</p>
      <div id="colorpalette" class="colorpalette"></div>
      <hr>
      Size: <input id="size" type="range" min="0.5" max="100" value="1" step="0.1"/>
      <hr>
      <p>
        Erase:
        <span id="eraser" class="btn btn-secondary eraser center-block"><i class="fa fa-eraser" aria-hidden="true"></i></span>
      </p>
    </div>
    <div class="col-sm-9 p-l-0 p-r-0">
      <!-- SketchpadJS container here: -->
      <div id="sketchpad"></div>
    </div>
  </div>
</div>

<!-- http://sketchpad.pro - free online drawing board tool -->
<script src="http://cdn.sketchpad.pro/dist/current/sketchpad.min.js"></script>
<script src="http://developers.sketchpad.pro/js/WebSocketJsonWrapper.js"></script>
            
          
!
            
              #sketchpad {
    margin: auto;
    width: 100%;
    height: 480px;
    background-repeat: repeat;
    border: 1px solid #aaa;
}

            
          
!
            
              /*global window, Sketchpad, WebSocket, Colorpalette, WebSocketJsonWrapper*/

function initSketchpad() {
    "use strict";

    // websocket wrapper
    var ws = new WebSocketJsonWrapper();

    window.addEventListener("hashchange", function () {
        window.location.reload();//reconnect on room name in hash change
    });

    var sketchpad = new Sketchpad({
        containerEl: document.getElementById("sketchpad"),
        token: window.location.hash || "#simple",
        ws: ws,
        createPageConfig: {sid: "autoplay", no: 1}
    });
    // sketchpad.setMetaConfig({});
    // sketchpad.clearSketchpad();
    // var sketch = sketchpad.room.addSketch(sketchpad, {sid: "autoplay", no: 1});
    // sketchpad.initialised = true;
    // sketchpad.room.setActiveSketch(sketchpad, sketch);

    // avaliable tools `src/sketchpad.tool.*.js`, ex. "pen", "colouring", "line", "rect", "circ"...
    var toolId = "mandala";
    var tool = sketchpad.setTool(toolId).getCurrentTool();

    //draw from background
    tool.layers = ["B"];
    tool.axis = 16;
    tool.mirrorV = false;

    console.log("Selected tool:", tool);

    //color
    var colorpalette = new Colorpalette({
        containerEl: document.getElementById("colorpalette")
    }).on("change", function (e) {
        sketchpad.setTool(toolId).getCurrentTool().setColor(e.color.red, e.color.green, e.color.blue, e.color.alpha);
    }).setColor(tool.setColor(0, 255, 255, 1).getColor());

    //size
    document.getElementById("size").addEventListener("change", function (e) {
        sketchpad.getCurrentTool().setSize(e.target.value);
    });
    document.getElementById("size").value = tool.setSize(2).getSize();

    //rubber
    document.getElementById("eraser").addEventListener("click", function () {
        sketchpad.setTool("eraser");
    });

    //objects visible in developer console
    window.sketchpad = sketchpad;
    window.colorpalette = colorpalette;
    window.tool = tool;
    sketchpad.setScale(0.5);
    sketchpad.on("initialised", function () {
        ws.emitFile("https://developers.sketchpad.pro/example.sketchpad.json");
    });

}
initSketchpad();


            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console