Git Product home page Git Product logo

pencil.js's Introduction

Pencil.js logo

✏️ Pencil.js

NPM Version Vulnerability Maintainability Test Coverage

Nice modular interactive 2D drawing library.

Installation

You can install Pencil.js with the following command :

npm install pencil.js

On capable browsers, the easiest way is to import the ESM package.

<script type="module">
    import { Scene } from "https://unpkg.com/pencil.js/dist/pencil.esm.js";
    
    const scene = new Scene();
</script>

If you want to go old-school, you can fetch the script with unpkg or jsdelivr.

<script src="https://unpkg.com/pencil.js"></script>
<!-- or -->
<script src="https://cdn.jsdelivr.net/npm/pencil.js"></script>

<script>
    const scene = new Pencil.Scene();
</script>

Usage

Once you have installed the library using NPM, you can start to import it.

You can either import everything under a namespace or only the package you're going to use. Pick the way that fit your style.

// The whole package under a namespace
import Pencil from "pencil.js";

const scene = new Pencil.scene();

/***/

// Just the part you need (recommended)
import { Scene } from "pencil.js";

const scene = new Scene();

In that case, you will need to use a bundler like webpack or browserify.

Documentation

The official documentation Vercel logo.

What Pencil.js do best

Abstraction

Drawing in a canvas is not trivial. First of all, the goal is to ease the use of canvas in a browser; allowing anyone to use it with its comprehensible syntax and extensible options.

OOP

OOP is great, OOP is almighty, OOP saves lives ! Others library exists, but none with a beautiful OOP syntax. It makes code look natural.

Modularity

Splitting the whole code into modules make everything cleaner. It also allows you to grab only what you need or replace what you don't like.

Documentation

A complete documentation goes a long way to help developers. All functions are assured to have a description and typed arguments and returns.

Performance

Pencil.js is able to draw thousands of shapes pretty smoothly without tanking your memory. Even more if you use the Particles generator.

Size

With Package size, Pencil.js is fairly lightweight. Furthermore, with no side effect, it's fully tree-shakable. So, any decent bundler can further reduce its footprint.

Examples

import { Scene, Rectangle } from "pencil.js";

const scene = new Scene(); // create a new scene

const position = [100, 200];
const width = 80;
const height = 50;
const options = {
    fill: "red",
};
const rectangle = new Rectangle(position, width, height, options); // Create a new red rectangle
scene.add(rectangle); // Add the rectangle to the scene

scene.render(); // Render the scene once

Take a look at more advanced examples.

Modules

Core modules

Core modules refer to all classes and methods you'll get within Pencil.js library.

Non-core modules

Non-core modules refer to packages made by us and not part of Pencil.js library. We find them useful, so maybe you will too...

  • spritesheet (CLI)
    Pack a set of images into a single spritesheet along its json description file.
  • vue-pencil.js
    Build reactive 2D graphics scene in your Vue project.
  • gif
    Turn any Pencil.js scene into an animated GIF.
  • text-direction
    Gives the rendering text direction (left to right or right to left) of a node.
  • test-environment
    Set a Node.js environment suitable for testing Pencil.js and Pencil.js applications.
  • canvas-gif-encoder
    Create a GIF stream frame by frame from a canvas rendering context.

Who is using Pencil.js ?

Take a tour of all the awesome project using Pencil.js.

Enterprises

We are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.

Contributions

You want to help us improve ? Please read the contributing manual.

Contributors

Guillaume Martigny avatar
Guillaume Martigny
Heraclite avatar
Heraclite
Zachary Nguyen avatar
Zachary Nguyen
Christian Paul avatar
Christian Paul
Rémi Marche avatar
Rémi Marche
Parsa avatar
Parsa

All contributions are valued, you can add yourself to this list (or request to be) whatever your contribution is.

License

MIT

pencil.js's People

Contributors

angelmunoz avatar code418 avatar curedbylethe avatar ecstrema avatar gmartigny avatar greenkeeper[bot] avatar jaller94 avatar zachary-nguyen 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar

pencil.js's Issues

Drop the use of stable sort dependency

Since Chrome v70, all major browsers sort algorithm is stable. So, when this version is more widespread, we can drop the stable dependency from @pencil.js/container module.

Fully node compatible

As an abstract renderer, Pencil.js could be run in node. However, there's still browser dependencies (Path2D, FontFace, CSS ...) that should be dealt with.

In the end, Pencil.js could generated images out of the browser context with the help of https://www.npmjs.com/package/canvas for example.

