Convert Figma logo to code with AI

metafizzy logozdog

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

10,336
393
10,336
51

Top Related Projects

101,622

JavaScript 3D Library.

43,513

The HTML5 Creation Engine: Create beautiful digital content with the fastest, most flexible 2D WebGL renderer.

21,400

p5.js is a client-side JS platform that empowers artists, designers, students, and anyone to learn to code and express themselves creatively on the web. It is based on the core principles of Processing. http://twitter.com/p5xjs —

3,696

Minimal WebGL Library

Cross-Platform JavaScript Creative Coding Framework

JavaScript Performance Monitor

Quick Overview

Zdog is a pseudo-3D engine for creating 2D illustrations with a playful, sketchy aesthetic. It provides a simple and intuitive API for building and animating vector-based shapes, scenes, and characters.

Pros

  • Lightweight and Performant: Zdog is designed to be lightweight and efficient, making it suitable for use in web-based applications and animations.
  • Flexible and Customizable: Zdog offers a wide range of customization options, allowing developers to create unique and visually appealing designs.
  • Intuitive API: The API is straightforward and easy to use, making it accessible for developers of all skill levels.
  • Active Development: The project is actively maintained and regularly updated, ensuring ongoing support and improvements.

Cons

  • Limited 3D Capabilities: While Zdog can create pseudo-3D effects, it is primarily a 2D rendering engine and may not be suitable for more complex 3D applications.
  • Steep Learning Curve for Advanced Features: Some of the more advanced features and techniques in Zdog may have a steeper learning curve for developers who are new to the library.
  • Lack of Built-in Physics Simulation: Zdog does not include built-in physics simulation, which may be a limitation for certain types of animations or interactions.
  • Limited Community and Documentation: Compared to some larger and more established libraries, Zdog may have a smaller community and less comprehensive documentation.

Code Examples

Here are a few short code examples demonstrating the use of Zdog:

Creating a Simple Shape

const illo = new Zdog.Illustration({
  element: '.my-canvas',
  zoom: 4,
});

const shape = new Zdog.Shape({
  addTo: illo,
  path: [
    { x: 0, y: 0 },
    { x: 2, y: 0 },
    { x: 2, y: 2 },
    { x: 0, y: 2 },
  ],
  closed: true,
  color: '#ED2',
  stroke: 0.5,
});

This code creates a simple square shape and adds it to the Zdog illustration.

Animating a Shape

const box = new Zdog.Rect({
  addTo: illo,
  width: 2,
  height: 2,
  color: '#636',
  stroke: 0.5,
});

let rotation = 0;

function animate() {
  rotation += 0.01;
  box.rotate.z = rotation;
  illo.updateRenderGraph();
  requestAnimationFrame(animate);
}

animate();

This code creates a rotating box by updating the rotate.z property of the box shape on each animation frame.

Creating a 3D-like Effect

const illo = new Zdog.Illustration({
  element: '.my-canvas',
  zoom: 4,
  perspective: 100,
});

const cube = new Zdog.Rect({
  addTo: illo,
  width: 2,
  height: 2,
  depth: 2,
  color: '#636',
  stroke: 0.5,
});

cube.rotate.x = Zdog.TAU / 8;
cube.rotate.y = Zdog.TAU / 6;

This code creates a 3D-like cube effect by setting the depth property and rotating the shape in 3D space.

Getting Started

To get started with Zdog, you can follow these steps:

  1. Include the Zdog library in your HTML file:
<script src="https://unpkg.com/zdog@1/dist/zdog.dist.min.js"></script>
  1. Create a new Zdog illustration and add shapes to it:
const illo = new Zdog.Illustration({
  element: '.my-canvas',
  zoom: 4,
});

