-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbots.js
83 lines (68 loc) · 2.76 KB
/
bots.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
82
83
function Bot (idNum, startingPos, length){
this.idNum = idNum;
this.color = colorS[ Math.floor(Math.random()*colorS.length)];
this.length = length;
this.bodyPos = startingPos //as array [x,y]
this.tailPos = [startingPos[0], (startingPos[1] - length)];
this.pos = [this.bodyPos[0], this.bodyPos[1]];
this.headPos = [
this.bodyPos[0] + ( this.bodyPos[0] - this.tailPos[0] ) ,
this.bodyPos[1] + ( this.bodyPos[1] - this.tailPos[1] ) ];
this.centerHeadPos = [
((this.bodyPos[0] + this.headPos[0]) / 2 ),
((this.bodyPos[1] + this.headPos[1]) / 2 )
]
this.leftAntennaePos = [
this.centerHeadPos[0] + (this.bodyPos[1] - this.centerHeadPos[1]),
this.centerHeadPos[1] - (this.bodyPos[0] - this.centerHeadPos[0])
]
this.rightAntennaePos = [
this.centerHeadPos[0] - (this.bodyPos[1] - this.centerHeadPos[1]),
this.centerHeadPos[1] + (this.bodyPos[0] - this.centerHeadPos[0])
]
}
Bot.prototype.render = function(){
//body
context.beginPath();
context.arc(this.bodyPos[0], this.bodyPos[1], this.length/4, 0, (2 * Math.PI), false);
//context.fillStyle = 'red';
//context.fill();
context.lineWidth = 2;
context.strokeStyle = this.color
context.stroke();
//tail
//context.moveTo(this.tailPos[0], this.tailPos[1])
context.beginPath();
context.arc(this.tailPos[0], this.tailPos[1], this.length/6, 0, (2 * Math.PI), false);
//context.fillStyle = 'green';
//context.fill();
context.lineWidth = 2;
context.strokeStyle = this.color
context.stroke();
//center of head
context.beginPath();
context.arc(this.centerHeadPos[0], this.centerHeadPos[1], this.length/6, 0, (2 * Math.PI), false);
//context.fillStyle = 'green';
//context.fill();
context.lineWidth = 2;
context.strokeStyle = this.color
context.stroke();
//left antennae
//context.moveTo(this.leftAntennaePos[0], this.leftAntennaePos[1])
context.beginPath();
context.arc(this.leftAntennaePos[0], this.leftAntennaePos[1], this.length/6, 0, (2 * Math.PI), false);
//context.fillStyle = 'yellow';
//context.fill();
context.lineWidth = 2;
context.strokeStyle = this.color
context.stroke();
//right antennae
//context.moveTo(this.rightAntennaePos[0], this.rightAntennaePos[1])
context.beginPath();
context.arc(this.rightAntennaePos[0], this.rightAntennaePos[1], this.length/6, 0, (2 * Math.PI), false);
//context.fillStyle = 'blue';
//context.fill();
context.lineWidth = 2;
context.strokeStyle = this.color
context.stroke();
}