Giter Club home page Giter Club logo

graphics2d's Introduction

Graphics2D JavaScript Library

Note: Graphics2D 2.0 will be renamed to DeltaJS.

Graphics2D is a javascript library available under the MIT License.

Install with bower

bower install graphics2d

Or use as a script

Just download graphics2d.min.js, put into your project folder and attach to your page:

<script src="./js/graphics2d.min.js"></script>

Then use

<canvas id="cnv" width="600" height="400"></canvas>
var ctx = Delta.query('#cnv');

// draw a red rect
ctx.rect({
    x: 100,
    y: 100,
    width: 50,
    height: 50,
    fill: 'red'
});

Documentation

Russian

English

Examples

Sandbox

graphics2d's People

Contributors

gitter-badger avatar keyten avatar keytomath avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

graphics2d's Issues

Native size for image

var image = ctx.image(im, x, y, width, 'native');
// ==
var image = ctx.image(im, x, y, width, im.height);

Shape bounds: transform, stroke...

var text = ctx.text( 'Hello, world', x, y, fill ),
    b = text.bounds({ transform: true / false (default - true), stroke: true / false / 'exclude' (default - false) });
b.ltx, rtx, lbx, rbx, lty, rty, lby, rby // -- corners of the transformed shape
b.x1, y1, x2, y2, width, height // -- corners of the transformed shape bounds

More curves & curves utils

  1. More curves (Catmull-Rom, BSplines, Lagrange approx poly, bezier of custom power). Including relative and shorthand curves.

  2. Curves utils.

  3. Path utils based on curves utils.

  4. Special utils for bezier (& catmull based on converting to bezier).

  5. Possibly, bezier curves with weight of points?

Benchmarks

Todo: test what variation is faster
And use it everywhere in the lib.

Priority: webkit, firefox, edge.

  1. Checking the property existence: hasOwnProperty, prop in obj, obj[prop] !== undefined.

The list is to update.

Abstract shapes

var rect = Graphics2D.rect(10, 10, 200, 200);
ctx.push(rect);

Finish the Core

The current idea:

DeltaJS (Graphics2D 2.0) will include:

  • Core
  • More
  • Physics
  • Geometry
  • WebGL

Image filling

var tex = new Image;
tex.src = 'http://url';
ctx.rect(10, 10, 200, 200, tex);
// ==
ctx.rect(10, 10, 200, 200, 'http://url');

Test drawing in reverse order with composite

How about drawing all the objects with dest-over composite in reverse order?

It will break all the composites and maybe opacity, but it may be very faster (the browser doesn't have to calculate the pixels behind other obs).

Shape::corner

Move the util.corner function to Shape class.

Add offsets:

shape.corner({
 from: 'top left',
 x: 10
});

Note: the corner function is using in the transforms and gradients.

FillRule for paths

Algo:

  1. Stroke the path.
  2. Divide the path to even & odd parts.
  3. Fill them or not.
    (maybe, custom functions deciding whether the part must be filled)

Two transform modes

  1. free: there's a matrix and the methods scale, rotate, skew, translate, transform change it with any pivot.
  2. strict: the matrix is generated from scale, rotate, skew, translate attrs with scalePivot, rotatePivot, skewPivot.

The matrix is in transform attr.

To think about: abstract position

Position of the element do not have to be cartesian coords always.
Now:

ctx.rect(x, y, width, height, fill, stroke);

To think about:

// polar coords
ctx.rect({ angle: 90, length: 50 }, width, height, fill, stroke);
// in-hex-engine coords
var hexEngine = ...
ctx.rect({ engine: hexEngine, r: 0, g: 0, b: 0 }, width, height, fill, stroke);
// maybe table-like, row-like, col-like, flex-line engines? with margins, paddings and etc

in Delta.More ofc.

It is neccessary to find out is v8 able to optimize functions passing arguments ob to another function. And think when is it neccessary to convert coords when init.
Maybe additional predraw function for calculating position?

Multiple binds

shape.on({
 click: listener1,
 mouseover: listener2
});

Shape::events

Make possible to enable / disable mouse processing for a shape.

shape.events(false);

Bug with bounds on rasterizing

ctx.rect(100, 100, 100, 100, {
    colors: ['red', 'green', 'blue'],
    from: 'top',
    to: 'bottom'
}).rotate(45).remove().rasterize();

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.