Code Monkey home page Code Monkey logo

canvasrenderer's Introduction

CanvasRenderer

LATEST VERSION
source code

#About This is a library which enables canvas to have object which you can manipulate like DOM elements. The syntax is familiar as it acts like DOM elements. You set style attribute like this:

circle.style.width(100);
circle.styler.x(20);

Don't worry the library is not trying to reinvent the wheel but it creates wrappers for canvas to allow it to behave like DOM elements. The is one canvas renderer/ticker which only runs if a change has been made to a style attribute on the canvas objects.

This library comes with several plugins/extensions in which you have the option to use and the whole library is scalable and extendible. The idea is that you build components and wrappers by extending the DisplayObject object.

A animation extension is available with this library to allow you to do easing and animate object in your canvas.

Another extension call CanvasEvents gives the canvas and displayobjects 'addEventListener' and 'removeEventListener' methods.

##Basics

The library consists of two main components, the Canvas object and the DisplayObject.

###Structure of this Library
Structure

###Canvas The Canvas is a wrapper for the HTML5 canvas and it stores a reference to object which have been appended to it. You can create multiple instances of the canvas wrapper. ###DisplayObject The DisplayObject the base level object which you can extend to make your own custom components. This like the canvas can have children associated with it and contains a style method where you can set different style attributes.

###Style The style object works like the DOM stlye object, it allows you to change styling properties such as height, width, background colour, rotation and opacity etc.
This is the heart of the library as only changes to a style will render the canvas but you can call CanvasRenderer.render() manually if required.

##Example Code

//creating a canvas wrapper
canvas = new Canvas();
canvas.build();
canvas.width(500);
canvas.height(500);
document.getElementById('canvasHolder').appendChild(canvas.element);

//creating a base level display object
dp = new CanvasDisplayObject();
dp.build();
dp.style.width(20);
dp.style.height(20);
dp.style.x(20);
dp.style.y(20);
dp.style.backgroundColor('#f00');
canvas.appendChild(dp);


//create a circle
circle = new Sprite();
circle.beginFill('#A8CD1B', 0.5);
circle.drawCircle(0, 0, 40);
canvas.appendChild(circle);

//set style properties
circle.style.opacity(0.8)'
circle.style.rotate(45);


#API

Canvas Renderer API

#Examples

Bar Chart with Animation
Event Listeners
Canvas Animations
Using the Sprite Object

canvasrenderer's People

Contributors

fchowdhury-oo avatar

Stargazers

Fahim Chowdhury avatar

Watchers

Fahim Chowdhury avatar  avatar

canvasrenderer's Issues

TextField Creates a border

when a textfield is added as the first child it adds a white border.

Example:

this.label = new TextField();
    this.label.build();
    this.label.text("PRICE");
    this.label.style.rotate(-90);
    //this.label.style.font('12px Arial #FFFFFF');
    //this.label.color('#FFFFFF');
    this.appendChild(this.label);

    //draw horizontal line
    this.hLine=new Sprite();
    this.hLine.moveTo(this.hLinePadding,this.style.height()-this.hLinePadding);
    this.hLine.lineTo(this.style.width()-(this.hLinePadding * 2),this.style.height()-this.hLinePadding);
    this.hLine.style.lineWidth(2);
    this.hLine.style.strokeStyle("#FFF");

    this.appendChild(this.hLine);

    //draw vertical line
    this.vLine=new Sprite();
    this.vLine.moveTo(this.vLinePadding,this.style.height()-this.vLinePadding);
    this.vLine.lineTo(this.vLinePadding,this.vLinePadding);
    this.vLine.style.lineWidth(2);
    this.vLine.style.strokeStyle("#FFF");

    this.appendChild(this.vLine);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.