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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <div class="canvas-wrapper">
  <canvas id="zdog-canvas" class="zdog-canvas" width="240" height="240"></canvas>
</div>

              
            
!

CSS

              
                body {
  background-color: #fff;
}
.canvas-wrapper {
  overflow: hidden;
  height: 100%;
  width: 100%;
}
              
            
!

JS

              
                //adjust canvas size for screen size
const canvas = document.getElementById('zdog-canvas');
canvas.setAttribute('width', window.innerWidth);
canvas.setAttribute('height', window.innerHeight);


var TAU = Zdog.TAU;
var ticker = 0;
var cycleCount = 160; 
var isSpinninig = true; 


const illo = new Zdog.Illustration({
  // set canvas with selector
  element: '#zdog-canvas',
  scale: 1,
  dragRotate: true,
  rotate: {x: -TAU/24},
  onDragStart: function() {
    isSpinninig = false;
  },
});


//start head
const headGroup = new Zdog.Group({
  addTo: illo,
  translate: {y: -50}
});

const headDepth = 100

const head = new Zdog.RoundedRect({
  addTo: headGroup,
  width: 110,
  height: 15,
  stroke: headDepth,
  color: 'black',
  cornerRadius: 0,
});


const earTranslateX = 50;
const earTranslateY = -45;
const earRotateY = -1 * TAU/22;
const ear = new Zdog.Cone({
  addTo: headGroup,
  diameter: 70,
  length: 35,
  stroke: false,
  color: '#000',
  backface: '#000',
  rotate: {x: TAU/4, y: earRotateY},
  translate: {x: earTranslateX, y: earTranslateY},
});
ear.copy({
  rotate: {x: TAU/4, y: -1 * earRotateY},
  translate: {x: -1 * earTranslateX, y: earTranslateY}
});


const faceGroup = new Zdog.Group({
  addTo: illo,
  translate: {y: -50, z: headDepth/2 + 5}
});

const faceWidth = 150;
const faceHeight = 70;
const face = new Zdog.RoundedRect({
  addTo: faceGroup,
  width: faceWidth,
  height: faceHeight,
  stroke: false,
  cornerRadius: 40,
  color: 'navajowhite',
  fill: true,
});


const eyeTranslateX = 38;
const eyeTranslateY = -5;
//const eyeTranslateZ = 50 + 10;
const eye_1 = new Zdog.Ellipse({
  addTo: faceGroup,
  width: 30,
  height: 40,
  stroke: false,
  color: '#fff',
  fill: true,
  translate: {x: eyeTranslateX, y: eyeTranslateY},
});
eye_1.copy({
  translate: {x: -1 * eyeTranslateX, y: eyeTranslateY},
});
const eye_2 = new Zdog.Ellipse({
  addTo: faceGroup,
  width: 20,
  height: 26,
  stroke: false,
  color: 'brown',
  fill: true,
  translate: {x: eyeTranslateX -1, y: eyeTranslateY},
});
eye_2.copy({
  translate: {x: -1 * (eyeTranslateX -1), y: eyeTranslateY},
});

const eye_3 = new Zdog.Ellipse({
  addTo: faceGroup,
  width: 6,
  height: 6,
  stroke: false,
  color: '#fff',
  fill: true,
  translate: {x: eyeTranslateX - 4, y: eyeTranslateY - 6},
});
eye_3.copy({
  translate: {x: -1 * eyeTranslateX - 2, y: eyeTranslateY - 6},
});

const nose = new Zdog.Ellipse({
  addTo: faceGroup,
  width: 5,
  height: 5,
  stroke: 3,
  fill: true,
  color: 'brown',
  translate: {y: 15},
});
const mouse = new Zdog.Shape({
  addTo: faceGroup,
  path: [
    { x: -10, y: 0},   // start
    { bezier: [
      { x:  -3, y: 5}, // start control point
      { x:  3, y: 5}, // end control point
      { x:  10, y: 0}, // end point
    ]},
  ],
  color: 'brown',
  stroke: 4,
  closed: false,
  translate: {y: 25},
});



