npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

canvas-paint

v0.1.1

Published

Helper functions for drawing onto <canvas> elements

Downloads

7

Readme

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

  • [x] 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