Zdog

Flat, round, designer-friendly pseudo-3D engine for canvas & SVG

README

Zdog


_Round, flat, designer-friendly pseudo-3D engine_

View complete documentation and live demos at zzz.dog.

Install


Download


+ zdog.dist.min.js minified, or
+ zdog.dist.js un-minified

CDN


Link directly to Zdog JS on unpkg.

  1. ``` html
  2. <script src="https://unpkg.com/zdog@1/dist/zdog.dist.min.js"></script>
  3. ```

Package managers


npm: npm install zdog

Bower: bower install zdog

Hello world demo


Create 3D models with Zdog by adding shapes. See Getting started for a walk-through of this demo.

  1. ``` js
  2. let isSpinning = true;

  3. let illo = new Zdog.Illustration({
  4.   element: '.zdog-canvas',
  5.   zoom: 4,
  6.   dragRotate: true,
  7.   // stop spinning when drag starts
  8.   onDragStart: function() {
  9.     isSpinning = false;
  10.   },
  11. });

  12. // circle
  13. new Zdog.Ellipse({
  14.   addTo: illo,
  15.   diameter: 20,
  16.   translate: { z: 10 },
  17.   stroke: 5,
  18.   color: '#636',
  19. });

  20. // square
  21. new Zdog.Rect({
  22.   addTo: illo,
  23.   width: 20,
  24.   height: 20,
  25.   translate: { z: -10 },
  26.   stroke: 3,
  27.   color: '#E62',
  28.   fill: true,
  29. });

  30. function animate() {
  31.   illo.rotate.y += isSpinning ? 0.03 : 0;
  32.   illo.updateRenderGraph();
  33.   requestAnimationFrame( animate );
  34. }
  35. animate();
  36. ```

About Zdog


Hi, Dave here. I wanted to make a video game. I needed a 3D engine, but most engines were too powerful and complex for me. I made Zdog so I could design and display simple 3D models without a lot of overhead.

Zdog is directly inspired by Dogz, a virtual pet game by P.F. Magic released in 1995. It used flat 2D circle sprites to render the Dogz’ models, but in a 3D scene. See Dogz playthrough video here. Dogz were fully animated in real time, running, flopping, scratching (on Windows 3.1!). It was remarkable.

Zdog uses the same principle. It renders all shapes using the 2D drawing APIs in either `` or ``. Spheres are actually dots. Toruses are actually circles. Capsules are actually thick lines. It’s a simple, but effective trick. The underlying 3D math comes from [Rotating 3D Shapes](https://www.khanacademy.org/computing/computer-programming/programming-games-visualizations/programming-3d-shapes/a/rotating-3d-shapes) by [Peter Collingridge](https://petercollingridge.appspot.com/3D-tutorial/rotating-objects).

Zdog is pronounced "Zee-dog" in American parlance or "Zed-dog" in British.

Beta!


Zdog v1 is a beta-release, of sorts. This is my first time creating a 3D engine, so I probably got some stuff wrong. Expect lots of changes for v2. Provide input and select new features on the Zdog issue tracker on GitHub.

More Zdog resources


Other people's stuff:

+ Zfont - Text plugin for Zdog
+ vue-zdog - Vue wrapper for Zdog
+ zDogPy - Python port of Zdog for DrawBot

My stuff:

+ zdog-docs - Docs site source code


Licensed MIT. Made by Metafizzy 🌈🐻