Giter Site home page Giter Site logo

objectivecanvas.js's Introduction

ObjectiveCanvas.js

To use <canvas> in an objective way.

What's ObjectiveCanvas.js ?

It defines some constructors which you can use to create objects and draw them on <canvas>.

Some constructors:

  • OC.Object
  • OC.Shape
  • OC.Rect
  • OC.RoundRect
  • OC.Circle
  • OC.Arc
  • OC.Star
  • OC.Text
  • OC.Line
  • OC.Polygon
  • OC.Sprite
  • OC.TextGroup

How to use them ?

  1. Get an instance
  2. Set properties (position, transform, color, shadow, clip...)
  3. Draw it on <canvas>

Example:

<!DOCTYPE html>
<html>

<head>
    <title>ObjectiveCanvas.js</title>
    <!-- Load OC(.min).js -->
    <script src="OC.min.js"></script>
</head>

<body>
    <canvas id="canvas"></canvas>
    <script>

        var canvas = document.querySelector('#canvas'),
            ctx = canvas.getContext('2d'),
            circle = new OC.Circle(); // create a circle

        /* set position */
        circle.setX(100);
        circle.setY(100);
        // equals to circle.setPos(100, 100);

        /* set color */
        circle.setFillStyle('#ff0');
        circle.setStrokeStyle('#f00');

        /* draw */
        circle.draw(ctx);
        // You can also set OC.defaultContext
        // and just write: xxx.draw();

    </script>
</body>

</html>

OC.Object.prototype.set(obj)

You can use this method to set properties of an object by giving an object.

Example:

circle.set({
    lineWidth: 2,
    shadowColor: 'rgba(0,0,0,.5)',
    shadowBlur: 10
});

OC.parse(str)

This method enable you to get canvas objects from json strings.

Example:

var rect = OC.parse('{ "constructor": "Rect", "x": 100, "y": 100, "w": 200, "h": 200, "fillStyle": "#00f" }');

Try it !

objectivecanvas.js's People

Contributors

huang2002 avatar

Stargazers

 avatar  avatar

Watchers

 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.