Git Product home page Git Product logo

ncl.js's Introduction

NCL.js

NylCanvasLibrary (NCL) is a lightweight toolbox to make canvas animations

N.B: Examples are old and a little messy. I know about that. I'll prepare some new examples soon :)

Features

  • Use requestAnimationFrame API when possible, if not, a setInterval.
  • Provide helpers and function chaining to draw with canvas
  • Plugin architecture
  • Mouse and touch events handled in plugins
  • ... Well, there's probably more, but the doc is coming. Please be patient and look up the code until the doc release :)

Getting started

1) Create a "plugin" function

function MyNclPlugin() {

	//Setup is used to init variables before the loop render begins
	this.setup = function()
	{
	    this.position = new NCLVector2(this.NCL.mouseX, this.NCL.mouseY);
	    this.size = 20;

	};
	
	//The (infinite) loop render. You can draw here
	this.draw = function(scene)
	{
	
		this.NCL.clear();

		this.NCL.colorShape('cyan')
				.colorBorder('red')
				.square(this.position, this.size);
				
		  this.position.setX(this.NCL.mouseX);
		  this.position.setY(this.NCL.mouseY);
	}
}

2) In your HTML, create an empty div with an id

	<div id="myanimation"></div>
	

2) Load the library and hook your function

	var NCL = new NylCanvasLibrary("myanimation",800,600,"canvaselementid",60);
	
	//load the plugin
	NCL.loadPlugin(new MyNclPlugin(NCL));
	NCL.setFullscreen(false);
	NCL.init();
	

API References

Doc is under writing and is not complete for now. Please be patient

Render functions

###Shapes

Function Arguments Description
NCL.square(startVector,size) startVector : NCLVector2
size : number
Draw a square
NCL.rect(startVector,width,height) startVector : NCLVector2
width : number
height : number
Draw a rectangle
NCL.line(startVector, endVector) startVector : NCLVector2
endVector : NCLVector2
Draw a line
NCL.circle(radius,position) radius : number
position : NCLVector2
Draw a circle
NCL.triangle(v1,v2,v3) v1 : NCLVector2
v2 : NCLVector2
v3 : NCLVector2
Draw a triangle
NCL.curve(start, end, center) start : NCLVector2
end : NCLVector2
center : NCLVector2
Draw a curve

###Others

Function Arguments Description
NCL.text(text, font, position, align) text : string
font : string (See Canvas Doc)
position : NCLVector2
align: string
Draw a text

###Utils

Function Arguments Description
NCL.clear() none Clear the screen
NCL.pointRotate(radians, position) radians : float
position : NCLVector2
Rotate the context around a point
NCL.save() none Save the context
NCL.restore() none Restore the previously saved context

More details and doc to come ! (But the code is documented)

ncl.js's People

Contributors

nyl000 avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

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.