Add mono select input

Add mono-select input. Should work like <select> or <input type="radio">, but could be better designed.

Solution Pros Cons
Drop-down Compact Should handle overflow/scroll and complex
Radial Smart and fun Limited number of items
Radio Display every options How to group them ?

Resizable should be compatible with rotation

Information

  • Your current navigator: whatever
  • The package and version you used: @pencil.js/[email protected]

Description

An error is thrown when the user tries to make a rotated rectangle resizable. This is expected as it's not possible to directly compare x and y position to compute width and height.
A bit of trigonometry should do the trick with something along the line of:

this.width = diffX * Math.cos(this.options.rotation * 2 * PI) +
	diffY * Math.sin(this.options.rotation * 2 * PI);

Reproduce by

const rect = new Rectangle([0, 0], 100, 200, {
	rotation: 1 / 8,
});
rect.resizable();

An in-range update of lerna is breaking the build 🚨

Version 3.3.1 of lerna was just published.

Branch Build failing 🚨
Dependency lerna
Current Version 3.3.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

lerna is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes v3.3.1

Bug Fixes

  • create: Upgrade whatwg-url to ^7.0.0 (00842d6)
  • import: Handle filepaths with spaces more robustly (#1655) (b084293)
  • prompt: Upgrade inquirer to ^6.2.0 (ebb7ee4)
  • publish: Tell yarn to stop creating git tags (2a6f0a4), closes #1662
  • run-lifecycle: Remove repetitive error logging (b8915e7)
Commits

The new version differs by 13 commits.

  • 5da1319 chore(release): publish v3.3.1
  • 367bf4e test(integration): Avoid inexplicable snapshot comparison errors on Windows
  • 5880788 test(helpers): Replace normalize-test-root with augmented placeholder serialization
  • ed16536 test(helpers): Make serialize-tempdir placeholder consistent with normalize-test-root
  • 00842d6 fix(create): Upgrade whatwg-url to ^7.0.0
  • ebb7ee4 fix(prompt): Upgrade inquirer to ^6.2.0
  • b8d11b8 chore(deps): Update eslint + jest
  • 7bd3179 chore: flailing around trying avoid 'no visual difference' snapshot garbage on Windows
  • b8915e7 fix(run-lifecycle): Remove repetitive error logging
  • a379266 chore(helpers): Normalize newlines to coddle windows
  • 2a6f0a4 fix(publish): Tell yarn to stop creating git tags
  • ac0baa7 test(integration): avoid quoting arguments to coddle windows
  • b084293 fix(import): Handle filepaths with spaces more robustly (#1655)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Should Line/Polygon/Path points be absolute or relative to position ?

Points of a Line object have absolute position. That way, in order to draw a polygon between 3 shapes, it's easy to write:

const line = new Polygon([
	shape1.position,
	shape2.position,
	shape3.position,
]);

This means that moving one position don't change the others.

In the other hand, relative position could allow to move the polygon position and keep the polygon shape.

An in-range update of babel7 is breaking the build 🚨

Version 7.0.1 of the babel7 packages was just published.

Branch Build failing 🚨
Monorepo release group babel7
Current Version 7.0.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

This monorepo update includes releases of one or more dependencies which all belong to the babel7 group definition.

babel7 is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Text cached measures should be share across instances

In Text class, the _cachedMeasures prevents re-computing measures each times when text hasn't changed.

It could be a slight improvement to share this cache across all Text instances. Getters and setters should exist through a Text static property.

It's not important for the user to access the cache, but it should be possible to:

  • Add new value
  • Read value
  • Remove (all) value(s)

IsHover function is incompatible with scale option

Information

  • Your current navigator: Chrome v77
  • The package and version you used: @pencil.js/component v1.12.0

Description

When a component has a scale option different from the default [1, 1] the function isHover is not working properly. The detection just don't take the scaling into account and consider the component still at its original size.

It would probably be better to make a setContext function in Container class. This function would be in charge of clip, rotation and scale (instead of doing that in render).
Then, it might be possible to lean on isPointInPath with the right context. It means that the manual rotation of position would not be needed anymore.

Reproduce by

const square = new Square(scene.center, 400, {
	scale: [0.5, 0.5],
});
square.on("hover", () => console.log("hover"));
scene.add(square).startLoop();

Slider is not compatible with rotation

Information

  • Your current navigator: whatever
  • The package and version you used: @pencil.js/[email protected]

Description

Similarly to #55, Slider rely on difference of mouse position across the x axis. But once rotated, the Component and browser axis don't match up.
Slider handle is a simple draggable component. It'll be hard to hack the draggable constrain option to work with rotation.

Reproduce by

const slider = new P.Slider(scene.center, {
	rotation: 1 / 8,
});

Images are drawn on top of their children

Infos

Your current navigator: Chrome v66
The package you used: @pencil.js/image

Description

Regardless of the z-index of its children, Image are drawn on top.

It's caused by the override of the render function in Image module.
However, drawImage is not on Path2D prototype and can't be called on trace. (like it should be)

Reproduce by

const img = new Image([], "url");
img.on("load", () => {
	img.add(new Rectangle([], img.width, img.height);
	scene.add(img).render();
});

Draggable cursor not correctly updated

Information

  • Your current navigator: Chrome v73
  • The package and version you used: @pencil.js/draggable v1.6.3

Description

When setting a component draggable, the cursor option change to "grab" => ok. But when the component is actively dragged, the cursor should change to "grabbing" => ko.
The Scene setCursor function seems not to be called with the updated option.

Reproduce by

const square = new Square(scene.center, 200);
square.draggable();
scene.add(square);

Grabbing the square doesn't update the cursor.

Should component have an origin option ?

At the beginning, I wanted to change the "position" of rectangle. For example, the user could specify the bottom-right corner as origin.

Then, I wonder about allowing this behavior for all components. But it gets confusing really fast and moreover broke rotations.

Should Pencil.js have an origin option on Component to move the shape drawing relative to its position ?

How is it suppose to interact with rotations and rotation anchor ?

An in-range update of webpack is breaking the build 🚨

Version 4.18.0 of webpack was just published.

Branch Build failing 🚨
Dependency webpack
Current Version 4.17.3
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

webpack is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes v4.18.0

Features

  • Upgrade webassemblyjs dependency
Commits

The new version differs by 12 commits.

  • ee7d948 4.18.0
  • de85978 Merge pull request #7732 from xtuc/chore-bump-webassemblyjs11
  • 4e02cac chore: bump webassemblyjs
  • 52e1630 bump webassemblyjs
  • e0e0061 Merge branch 'master' into chore-bump-webassemblyjs11
  • c9d6ec1 feat: remove wasm-opt
  • 075208d fix: merging
  • 38c3403 Merge remote-tracking branch 'upstream/master' into chore-bump-webassemblyjs11
  • 8214d56 chore: bump webassemblyjs
  • 59114c1 chore: bump webassemblyjs
  • b310b9b feat: remove LEB128 opt
  • f744c4a chore: bump webassemblyjs 1.6.0

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

getAbsolutePosition don't work with rotation

Infos

Your current navigator: Chrome v65
The package you used: @pencil.js/container

Description

The function getAbsolutePosition returns wrong position when the container is nested inside another with a rotation.

Reproduce by

const parent = new Container([0, 0], {
  rotation: 0.5,
});
const child = new Container([10, 10]);
parent.add(child);

child.getAbsolutePosition(); // => fail

Change max values for Slider and Knob

In current version (v1.13.0) Slider and Knob input have a default options max value of 10. This doesn't really make sense.

All Pencil.js works with value between 0 and 1 except those.

Fixing this should only require to change the value in the defaultOptions static function. But both component should be manually tested (using drawingTests folder) to be sure.

Add path drawing tool

Adding shape with a single class instantiation is nice, but sometimes you could want more in-depth drawing.

Could be a declarative set of rules

// Easy to read but blotted
const startingPoint = new Position();
new Shape(startingPoint, [
	Shape.lineTo(position),
	Shape.arcTo(position, center),
	Shape.quadTo(position, controlPoint),
	Shape.bezierTo(position, controlPoints),
], options);

Or a set of code like SVG

// Clean but hard to read
const startingPoint = new Position();
new Shape(startingPoint, "M 20 230 Q 40 205, 50 230 T 90230", options);

Rename Vector to Segment

Vector should be a direction and a amplitude. Two Positions better represent a segment.
In a second time, a real vector implementation should be done.

Images without fill option can't be hovered

Information

Description

The Component's isHover function returns true only if the Component is either filled or stroked. Image can be drawn without neither of these and are not detected as hovered.

As with malePath, maybe Image need its own duplication of isHover to account for this.

May be fixed by a refacto when doing #67.

Reproduce by

const img = new P.Image(scene.center, "url.png", {
    fill: "white", // <- The image can't be hovered without this
});
img.on("ready", () => scene.add(img).render())
    .on("hover", console.log("Hover"));

Polish the Heart component

Information

  • The package and version you used: @pencil.js/polygon v1.11.0

Description

A few things was missing from the first implementation of the Heart component.

  • The trace function doesn't take into account the heart position (this.position)
  • The radius is not representative of the actual radius.
  • The static from function is missing
  • Missing link in the main Pencil.js readme.md

Reproduce by

// The heart won't be at the center neither will have a radius of 100px
const heart = new Heart(scene.center, 100, {
	fill: "red",
});
// missing function
const clone = Heart.from(heart.toJSON());

Find a good documentation generator

Low level documentation could be generated from jsDoc. We need to find a good module able to handle this for each sub-packages.
Generated documentation should be easily readable, display all informations present in jsDoc and have links to other files (for types for example).

PS: High level documentation ("readme", "first steps", "changelog" ...) should still be written by hand.

Draggable is not compatible with rotation

Information

  • Your current navigator: Chrome v76
  • The package and version you used: @pencil.js/[email protected]

Description

When a component is rotated (by itself or any of its parents) the draggable package will produce unexpected result. This impact other package like resizable and Slider that use draggable and prevent them to work when rotated.

A solution might be to climb the component ancestry to compute its absolute rotation and act accordingly in draggable.js.

Reproduce by

const circle = new Circle(scene.center, 200, {
    rotation: 0.25,
    fill: "red",
});

const square = new Square(undefined, 200);
square.draggable();
circle.add(square);

scene.add(circle);

Z-index flickering

Infos

Your current navigator: Chrome v65
The package you used: @pencil.js/container

Description

The z-index sorting of children in a container sometimes change order.

This induce shapes to quickly move over and under each others and flicker.

Reproduce by

Don't find code that reproduce 100%, but a bunch of shapes with the same z-index (1) can d it.

Only render dirty part of the scene

It could be a huge performance boost to only render part of the scene that need to be redrawn.
The scene could be split into an arbitrary number of parts (3x3 ...) and component should "dirty" the part their into.
Alternatively, component can return informations on their bounding box (AABB). Then scene only redraw the union of all AABB. (see below comment)

Multi-line texts

Add the possibility to have multi-lined texts.

Instead of many Text, the user could just passed an array of string to one Text to have multi-lines.

The CanvasRenderingContext2D API doesn't support multi-line, so it should be a "housemade" solution based on measureText.

This also impact Text.prototype.getMeasures.

Examples

new Text(position, ["First line", "second line"]);
new Text(position, "First line\nsecond line");
new Text(position, `First line
second line`);

Update weback to v4

Webpack has got a major update to v4.

We should update, but it seams to mean some changes on the webpack.config.js

An in-range update of webpack is breaking the build 🚨

Version 4.12.2 of webpack was just published.

Branch Build failing 🚨
Dependency [webpack](https://github.com/webpack/webpack)
Current Version 4.12.1
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

webpack is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details

Release Notes v4.12.2

Bugfixes

  • fix crash when using invalid JSON with HMR
  • fix missing modules when a side-effect-free package is root of module concatenation
  • update chunkhash when entry-chunks list or prefetched chunks change
Commits

The new version differs by 19 commits.

There are 19 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of @gmartigny/eslint-config is breaking the build 🚨

Version 1.2.0 of @gmartigny/eslint-config was just published.

Branch Build failing 🚨
Dependency @gmartigny/eslint-config
Current Version 1.1.2
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

@gmartigny/eslint-config is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Detection of points inside polygon doesn't work

Infos

Your current navigator: Chrome v65
The package you used: @pencil.js/polygon

Description

The ishover method always return false.
It use the Ray casting algorythm using Vector class.
But according to test Vector.prototype.intersect is working.

Reproduce by

const poly = new Polygon(points, {
	cursor: "crosshair", // The cursor will never change
});

An in-range update of @gmartigny/eslint-config is breaking the build 🚨

Version 1.2.1 of @gmartigny/eslint-config was just published.

Branch Build failing 🚨
Dependency @gmartigny/eslint-config
Current Version 1.2.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

@gmartigny/eslint-config is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details

Commits

The new version differs by 2 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Tests for all sub-packages

All packages should have their own tests.

  • Arc
  • BaseEvent
  • Button
  • Checkbox
  • Circle
  • Component
  • Container
  • draggable()
  • EventEmitter
  • Image
  • Input
  • KeyboardEvent
  • Line
  • Math
  • MouseEvent
  • NetworkEvent
  • OffscreenCanvas
  • Path
  • Polygon
  • Position
  • Rectangle
  • RegularPolygon
  • resizable()
  • Scene
  • Select
  • Slider
  • Spline
  • Square
  • Star
  • Text
  • Triangle
  • Vector

Add color manager

Would be great to have a comprehensive, easy to use color manager.

Maybe a wrapper around Qix-color

## Need

  • OOP syntax
  • Clean and straightforwards
  • Documented

Should Line points be relative or absolute ?

The question was settled in #18, but I wanted to re-open the debate for the Line class here.

I often find myself wanting to draw a line between two moving shape in a scene (absolute positions). If the shapes are moving and the line is not keeping reference to these positions, it's not possible without using absolute positions.

In the other hand, being able to move the Line as a whole (with dra'n'drop or programatically) makes more sense. Moreover, Pencil.js is build around relative positions and they're used everywhere else.

Relative over absolute positions
Pros:

  • All points follow the main position
    • Is possible to do drag'n'drop
  • It's the standard in Pencil
  • Changing impact at least Line, Spline and Path
    Cons:
  • Who need to drag'n'drop a line ??
  • Can't draw line between moving shapes
  • Absolute is more straightforward

Any opinion on that ?

Design of gh-page

The main page is hosted on github via the gh-pages branch and it seriously need some love.

The content is pretty much ok, but the look is awful.

Open to suggestion.

Documentations and readme

Every classes and every functions should have a jsDoc documentation.
Moreover, all modules should have a readme.md and a documentation.md.

I'm not a great writer, so someone else should check all texts for misspelling or incoherence.

Use c8 for code coverage

Since node 10.10.0, code coverage is natively supported. The c8 package use this new feature and report a ~300% performance improvement.
Once this feature has live a little and node is more widely used, we should use it instead of nyc.

Text has no baseline options

Information

  • Your current navigator: Chrome v77
  • The package and version you used: @pencil.js/text v1.12.0

Description

It's not currently possible to change the baseline of texts. A new option would be great.
It would be an enum, much like the align option. With "top", "middle" and "bottom" for a start.
Should we can call it baseline ?

Specs

Reproduce by

// This text is not center on screen :/
const text = new Text(scene.center, "Hello\nWorld", {
	align: "center",
});

Add sprite manager

Description

A recurring use-case for drawing engine like Pencil.js is to display sprite. Sprites are a large image composed of other images, the point is to go through them to create the illusion of movement (ex)
Mostly used in games, a sprite must have an image and the metadata for each position in that image.
As far as I know, there's no standard, but we should be able to read from JSON output of popular image packers (TexturePacker, ShoeBox, Spritesheet.js ...)

Example

// Will preload the json and the meta texture
const sheet = new SpriteSheet("sheet.json");

// Return all corresponding data
const array = sheet.get(globPattern);
// Create the component
const sprite = new Sprite(position, array, {
	loop: true, // default, should the animation start over when done
	speed: 1, // default, number of animation frame per scene frame
});
const sheet = new SpriteSheet("sheet.json");

// Define states
const object = {
	state1: sheet.get(globPattern1),
	state2: sheet.get(globPattern2),
};
const sprite = new Sprite(position, object);
// Change the sprite state (default to the first)
sprite.setState("state1");
const sheet = new SpriteSheet("sheet.json");

const sprite = new Sprite(position, sheet.get(globPattern1), {
	loop: false,
});
// Set of event
sprite.on("animation-start", () => sprite.show());
sprite.on("animation-frame", () => {});
sprite.on("animation-end", () => sprite.hide());
// Set of playback methods
sprite.play();
sprite.pause();
sprite.setFrame(0);

Add ellipse

Ellipses are one of the most common shape and it's easy to draw in canvas.

However, I don't know how it should integrate in the current dependency tree.

Current tree:

  • Component
    • Arc
      • Circle

Possible solutions:

  1. Split arcs and full ellipses
  • Component
    • EllipseArc
      • CircleArc
    • Ellipse
      • Circle
  1. Add another branch
  • Component
    • EllipseArc
      • Ellipse
    • Arc
      • Circle

(1) IMO, arcs (ellipse or circle) should be treated by default as stroke (like lines and paths). Which mean that they could even inherit from Line.

(2) In the other hand, circle is just a specific arc (just as square is a specific rectangle) as much as a specific ellipse. Since double inheritance is impossible in JS, it's not an option.

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.