-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.js
More file actions
36 lines (28 loc) · 778 Bytes
/
demo.js
File metadata and controls
36 lines (28 loc) · 778 Bytes
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
var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');
document.body.appendChild(canvas);
var width, height, pixelRatio;
function resize () {
width = 256;
height = 256;
pixelRatio = window.devicePixelRatio;
canvas.width = width * pixelRatio;
canvas.height = height * pixelRatio;
canvas.style.width = width+"px";
canvas.style.height = height+"px";
}
function draw () {
context.save();
context.scale(pixelRatio, pixelRatio);
context.fillStyle = 'tomato';
context.fillRect(0, 0, width, height);
context.fillStyle = 'orange';
context.fillRect(50, 100, 50, 25);
context.fillStyle = 'red';
context.beginPath();
context.arc(150, 150, 50, 0, Math.PI * 2);
context.fill();
context.restore();
}
resize();
draw();