const shape = new Zdog.Shape({
  addTo: illo,
  path: [
    { x: 0, y: 0 },

Competitor Comparisons

101,622

JavaScript 3D Library.

Pros of three.js

  • More comprehensive 3D rendering capabilities, including advanced lighting, shadows, and textures
  • Larger community and ecosystem, with extensive documentation and third-party resources
  • Support for a wide range of 3D file formats and export options

Cons of three.js

  • Steeper learning curve due to its extensive feature set and complexity
  • Larger file size and potentially higher performance overhead for simpler projects

Code Comparison

three.js:

const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

Zdog:

const illo = new Zdog.Illustration({
  element: '.zdog-canvas',
  zoom: 4,
});
new Zdog.Box({
  addTo: illo,
  width: 100,
  height: 100,
  depth: 100,
  stroke: false,
  color: '#C25',
});

Summary

three.js offers a more powerful and versatile 3D rendering solution with a larger ecosystem, making it suitable for complex 3D projects. Zdog, on the other hand, provides a simpler and more lightweight approach to creating pseudo-3D graphics, making it easier to learn and use for basic illustrations and animations. The choice between the two depends on the project's requirements and the developer's familiarity with 3D concepts.

43,513

The HTML5 Creation Engine: Create beautiful digital content with the fastest, most flexible 2D WebGL renderer.

Pros of PixiJS

  • More comprehensive and feature-rich 2D rendering engine
  • Larger community and ecosystem with extensive plugins and extensions
  • Better performance for complex 2D graphics and animations

Cons of PixiJS

  • Steeper learning curve due to its extensive API and features
  • Larger file size, which may impact load times for smaller projects
  • Primarily focused on 2D graphics, lacking built-in 3D capabilities

Code Comparison

PixiJS example:

const app = new PIXI.Application();
document.body.appendChild(app.view);
const sprite = PIXI.Sprite.from('image.png');
app.stage.addChild(sprite);
app.ticker.add(() => sprite.rotation += 0.01);

Zdog example:

let illo = new Zdog.Illustration({
  element: '.zdog-canvas',
  dragRotate: true,
});
new Zdog.Rect({
  addTo: illo,
  width: 80,
  height: 80,
  stroke: 4,
  color: '#EA0',
});
illo.updateRenderGraph();

Both libraries offer different approaches to graphics rendering. PixiJS provides a robust 2D rendering engine with a focus on performance and extensive features, while Zdog offers a simpler, lightweight 3D engine for creating pseudo-3D illustrations. The choice between them depends on project requirements, complexity, and whether 2D or 3D graphics are needed.

21,400

p5.js is a client-side JS platform that empowers artists, designers, students, and anyone to learn to code and express themselves creatively on the web. It is based on the core principles of Processing. http://twitter.com/p5xjs —

Pros of p5.js

  • Broader scope: p5.js is a full-featured creative coding library for interactive graphics, animations, and more
  • Extensive documentation and large community support
  • Easier integration with web technologies and DOM manipulation

Cons of p5.js

  • Larger file size and potentially slower performance for simple 3D projects
  • Steeper learning curve for beginners due to its extensive feature set

Code Comparison

p5.js:

function setup() {
  createCanvas(400, 400, WEBGL);
}

function draw() {
  background(200);
  rotateX(frameCount * 0.01);
  rotateY(frameCount * 0.01);
  box(100);
}

Zdog:

let illo = new Zdog.Illustration({
  element: '.zdog-canvas',
  dragRotate: true,
});

new Zdog.Box({
  addTo: illo,
  width: 100,
  height: 100,
  depth: 100,
  stroke: false,
  color: '#C25',
});

illo.updateRenderGraph();

Summary

While p5.js offers a comprehensive toolkit for creative coding with extensive community support, Zdog focuses specifically on 3D graphics with a simpler API. p5.js is more versatile but may be overkill for simple 3D projects, where Zdog's lightweight nature shines. The choice between them depends on the project's scope and the developer's familiarity with each library.

3,696

Minimal WebGL Library

Pros of OGL

  • More comprehensive 3D rendering capabilities, supporting complex scenes and advanced shaders
  • Better performance for large-scale 3D applications
  • Extensive documentation and examples for various use cases

Cons of OGL

  • Steeper learning curve due to its more complex API
  • Larger file size and potentially higher resource usage
  • Less suitable for simple, lightweight 3D graphics

Code Comparison

OGL example:

const renderer = new Renderer();
const gl = renderer.gl;
const camera = new Camera(gl);
const scene = new Transform();

const geometry = new Box(gl);
const material = new Program(gl, {
    vertex,
    fragment,
});

Zdog example:

let illo = new Zdog.Illustration({
    element: '.zdog-canvas',
    zoom: 4,
});

new Zdog.Box({
    addTo: illo,
    width: 100,
    height: 100,
    depth: 100,
    stroke: false,
    color: '#C25',
});

Summary

OGL is a more powerful and flexible 3D rendering library, suitable for complex 3D applications. Zdog, on the other hand, excels in creating simple, stylized 3D graphics with a more approachable API. Choose OGL for advanced 3D projects and Zdog for lightweight, pseudo-3D illustrations.

Cross-Platform JavaScript Creative Coding Framework

Pros of sketch.js

  • Lightweight and simple 2D drawing library
  • Easy to set up and use for quick prototyping
  • Supports both canvas and WebGL rendering

Cons of sketch.js

  • Limited to 2D graphics and animations
  • Less active development and community support
  • Fewer built-in features compared to more comprehensive libraries

Code Comparison

sketch.js:

Sketch.create({
  setup: function() {
    // Initialize your sketch
  },
  draw: function() {
    // Draw your sketch
  }
});

Zdog:

let illo = new Zdog.Illustration({
  element: '.zdog-canvas',
  zoom: 4,
});

new Zdog.Box({
  addTo: illo,
  width: 100,
  height: 100,
  depth: 100,
  stroke: false,
  color: '#C25',
});

illo.updateRenderGraph();

Key Differences

  • sketch.js focuses on 2D graphics, while Zdog is designed for pseudo-3D illustrations
  • Zdog offers a more specialized set of tools for creating isometric-style graphics
  • sketch.js provides a simpler API for general-purpose 2D drawing and animation
  • Zdog has a more active development community and regular updates

Both libraries serve different purposes, with sketch.js being more suitable for quick 2D prototypes and Zdog excelling in creating pseudo-3D illustrations and animations.

JavaScript Performance Monitor

Pros of stats.js

  • Lightweight and focused on performance monitoring
  • Easy to integrate into existing projects
  • Provides real-time FPS, MS, and MB statistics

Cons of stats.js

  • Limited to performance monitoring only
  • Less visually appealing compared to Zdog's 3D capabilities
  • Fewer customization options for appearance

Code Comparison

stats.js:

var stats = new Stats();
stats.showPanel(0); // 0: fps, 1: ms, 2: mb, 3+: custom
document.body.appendChild(stats.dom);

function animate() {
    stats.begin();
    // monitored code goes here
    stats.end();
    requestAnimationFrame(animate);
}

Zdog:

let illo = new Zdog.Illustration({
    element: '.zdog-canvas',
    zoom: 4,
});

new Zdog.Box({
    addTo: illo,
    width: 100,
    height: 100,
    depth: 100,
    stroke: false,
    color: '#C25',
});

function animate() {
    illo.rotate.y += 0.03;
    illo.updateRenderGraph();
    requestAnimationFrame(animate);
}

While stats.js focuses on performance monitoring, Zdog is a 3D engine for canvas and SVG. stats.js is more suitable for developers needing to track performance metrics, while Zdog is better for creating interactive 3D graphics. The code examples show the simplicity of integrating stats.js for monitoring versus creating a 3D object with Zdog.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Zdog

Round, flat, designer-friendly pseudo-3D engine

View complete documentation and live demos at zzz.dog.

Install

Download

CDN

Link directly to Zdog JS on unpkg.

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

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.

let isSpinning = true;

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

// circle
new Zdog.Ellipse({
  addTo: illo,
  diameter: 20,
  translate: { z: 10 },
  stroke: 5,
  color: '#636',
});

// square
new Zdog.Rect({
  addTo: illo,
  width: 20,
  height: 20,
  translate: { z: -10 },
  stroke: 3,
  color: '#E62',
  fill: true,
});

function animate() {
  illo.rotate.y += isSpinning ? 0.03 : 0;
  illo.updateRenderGraph();
  requestAnimationFrame( animate );
}
animate();

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 <canvas> or <svg>. 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 by Peter Collingridge.

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:

My stuff:


Licensed MIT. Made by Metafizzy 🌈🐻

NPM DownloadsLast 30 Days