forked from soggybag/shared-canvas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjonathan.js
71 lines (56 loc) · 1.81 KB
/
jonathan.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
import ctx, { size } from './main.js'
//restore context
ctx.restore()
//my position
const jwx = 1 * size
const jwy = 0 * size
// background square
drawRect(ctx, jwx, jwy, size, size, "#222222")
// stem
drawRect(ctx, jwx + (113 / 2) - 5, jwy + 15, 10, 25, "#FFFDD0")
// pumpkin
drawEllipse(ctx, jwx + (113 / 2), jwy + (113 / 2) + 10, 50, 40, "#FF7518")
// eyes black
drawCircle(ctx, jwx + (113 / 2) - 25, jwy + (113 / 2) - 5, 10, "#000000")
drawCircle(ctx, jwx + (113 / 2) + 15, jwy + (113 / 2) - 5, 10, "#000000")
// eyes white
drawCircle(ctx, jwx + (113 / 2) - 25, jwy + (113 / 2) - 5, 5, "#ffffff")
drawCircle(ctx, jwx + (113 / 2) + 15, jwy + (113 / 2) - 5, 5, "#ffffff")
// mouth
drawRect(ctx, jwx + (113 / 2) - 10, jwy + (113 / 2) + 15, 20, 10, "#000000")
drawRect(ctx, jwx + (113 / 2) - 5, jwy + (113 / 2) + 15, 10, 5, "#ffffff")
//signature
drawText(ctx, "Spooky", jwx, jwy, 7, "#fff")
// draw a rectangle
function drawRect(ctx, x, y, width, height, color) {
ctx.beginPath()
ctx.rect(x, y, width, height)
ctx.fillStyle = color
ctx.fill()
}
// draw a circle
function drawCircle(ctx, x, y, size, color) {
ctx.beginPath()
ctx.arc(x + size / 2, y + size / 2, size, 0, Math.PI * 2)
ctx.fillStyle = color
ctx.fill()
}
function drawText(ctx, text, x, y, size, color) {
ctx.beginPath()
ctx.font = size + 'px Helvetica'
ctx.fillStyle = color
ctx.fillText(text, x + 70, y + 10)
}
// draw an ellipse
// taken from:
//https://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas
function drawEllipse(ctx, cx, cy, rx, ry, color) {
ctx.save(); // save state
ctx.beginPath();
ctx.translate(cx - rx, cy - ry);
ctx.scale(rx, ry);
ctx.arc(1, 1, 1, 0, 2 * Math.PI, false);
ctx.restore(); // restore to original state
ctx.fillStyle = color
ctx.fill();
}