DrCircuitsCanvasLibrary

DrCircuitsCanvasLibrary click to view examples live

A tiny library for doing boilerplate stuff for canvas based vanilla js gfx and game projects.

Installation: Install via npm: npm install --save drcircuitscanvaslibrary

Usage:

(function(){
    let scr;
  
    function setup() {
        scr = dcl.setupScreen(window.innerWidth ,window.innerHeight );
        scr.setBgColor('darkblue');
        document.body.style.backgroundColor = 'darkblue';      
    }
    function draw(t, dt){
       // your drawing and update logic here..
    }
    dcl.init(setup, draw);
    dcl.animate();
})();

Examples:

setupScreen function

setupScreen: function (width, height, keepSquare, gridScale)

Parameters:

return object:

This method returns an object with the following:

dcl.random function

dcl.random: function(min, max)

Parameters:

return object:

This method returns a random integer between the given min / max values passed to the function.

dcl.rect function

dcl.rect: function(x, y, width, height, color, lineWidth, lineColor, ctx)

Parameters:

void

This method draws a rectangle based on the given parameters.

dcl.circle function

dcl.circle: function(x, y, radius, color, lineWidth, lineColor, ctx)

Parameters:

void

This method draws a circle based on the given parameters.

dcl.line function

dcl.circle: function(x, y, dx, dy, lineWidth, lineColor, ctx)

Parameters:

void

This method draws a line based on the given parameters.

dcl.init function

Parameters:

dcl.animate function

This function starts the render loop.