-
Notifications
You must be signed in to change notification settings - Fork 0
/
cards-artwork.html
183 lines (136 loc) · 6.76 KB
/
cards-artwork.html
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<img src="deck.png"
style="position: fixed; opacity: 0.3; height: 1940px; left: -87px; top:-600px; display: none;" />
<script>
const width = 150;
const height = width * 3 / 2;
const tenth = width / 10;
const twentieth = width / 20;
function createCanvas() {
const newCanvas = document.createElement('canvas');
newCanvas.style.border = '1px solid black';
newCanvas.style.margin = '5px';
newCanvas.width = width;
newCanvas.height = height;
document.body.appendChild(newCanvas);
return newCanvas.getContext('2d');
}
function addTextToCanvas(ctx, text, color) {
ctx.fillStyle = color;
ctx.lineWidth = 1;
ctx.font = '50px sans-serif';
ctx.fillText(text, 2, 40);
ctx.fillText(text, width - 30, height - 2);
}
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
}
function drawDiamondsOnCanvas(ctx) {
ctx.fillStyle = 'red';
ctx.beginPath();
const start = new Point(width / 2, width / 2)
ctx.moveTo(start.x, start.y);
const right = new Point(height / 2 - 10, height / 2)
ctx.lineTo(right.x, right.y);
const bottom = new Point(width / 2, width)
ctx.lineTo(bottom.x, bottom.y);
const left = new Point(width - right.x, height / 2);
ctx.lineTo(left.x, left.y);
ctx.closePath();
ctx.fill();
}
function drawSpadesOnCanvas(ctx) {
ctx.fillStyle = 'black';
ctx.beginPath();
const start = new Point(width / 2, width / 2);
const startCp1 = new Point(width - 10, width - 25);
const startCp2 = new Point(width - startCp1.x, startCp1.y);
ctx.moveTo(start.x, start.y);
const inRight = new Point(width / 2 + 5, height / 2)
const inRightCp1 = new Point(width / 2 + 5, width + 5);
const inRightCp2 = new Point(width / 2 + 3, height / 2);
ctx.bezierCurveTo(startCp1.x, startCp1.y, inRightCp1.x, inRightCp1.y, inRight.x, inRight.y);
const baseRight = new Point(width / 2 + 10, width);
const baseRightCp = new Point(width / 2, width);
ctx.bezierCurveTo(inRightCp2.x, inRightCp2.y, baseRightCp.x, baseRightCp.y, baseRight.x, baseRight.y);
const baseLeft = new Point(width - baseRight.x, baseRight.y)
const baseLeftCp = new Point(width - baseRightCp.x, baseRightCp.y)
ctx.lineTo(baseLeft.x, baseLeft.y);
const inLeft = new Point(width - inRight.x, inRight.y)
const inLeftCp1 = new Point(width - inRightCp2.x, inRightCp2.y)
const inLeftCp2 = new Point(width - inRightCp1.x, inRightCp1.y)
ctx.bezierCurveTo(baseLeftCp.x, baseLeftCp.y, inLeftCp1.x, inLeftCp1.y, inLeft.x, inLeft.y);
ctx.bezierCurveTo(inLeftCp2.x, inLeftCp2.y, startCp2.x, startCp2.y, start.x, start.y);
ctx.closePath();
ctx.fill();
}
function drawHeartsOnCanvas(ctx) {
ctx.fillStyle = 'red';
ctx.beginPath();
const start = new Point(width / 2, width * 2 / 3)
const startCp1 = new Point(width / 2 - 5, height / 4)
const startCp2 = new Point(width - startCp1.x, startCp1.y)
ctx.moveTo(start.x, start.y);
const bottom = new Point(width / 2, width)
const bottomCp1 = new Point(width - 10, height / 4)
const bottomCp2 = new Point(width - bottomCp1.x, bottomCp1.y)
ctx.bezierCurveTo(startCp1.x, startCp1.y, bottomCp1.x, bottomCp1.y, bottom.x, bottom.y);
ctx.bezierCurveTo(bottomCp2.x, bottomCp2.y, startCp2.x, startCp2.y, start.x, start.y);
ctx.closePath();
ctx.fill();
}
function drawClubsOnCanvas(ctx) {
ctx.strokeStyle = 'black';
ctx.beginPath();
const inUpRight = new Point(width / 2 + 5, height / 2 - 5);
const inUpRightCp1 = new Point(height / 2, width / 2 - 10);
const inUpRightCp2 = new Point(height / 2, width / 2 - 10);
ctx.moveTo(inUpRight.x, inUpRight.y)
const inDownRight = new Point(width / 2 + 5, height / 2 + 5);
const inDownRightCp1 = new Point(height / 2, width + 10);
const inDownRightCp2 = new Point(width / 2 + 5, height / 2);
ctx.bezierCurveTo(inUpRightCp1.x, inUpRightCp1.y, inDownRightCp1.x, inDownRightCp1.y, inDownRight.x, inDownRight.y)
const baseRight = new Point(width / 2 + 10, width);
const baseRightCp = new Point(width / 2, width);
ctx.bezierCurveTo(inDownRightCp2.x, inDownRightCp2.y, baseRightCp.x, baseRightCp.y, baseRight.x, baseRight.y)
const baseLeft = new Point(width - baseRight.x, baseRight.y);
const baseLeftCp = new Point(width / 2, width);
ctx.lineTo(baseLeft.x, baseLeft.y)
const inDownLeft = new Point(width - inDownRight.x, inDownRight.y);
const inDownLeftCp1 = new Point(width / 2 - 5, height / 2);
const inDownLeftCp2 = new Point(width - inDownRightCp1.x, inDownRightCp1.y);
ctx.bezierCurveTo(baseLeftCp.x, baseLeftCp.y, inDownLeftCp1.x, inDownLeftCp1.y, inDownLeft.x, inDownLeft.y)
const inUpLeft = new Point(width - inUpRight.x, inUpRight.y);
const inUpLeftCp1 = new Point(width - inUpRightCp1.x, inUpRightCp1.y);
const inUpLeftCp2 = new Point(height / 5 - 10, width / 2 - 10);
ctx.bezierCurveTo(inDownLeftCp2.x, inDownLeftCp2.y, inUpLeftCp1.x, inUpLeftCp1.y, inUpLeft.x, inUpLeft.y);
ctx.bezierCurveTo(inUpLeftCp2.x, inUpLeftCp2.y, inUpRightCp2.x, inUpRightCp2.y, inUpRight.x, inUpRight.y);
ctx.closePath()
ctx.fill();
}
// 1 of hearts
const h1x = createCanvas();
drawHeartsOnCanvas(h1x)
// addTextToCanvas(h1x, '1', 'red');
// 2 of spades
const s2x = createCanvas();
drawSpadesOnCanvas(s2x)
// addTextToCanvas(s2x, '2', 'black');
// 4 of clubs
const c4x = createCanvas();
drawClubsOnCanvas(c4x)
// addTextToCanvas(c4x, '4', 'black');
// 3 of Diamonds
const d3x = createCanvas();
drawDiamondsOnCanvas(d3x)
// addTextToCanvas(d3x, '3', 'red');
</script>
</body>
</html>