-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
75 lines (62 loc) · 1.47 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*!
* jCanvas in Node demo
* Copyright (c) 2015 Robert Jones <rjones@opdots.com>
* MIT Licensed
*/
var jsdom = require('jsdom'),
JQuery = require( 'jquery' ),
JCanvas = require( 'jcanvas' ),
html = '<html><body><canvas id="cx" width="400" height="300"></canvas></body></html>';
jsdom.env( html, function ( errors, window ) {
if( errors ) console.log( errors );
var $ = JQuery( window );
JCanvas( $, window );
var $c = $( '<canvas>' );
// hack required by width/height bug in jsdom/node-canvas integration
$c[0].width = 400;
$c[0].height = 300;
// Standard jCanvas
$c.scaleCanvas({
scale: 0.25
})
.drawArc({
fillStyle: 'black',
x: 100, y: 100,
radius: 50
})
.drawArc({
fillStyle: '#36b',
x: 300, y: 150,
radius: 50
})
.drawPolygon({
strokeStyle: 'black',
strokeWidth: 4,
x: 200, y: 100,
radius: 50,
sides: 3
})
.drawPolygon({
fillStyle: '#c33',
strokeStyle: '#000',
x: 340, y: 60,
radius: 50,
sides: 5,
rotate: 25
}).drawPolygon({
fillStyle: '#36c',
x: 160, y: 160,
radius: 50,
sides: 5,
concavity: 0.5
}).drawPolygon({
fillStyle: '#3c6',
strokeStyle: '#083',
x: 60, y: 240,
radius: 50,
sides: 50,
concavity: 0.1
});
console.warn( 'Paste the following as a url in your browser.' );
console.log( $c.getCanvasImage( 'png' ) );
});