Skip to content
This repository has been archived by the owner on Mar 26, 2022. It is now read-only.
/ canvas-pack Public archive

A creative-coding environment for JavaScript

Notifications You must be signed in to change notification settings

paulkre/canvas-pack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

canvas-pack

A creative-coding environment for JavaScript. Allows you to use npm packages in your creative-coding sketches. Will automatically reload the page as soon as you make changes to your code.

Usage

  1. Install canvas pack in your project (npm install --save canvas-pack).

  2. Create index.js in root directory:

    import createRegl from "regl";
    
    const canvas = document.getElementById("canvas");
    
    const regl = createRegl(canvas);
    
    const drawTriangle = regl({
      frag: `
       precision mediump float;
       uniform vec4 color;
       void main() {
          gl_FragColor = color;
       }`,
    
      vert: `
       precision mediump float;
       attribute vec2 position;
       void main() {
          gl_Position = vec4(position, 0, 1);
       }`,
    
      attributes: {
        position: regl.buffer([
          [-0.9, -0.9],
          [0.9, -0.9],
          [0.9, 0.9],
        ]),
      },
    
      uniforms: {
        color: regl.prop("color"),
      },
    
      count: 3,
    });
    
    regl.frame(({ time, tick }) => {
      regl.clear({
        color: [0, 0, 0, 0],
        depth: 1,
      });
    
      drawTriangle({
        color: [
          Math.cos(time * 0.1),
          Math.sin(time * 0.08),
          Math.cos(time * 0.3),
          1,
        ],
      });
    });
  3. Add start script to package.json:

    {
      // ...
      "scripts": {
        "start": "canvas-pack"
      }
      // ...
    }
  4. Run npm start.

  5. Open browser and navigate to http://localhost:3000/.

About

A creative-coding environment for JavaScript

Resources

Stars

Watchers

Forks

Packages

No packages published