Giter Site home page Giter Site logo

tunamagur0 / anywhere-paint Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 1.0 6.2 MB

anywhere-paint is a library to create painting apps.

Home Page: https://tunamagur0.github.io/anywhere-paint-sample

License: MIT License

HTML 1.53% TypeScript 95.98% JavaScript 2.49%
draw paint painting-apps typescript typescript-library

anywhere-paint's Introduction

anywhere-paint

Test npm version

anywhere-paint is a library to create painting apps. Sample is here!

DEMO

demo

Installation

npm install --save anywhere-paint

How to use

Create an AnywherePaint obj:

const container = document.getElementById('container'); //The aspect ratio of the container should be equal to the resolution.
const width = 600;  //width resolution
const height = 400; //height resolution
const awPaint = new AnywherePaint(container, width, height);

now you can draw lines.

Create a ColorCircle obj:

const container = document.getElementById('cc-container');  //The aspect ratio of the container should be 1:1
awPaint.createColorCircle(container);

color is automatically picked when you draw lines.

Methods

Undo, Redo

awPaint.undo(): void;
awPaint.redo(): void;

Layers

This library supports layer. You can only draw on selected layer. Unique number is assigned to each layer.

awPaint.addLayer(layerNum?: undefined | number): number;

If no arguments are specified, a new layer is added at the top. Otherwise, a new layer is added on top of the layerNum. Returns unique number which is assigned to new layer.

awPaint.removeLayer(layerNum: number): number | null;

Remove specified layer. Returns newly selected layer number. If there is not any layers, this function returns null.

awPaint.renameLayer(layerNum: number, layerName: string): void;

You can assign layer name to each layer.

awPaint.getLayerNames(): Map<number, string>;

Returns Map<layerNum, layerName>.

awPaint.selectLayer(layerNum: number): void;

Select layer which you want to draw.

awPaint.getLayerImages(): Map<number, string>;

Returns Map<layerNum, DataURI>.

awPaint.getSortOrder(): number[];

Returns an array of layerNum sorted by layer overlap order.

awPaint.setSortOrder(sortOrder: number[]): boolean;

sortOrder is an array which includes layerNums.

Example ) [0, 2, 1]. At this time, 0 is the top and 1 is the buttom.

If argument is valid, layers are sorted by input.

Returns argument is valid or not.

Line

awPaint.setColor(r: number, g: number, b: number): void;

Set line color by r (0-255), g (0-255), b (0-255).

awPaint.setLineWidth(px: number): void;

Set line width(px).

Image

awPaint.getIntegratedImage(): string;

Returns DataURI with a layer-integrated image. (png)

Mode

awPaint.changeMode(style: "Pencil" | "Eraser" | "Fill"): void;

Change drawing mode. style is "Pencil", "Eraser" or "Fill".

History

awPaint.addEventListener(callback: (history: History) => void);

Add callback that will be called when canvas is edited. The parameter of callback is command object of canvas operation. Returns listenerID.

awPaint.removeEventListener(listener: number): void;

Remove eventListener.

awPaint.drawByHistory(history: History): void;

Operate canvas using history.

Properties

awPaint.selectingLayer

layerNum which is selecting.

TypeScript

Write this in tsconfig.json.

{
    "compilerOptions": {
        "moduleResolution": "node",
        "esModuleInterop": true,
    }
}

Lisence

MIT

anywhere-paint's People

Contributors

dependabot[bot] avatar tunamagur0 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

xerz-one

anywhere-paint's Issues

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.