-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircleCanvas.js
More file actions
45 lines (41 loc) · 1.32 KB
/
circleCanvas.js
File metadata and controls
45 lines (41 loc) · 1.32 KB
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
class Circle {
constructor(posX, posY, dX, dY, radius, color, octave, note, context, id) {
this.posX = posX,
this.posY = posY,
this.dX = dX,
this.dY = dY,
this.radius = radius,
this.color = color,
this.octave = octave,
this.note = note,
this.context = context,
this.id = id
}
draw() {
this.context.shadowBlur = 5;
this.context.shadowColor = "black";
// this.context.shadowOffsetX = 2;
// this.context.shadowOffsetY = 2;
this.context.beginPath()
this.context.fillStyle = this.color
this.context.arc(this.posX, this.posY, this.radius, 0, Math.PI * 2)
this.context.fill()
}
nextStep() {
this.posX += this.dX;
this.posY += this.dY;
}
clear(canvas) {
this.context.clearRect(0,0, canvas.width, canvas.height)
}
checkBoundaries(canvas) {
if(this.posY + this.dY > canvas.height || this.posY + this.dY < 0) {
this.dY = -this.dY;
tones.play(this.note, this.octave);
console.log("tone played for Y boundary", this.note, this.octave)
} else if (this.posX + this.dX > canvas.width || this.posX + this.dX < 0) {
this.dX = -this.dX;
tones.play(this.note, this.octave);
}
}
}