All Projects → semibran → canvas-paint

semibran / canvas-paint

Licence: MIT license
🎨 helper functions for drawing onto <canvas> elements

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to canvas-paint

Flutter Canvas
About using of canvas in the flutter
Stars: ✭ 259 (+1338.89%)
Mutual labels:  paint, draw
Doodle
Image doodle for Android, with functions such as undo, zoom, move, text, image, etc. Also a powerful, customizable and extensible doodle framework & multi-function drawing board. Android图片涂鸦,具有撤消,缩放,移动,添加文字,贴图等功能。还是一个功能强大,可自定义和可扩展的涂鸦框架、多功能画板。
Stars: ✭ 809 (+4394.44%)
Mutual labels:  paint, draw
gridder
A Grid based 2D Graphics library
Stars: ✭ 51 (+183.33%)
Mutual labels:  paint, draw
Drawing
Drawing and fill color
Stars: ✭ 37 (+105.56%)
Mutual labels:  paint, draw
Pixelorama
A free & open-source 2D sprite editor, made with the Godot Engine! Available on Windows, Linux, macOS and the Web!
Stars: ✭ 2,535 (+13983.33%)
Mutual labels:  paint, draw
Mopaint
🎨💪 Modern, modular paint and more! (pre-alpha, not much done yet)
Stars: ✭ 50 (+177.78%)
Mutual labels:  paint, draw
React Sketch
Sketch Tool for React-based applications, backed up by FabricJS
Stars: ✭ 414 (+2200%)
Mutual labels:  paint, draw
leaflet-paintpolygon
Leaflet plugin to create polygon with circle as paint
Stars: ✭ 38 (+111.11%)
Mutual labels:  paint, draw
Sketchpad
Sketchpad is fully customisable collaborative whiteboard plugin written in pure JavaScript.
Stars: ✭ 85 (+372.22%)
Mutual labels:  paint, draw
Touchable
Flutter library to add gestures and animations to each Shape you draw on your canvas in your CustomPainter
Stars: ✭ 82 (+355.56%)
Mutual labels:  paint, draw
Sketch
Sketch have a lot of basic functions to develop a drawing app for iPhone. Anyone can easily create drawing iOS Application.
Stars: ✭ 229 (+1172.22%)
Mutual labels:  paint, draw
powerpaint
Kreative PowerPaint - Library and Application for Bitmap and Vector Image Editing
Stars: ✭ 27 (+50%)
Mutual labels:  paint, draw
DrawContainerDemo
作业盒子批注控件反编译
Stars: ✭ 17 (-5.56%)
Mutual labels:  draw
core
Renderer for tldraw and maybe you, too.
Stars: ✭ 418 (+2222.22%)
Mutual labels:  draw
GnuPlot
A PHP Library for using GnuPlot
Stars: ✭ 26 (+44.44%)
Mutual labels:  draw
android-3d-model-viewer
Android app to load 3D models in obj, stl, dae & gltf format using pure OpenGL ES 2.0. Published on Play Store https://play.google.com/store/apps/details?id=org.andresoviedo.dddmodel2
Stars: ✭ 150 (+733.33%)
Mutual labels:  draw
ti.paint
Touch-based painting with the Titanium SDK.
Stars: ✭ 27 (+50%)
Mutual labels:  paint
Webcam Paint OpenCV
This Python application uses OpenCV library to track an object-of-interest (water bottle cap in my case) and uses the detected object to draw colored lines (Blue, Green, Red and Yellow).
Stars: ✭ 66 (+266.67%)
Mutual labels:  paint
drawim
A simple drawing library in Nim, inspired by p5js
Stars: ✭ 66 (+266.67%)
Mutual labels:  draw
vscode-luna-paint
A raster image editor extension for VS Code
Stars: ✭ 235 (+1205.56%)
Mutual labels:  paint

canvas-paint

Helper functions for drawing onto <canvas> elements

install

npm install canvas-paint

usage

const paint = require('canvas-paint')

fill(canvas, color)

Fills the entire canvas with color.

fill(canvas, 'black')

clear(canvas, rect?)

Clears the region on canvas as specified by rect.

clear(canvas, {
  x: canvas.height / 4,
  y: canvas.height / 4,
  width: canvas.width / 2,
  height: canvas.height / 2
})

If rect is not provided, the entire canvas will be cleared.

rect(canvas, options)

rect(canvas, {
  x: 50,
  y: 25,
  width: 100,
  height: 50,
  fill: 'red'
})

circle(canvas, options)

circle(canvas, {
  x: canvas.width / 2,
  y: canvas.height / 2,
  radius: 32,
  stroke: {
    color: 'blue',
    width: 2
  }
})

arc(canvas, options)

arc(canvas, {
  x: canvas.width / 2,
  y: canvas.height / 2,
  radius: 48,
  start: 120,
  end: 60,
  fill: 'yellow'
})

The above code draws the following image:

arc example

Note that start and end are provided in angles instead of radians. Also, the anticlockwise parameter has been omitted. The values for start and end can be switched in order to achieve the same result.

line(canvas, options)

line(canvas, {
  start: { x: 50, y: 25 },
  end: { x: 125, y: 5 },
  stroke: {
    color: 'black',
    width: 2
  }
})

polygon(canvas, options)

Draws a polygon onto canvas.

polygon(canvas, {
  points: [
    { x: 64, y: 16 },
    { x: 112, y: 64 },
    { x: 64, y: 112 },
    { x: 16, y: 64 }
  ],
  fill: 'red'
})

The above code draws the following image:

polygon example

image(canvas, options)

image(canvas, {
  image: sprites.wall,
  x: 32,
  y: 16,
  width: sprites.wall.width * 2,
  height: sprites.wall.height * 2
})

width and height are optional - they will default to image.width and image.height if not provided.

text(canvas, options)

text(canvas, {
  text: 'Hello world',
  x: canvas.width / 2,
  y: canvas.height / 2,
  align: 'center',
  baseline: 'middle',
  font: {
    size: 48,
    family: 'sans-serif'
  },
  stroke: {
    color: 'blue'
  }
})

The above code draws the following image:

text example

Additionally, a couple of minor changes have been made to the API defaults.

  • font.size defaults to 16
  • align defaults to 'left'
  • baseline defaults to 'top'

to do

  • basic drawing methods
  • make fill/stroke blocks reusable
  • line cap, join, dash
  • shadows
  • gradients
  • compositing
  • masking
  • bezier curves
  • transforms (translation, rotation, scaling)

license

MIT © Brandon Semilla

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].