Pen Settings

HTML

CSS

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

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <canvas class="zdog-canvas" width="600" height="600"></canvas>
              
            
!

CSS

              
                body {
  margin: 0;
  padding: 0;
}

.zdog-canvas {
  background: #333;
  cursor: move;
  display: block;
  width: 100%;
  height: 100%;
}
              
            
!

JS

              
                let isSpinning = true;

let illo = new Zdog.Illustration({
  element: '.zdog-canvas',
  dragRotate: true,
  resize: 'fullscreen',
  onDragStart: function() {
    isSpinning = false;
  },
});

const bodyDia = 150;
const bodyHeight = 120;

const armColor = '#fff';
const bodyStartColor = [68, 139, 39];
const bodyEndColor = [51, 105, 30];

function bodyColor(t) {
  let r = t * (bodyEndColor[0] - bodyStartColor[0]) + bodyStartColor[0];
  let g = t * (bodyEndColor[1] - bodyStartColor[1]) + bodyStartColor[1];
  let b = t * (bodyEndColor[2] - bodyStartColor[2]) + bodyStartColor[2];
  return `rgb(${r}, ${g}, ${b})`;
}
const bodyBottomDia = 30;

var droid = new Zdog.Anchor({
  addTo: illo,
  translate: { y:-55 }
});
var handL, handR;

// Body
(function() {
  let stripSize = bodyBottomDia / 2;
  let stripCount = bodyHeight / stripSize;
  let offsetY = stripSize / 2;
  
  for (let i = 0; i < stripCount; i++) {
    new Zdog.Cylinder({
      addTo: droid,
      diameter: bodyDia,
      length: stripSize,
      stroke: false,
      color: bodyColor(i / (stripCount - 1)),
      backface: i == 0 ? bodyColor(1) : false,
      frontFace: false,
      rotate: {x: Math.PI  / 2},
      translate: {y: stripSize * i + offsetY}
    });
  }
  new Zdog.Ellipse({
    addTo: droid,
    width: bodyDia - bodyBottomDia,
    height: bodyDia - bodyBottomDia,
    stroke: bodyBottomDia,
    color: bodyColor(1),
    translate: {y: stripSize * stripCount},
    rotate: {x: Math.PI / 2}
  });
})();

// Hand
const handWidth = 30;
const armLength = 6;
const armWidth = 10;
const handLength = bodyHeight;
const armY = 30;

(function() {
  let dist = bodyDia / 2 + armLength + handWidth / 2;
  let handColor = bodyColor(1.1);
  
  new Zdog.Cylinder({
    addTo: droid,
    diameter: armWidth,
    length: armLength + 2,
    stroke: false,
    color: armColor,
    backface: handColor,
    rotate: {y: Math.PI / 2},
    translate: {y: armY, x: bodyDia / 2 + armLength / 2}
  });
  new Zdog.Cylinder({
    addTo: droid,
    diameter: armWidth,
    length: armLength + 2,
    stroke: false,
    color: armColor,
    backface: handColor,
    rotate: {y: Math.PI / 2},
    translate: {y: armY, x: -bodyDia / 2 - armLength / 2}
  });
  
  handL = new Zdog.Anchor({
    addTo: droid,
    translate: { x: -dist, y : armY}
  });
  new Zdog.Shape({
    addTo: handL,
    path: [
      { y: handWidth / 2 - armY },
      { y: handLength - handWidth / 2 - armY},
    ],
    stroke: handWidth,
    color: handColor
  });
  
  handR = handL.copyGraph({
    translate: { x: dist, y : armY}
  });
})();

const nextLength = 6;
const nextDia = 130;
// neck and head
(function() {
  new Zdog.Cylinder({
    addTo: droid,
    diameter: nextDia,
    length: nextLength,
    stroke: false,
    color: armColor,
    backface: bodyColor(0),
    rotate: {x: Math.PI / 2},
    translate: {y: -nextLength / 2}
  });
  
  new Zdog.Hemisphere({
    addTo: droid,
    diameter: bodyDia,
    // fill enabled by default
    // disable stroke for crisp edge
    stroke: false,
    color: bodyColor(0),
    backface: bodyColor(1),
    rotate: {x: Math.PI / 2},
    translate: {y: -nextLength}
  });
  
  new Zdog.Shape({
    addTo: droid,
    path: [
      { x: -50, y:  -90 },
      { x: -20, y: -50 },
      { x: 20, y: -50 },
      { x: 50, y:  -90 },
    ],
    stroke: 6,
    closed: false,
    color: bodyColor(0)
  });
  
  let eye1 = new Zdog.Anchor({
    addTo: droid,
    translate: {x: 0, y: -nextLength},
    rotate: {x: .5, y: .4}
  });
  new Zdog.Ellipse({
    addTo: eye1,
    diameter: 20,
    stroke: false,
    fill: true,
    color: armColor,
    translate: {z: bodyDia / 2}
  });
  
   eye1.copyGraph({
    rotate: {x: .5, y: -.4}
  });
})();

// Legs
(function() {
  let thinkness = 30;
  let height = 50;
  let depth = 60;
  let shift = 30;
  
  let y = bodyHeight + bodyBottomDia/2;
  let legColor = bodyColor(1.2);
  
  let leg1 = new Zdog.Anchor({
    addTo: droid,
    translate: {x: -shift, y: y}
  });
  new Zdog.Shape({
    addTo: leg1,
    path: [
      { y: thinkness, z: depth / 2 },
      { y: height, z: depth / 2 },
      { y: height, z: -depth / 2 },
      { y: thinkness, z: -depth / 2 },
    ],
    closed: false,
    stroke: thinkness,
    color: legColor
  });
  new Zdog.Cylinder({
    addTo: leg1,
    diameter: thinkness,
    length: thinkness * 1.5,
    stroke: false,
    color: legColor,
    backface: legColor,
    frontFace: bodyColor(1),
    rotate: {x: Math.PI / 2},
    translate: {y: thinkness *.75, z : depth / 2}
  });
  new Zdog.Cylinder({
    addTo: leg1,
    diameter: thinkness,
    length: thinkness * 1.5,
    stroke: false,
    color: legColor,
    backface: legColor,
    frontFace: bodyColor(1),
    rotate: {x: Math.PI / 2},
    translate: {y: thinkness * .75, z : -depth / 2}
  });
  new Zdog.Shape({
    addTo: leg1,
    path: [
      { x: thinkness / 2, z: depth / 2 },
      { x: thinkness / 2, y: height, z: depth / 2 },
      { x: thinkness / 2, y: height, z: -depth / 2 },
      { x: thinkness / 2, z: -depth / 2 },
    ],
    stroke: false,
    fill: true,
    color: legColor
  });
  new Zdog.Shape({
    addTo: leg1,
    path: [
      { x: -thinkness / 2, z: depth / 2 },
      { x: -thinkness / 2, y: height, z: depth / 2 },
      { x: -thinkness / 2, y: height, z: -depth / 2 },
      { x: -thinkness / 2, z: -depth / 2 },
    ],
    stroke: false,
    fill: true,
    color: legColor
  });
  
  leg1.copyGraph({
    translate: {x: shift, y: y}
  });
  
})();


const handDuration = 2000;
const w = 2 * Math.PI / handDuration;
function animate() {
  // let angle = .6 * Math.cos(Date.now() * w)
  // handL.rotate.x = angle;
  // handR.rotate.x = -angle;
  illo.rotate.y += isSpinning ? 0.03 : 0;
  
  illo.updateRenderGraph();
  requestAnimationFrame( animate );
}
animate();

              
            
!
999px

Console