-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcanvas.js
81 lines (57 loc) · 1.46 KB
/
canvas.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
74
75
76
77
78
79
80
81
canvas = document.querySelector("canvas");
canvas.width = innerWidth;
canvas.height = innerHeight;
c = canvas.getContext('2d');
mouse = {
x: innerWidth/2,
y: innerHeight/2
}
addEventListener('mousemove', (event) => {
mouse.x = event.clientX;
mouse.y = event.clientY;
})
addEventListener('resize', (event) => {
canvas.width = innerWidth;
canvas.height = innerHeight;
})
function text(text, x, y, color) {
c.fillStyle=color;
c.fillText(text, x, y);
}
function line(x1,y1, x2, y2, color="red") {
c.beginPath();
c.moveTo(x1,y1);
c.lineTo(x2,y2);
c.strokeStyle=color;
c.stroke();
}
function circle(x,y, radius, color="red", fill="blue") {
c.beginPath();
c.strokeStyle = color;
c.arc(x,y,radius,0,Math.PI *2);
c.fillStyle=fill;
c.stroke();
c.fill()
}
colors = ["#E63946", "#F1FAEE", "#A8DADC", "#457B9D", "#1D3557"];
class Object {
constructor() {
};
update () {
}
draw() {
}
}
function init() {
//init world
}
function animate() {
requestAnimationFrame(animate)
c.clearRect(0, 0, canvas.width, canvas. height);
//Update and draw objects
circle(mouse.x, mouse.y, 100, "black", "rgba(0,0,255,0.5")
circle(mouse.x+100, mouse.y, 100, "black", "rgba(0,255,255,0.5")
text("www.manualdocodigo.com.br", mouse.x,mouse.y, "black")
}
init();
animate();