-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
70 lines (60 loc) · 1.96 KB
/
server.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
class Server {
posX;
posY;
distance;
ipAddress;
websites;
radius = 25;
selected = false;
disabled = false;
colored = false;
neighbours = [];
previous;
highlighted = false;
bfsHighlighted = false;
constructor(posX, posY, ipAddress, websites) {
this.posX = posX;
this.posY = posY;
this.ipAddress = ipAddress;
this.websites = websites;
}
getIpString() {
return this.ipAddress.join('.');
}
draw(context) {
let circle = new Path2D();
circle.arc(this.posX, this.posY, this.radius, 0, 2 * Math.PI, false);
if(this.disabled) {
context.fillStyle = 'red'; // Fill color
} else {
context.fillStyle = 'blue'; // Fill color
}
context.fill(circle); // Fill the circle
if(this.selected) {
context.strokeStyle = '#FFFFFF'; // Stroke color
} else if(this.highlighted) {
context.strokeStyle = '#00FF00'; // Stroke color
} else if (this.bfsHighlighted) {
context.strokeStyle = '#FF0000'; // Stroke color
} else {
context.strokeStyle = '#000066'; // Stroke color
}
context.lineWidth = 5; // Stroke width
context.stroke(circle); // Stroke the circle
// Set the font properties
context.font = '15px Arial';
context.fillStyle = 'black';
// Draw the text
context.fillText(
this.ipAddress[0] + '.' + this.ipAddress[1] + '.' + this.ipAddress[2] + '.' + this.ipAddress[3],
this.posX - this.radius,
this.posY + 2 * this.radius
);
}
contains(x, y) {
// Calculate the distance between the point (x, y) and the center of the circle
let distance = Math.sqrt(Math.pow(x - this.posX, 2) + Math.pow(y - this.posY, 2));
// Check if the distance is less than or equal to the radius
return distance <= this.radius;
}
}