const rightBeard = new Zdog.Shape({
  addTo: faceGroup,
  path: [
    { x: faceWidth/2, y: 0},   // start
    { bezier: [
      { x:  faceWidth/2 + 40, y: -1}, // start control point
      { x:  faceWidth/2 + 60, y:  -1}, // end control point
      { x:  faceWidth/2 + 80, y:  3}, // end point
    ]},
  ],
  closed: false,
  stroke: 2,
  color: '#000',
});
rightBeard.copy({
  translate: {y: 10}
});

const leftBeard = new Zdog.Shape({
  addTo: faceGroup,
  path: [
    { x: -1 * faceWidth/2, y: 0},   // start
    { bezier: [
      { x:  -1 * (faceWidth/2 + 40), y: -1}, // start control point
      { x:  -1 * (faceWidth/2 + 60), y:  -1}, // end control point
      { x:  -1 * (faceWidth/2 + 80), y:  3}, // end point
    ]},
  ],
  closed: false,
  stroke: 2,
  color: '#000',
});
leftBeard.copy({
  translate: {y: 10}
});

// end head

// start legs
const legsGroup = new Zdog.Group({
  addTo: illo
});

let leg_a = [];
leg_a_1 = new Zdog.Shape({
  addTo: legsGroup,
  path: [
    { x: 0, y: 0},   // start
    { bezier: [
      { x:  -40, y: 10}, // start control point
      { x:  0, y: 100}, // end control point
      { x:  -40, y: 100}, // end point
    ]},
  ],
  closed: false,
  stroke: 20,
  color: '#000',
  translate: {x: -20}
});
leg_a.push(leg_a_1);
leg_a.push(
    leg_a_1.copy({
    rotate: {y: TAU/4},
    translate: {x: -20}
  })
);
leg_a.push(
  leg_a_1.copy({
    rotate: {y: TAU/2},
    translate: {x: 20}
  })
);
leg_a.push(
  leg_a_1.copy({
    rotate: {y: 3*TAU/4},
    translate: {x: 20}
  })
);

let leg_b = [];
const leg_b_1 = new Zdog.Shape({
  addTo: legsGroup,
  path: [
    { x: 0, y: 0, z:0},   // start
    { bezier: [
      { x:  0, y: 10, z:0}, // start control point
      { x:  0, y: 100, z:0}, // end control point
      { x:  -10, y: 110, z:30}, // end point
    ]},
  ],
  closed: false,
  stroke: 20,
  color: 'black',
  translate: {x: -10}
});
leg_b.push(leg_b_1)
leg_b.push(
  leg_b_1.copy({
    rotate: {y: TAU/4},
    translate: {x: -10},
  })
);
leg_b.push(
  leg_b_1.copy({
    rotate: {y: TAU/2},
    translate: {x: 10},
  })
);
leg_b.push(
  leg_b_1.copy({
    rotate: {y: 3*TAU/4},
    translate: {x: 10},
  })
);


// end legs

const foundationGroup = new Zdog.Group({
  addTo: illo,
});
const foundation = new Zdog.Ellipse({
  addTo: illo,
  width: 200,
  height: 200,
  stroke: 20,
  fill: true,
  color: 'powderblue',
  rotate: {x: TAU/4},
  translate: {y: 130},
})
foundation.copy({
  color: 'blue',
  translate: {y: 140},
  stroke: 20,
});


const spinIllo = () => {
  let progress = ticker / cycleCount;
  let tween = Zdog.easeInOut( progress % 1, 4 );
  illo.rotate.y = tween * TAU;
}

const moveLegs = () => {
  let legsRotateX = 0.006 * Math.sin(TAU * ticker / 90);
  let legsRotateY = 0.012 * Math.cos(TAU * ticker / 110);
  let legsRotateZ = 0.006 * Math.sin(TAU * ticker / 120);
  leg_a.forEach((leg) => {
    leg.rotate.x += legsRotateX;
    leg.rotate.y += legsRotateY;
    leg.rotate.z += legsRotateZ;
  });
  leg_b.forEach((leg) => {
    leg.rotate.x -= legsRotateX;
    leg.rotate.y -= legsRotateY;
    leg.rotate.z -= legsRotateZ;
  });
}


const animate = () => {
  ticker ++;
  moveLegs();
  if(isSpinninig){
    spinIllo();
  }
  illo.updateRenderGraph();
  // animate next frame
  requestAnimationFrame( animate );
}

animate();
              
            
!
999px

Console