• Stars
    star
    105
  • Rank 328,196 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 10 years ago
  • Updated over 10 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

JavaScript Canvas drawing library for drawing shaky lines and shapes.

shaky

When talking about traditional drawing on paper, many people say, "I can't draw a straight line." But with traditional computer graphics, you can usually ONLY draw straight lines. Let's fix that.

shaky is a Canvas/Context2D wrapper that adds shaky drawing methods. Most of the drawing related methods of Context2D are proxied, either directly, or into shaky version. In addition, there are a few new useful shaky shape drawing methods.

Methods:

setSize(width, height) // sets the size of the canvas
clear() // clears the canvas
beginPath() // straight proxy
stroke() // straight proxy
fill() // straight proxy
rect(x, y, w, h) // draws a shaky rectangle
fillRect(x, y, w, h) // fills a shaky rectangle
clearRect(x, y, w, h) // straight proxy
strokeRect(x, y, w, h) // strokes a shaky rectangle
moveTo(x, y) // moves to a point near the x, y point specified
lineTo(x, y, exactEnd) // draws a shaky line to a point near x, y, or exactly to x, y if exactEnd is true.
arc(x, y, r, start, end) // draws a shaky arc
circle(x, y, r) // draws a shaky circle
fillCircle(x, y, r) // fills a shaky circle
strokeCircle(x, y, r) // strokes a shaky circle
ellipse(x, y, xr, yr) // draws a shaky ellipse with a center of x, y, an x radius of xr and y radius of yr
fillEllipse(x, y, xr, yr) // fills a shaky ellipse
strokeEllipse(x, y, xr, yr) // strokes a shaky ellipse
bezierCurveTo(x1, y1, x2, y2, x3, y3) // draws a shaky bezier curve
quadraticCurveTo(x1, y1, x2, y2) // draws a shaky quadratic curve

Create a shaky instance using:

shaky.create(canvas);

The canvas parameter can be a reference to a canvas object, or the string id of a canvas element on the page.

Properties:

width and height: read the current size of the canvas. use the setSize method to change these.
canvas: a reference to the canvas that this shaky instance is wrapping.
context: a reference to the context2d that this shaky instance is wrapping.
segSize: controls the resolution of this shaky instance, described below.
shake: the shakiness of this shaky instance, described below.

segSize and shake:

segSize controls the resolution of the shaky instance. Say you use lineTo(x, y). Instead of drawing a single line from the current location to the new location, shaky will draw a series of short line segments between the two points. segSize specifies approximately how long those line segments will be. For example, if segSize = 10 and you draw a line from 0, 0, to 0, 100, it will draw 10 line segments, each approximately 10 pixels long. In reality, most will be longer, due to shake.

shake controls the random offset of each point or line segment. shake is a total range so if shake is 10 and you do a moveTo to 100, 100, you will actually wind up moving to somewhere from 95, 95 to 105, 105

Experiment changing both segSize and shake to create a lot of different shaky effects.

Demo images

squares lines arcs circles ellipses quadratic curve bezier curve

This shows the relationship of the segSize and shaky properties. Here, shaky increases left to right, and segSize decreases top to bottom.

segSize and shaky

More Repositories

1

CodingMath

JavaScript
1,125
star
2

quicksettings

JavaScript library for making a quick settings panel to control code parameters.
JavaScript
449
star
3

gifloopcoder

HTML/JS Library/App for coding looping gif animations.
JavaScript
306
star
4

ProjectMaker

A Sublime Text 2/3 plugin to allow creating any kind of project from your own custom templates
Python
233
star
5

grid

A library for drawing various types of grids on HTML5's Canvas.
JavaScript
173
star
6

tones

JavaScript
129
star
7

lab

Daily visual code experiments.
JavaScript
91
star
8

shapes

JavaScript
63
star
9

version

What version do I have of ___?
Shell
45
star
10

clrs

Color lib for HTML/JS. Lots of easy ways to generate colors for use in CSS or Canvas drawing.
JavaScript
34
star
11

wiki_example

30
star
12

minimalcomps2

A Web UI toolkit for creating rapid prototypes, experiments and proof of concept projects.
JavaScript
30
star
13

tutorials

JavaScript (and other?) tutorials
JavaScript
29
star
14

tinpig

A fast, lightweight command line utility to create projects of any kind from templates.
JavaScript
26
star
15

minicomps

JavaScript
25
star
16

bitlibjs

A collection of useful JS utils. Mostly math and graphics related.
JavaScript
21
star
17

STProjectMaker-templates

Sample templates for STProjectMaker
Makefile
20
star
18

perlin_noise_to_angle

JavaScript
15
star
19

bitlib-rs

A drawing, color, geometry and math library geared towards creating graphics and animation with cairo-rs
Rust
15
star
20

blgo

bitlib library for golang
Go
14
star
21

bljs

New version of bitlib js for 2021
JavaScript
14
star
22

sound-synth-music-resources

11
star
23

steggo

Go
9
star
24

bitlib_c

bitlib graphics library ported to c (gtk/cairo).
C
8
star
25

weave

JavaScript
8
star
26

curlnoise_tutorial

JavaScript
7
star
27

truchet

Go
6
star
28

lcg

Fast and simple Pseudo Random Number Generator
JavaScript
6
star
29

embeds2021

JavaScript
5
star
30

dailies

daily code experiments
Go
5
star
31

go-ansi

ANSI escape sequences for Golang
Go
4
star
32

bitface

Garmin Watch Face
Monkey C
4
star
33

bufkill

Better buffer deletion
Vim Script
4
star
34

tinpig-templates

Useful project templates for the tinpig templating utility.
Go
4
star
35

webgl_egghead

Source code for the WebGL video tutorial lessons on Egghead.io
JavaScript
4
star
36

gesso

Gesso prepares a canvas for painting (and animating).
JavaScript
3
star
37

simpledraw_chrome

A Packaged Chrome Application that is a simple drawing application.
JavaScript
2
star
38

adventofcode-go

All my advent of code submissions.
Go
2
star
39

c_iso

Isocmetric drawing library written in C using Cairo Graphics.
C
2
star
40

blcairo

Go
1
star
41

july2018gifs

a gif a day for july, made in golang
Go
1
star
42

7doc

7 days of code
JavaScript
1
star
43

blgrids

Go
1
star
44

rds

Reaction Diffusion simulation
Go
1
star
45

boxbreath

cli app to guide you through a box breathing session
Go
1
star
46

strange_explorer

Explore strange attractor algorithms.
C
1
star
47

bitlib

Go
1
star
48

omdb-graphql

GraphQL interface for the Open Movie Database API
JavaScript
1
star
49

tinpig2

Go
1
star