Socket
Book a DemoInstallSign in
Socket

franim

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

franim

canvas helper library

0.1.0
latest
Source
npmnpm
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

franim NPM version Code Climate

sample html canvas animation loop wrapper

NPM franim

Usage

var wrap = franim('wrapperid', {
    config : {
        resize: true
    },
    setup : function setup(ctx) {
        ctx.fillStyle = "black";
        ctx.fillRect(0,0,this.anim.getWidth(),this.anim.getHeight());
    },
    update : function update(time) {
        this.x = ~~(Math.random()*this.anim.getWidth());
        this.y = ~~(Math.random()*this.anim.getHeight());
    },
    draw : function draw(ctx) {
        ctx.fillStyle = "red";
        ctx.fillRect(this.x, this.y, 1, 1);
    }
});

Table of Contents generated with DocToc

##arguments ###wrapperid Type: String required

the id of canvas wrapper where new canvace elemnt will be appened

###context Type: Object required

object which contains required functions for animation loop

###context.config.resize Type: Boolean Default: false

if true make canvas element resize with its wrapper element

###context.init Type: Function optional it is called once before animation is started and context is passed to it as argument

function setup(ctx)

###context.update Type: Function optional it is called on every frame before draw and AnimationFrame's time argument is passed to it as argument

function update(time)

###context.draw Type: Function required it is called on every frame, after update (if is defined) and context is passed to it as argument

function draw(ctx)

if update is not defined then context is passed to it as a first argument and AnimationFrame's time argument as second argument

function draw(ctx,time)

##this.anim here is api to control animation loop and some helper functions

####this.anim.pause() it cancels Animation Frame and stops loop

####this.anim.resume() it request Animation Frame and starts loop

####this.anim.getHeight() returns height of canvas element

####this.anim.getWidth() returns width of canvas element

####this.anim.getDelta() returns delta time in seconds between frames

example: if you had code like this: x += 1; in your update, after 1 second it will be different depending on frame rate but if you write x += 100*this.anim.getDelta(); it will be changed by 100 after 1 second on any frame rate

License

The MIT License

Copyright (c) 2014, Irakli Safareli

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Keywords

canvas

FAQs

Package last updated on 13 Sep 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.