forked from DesirY/Visualization
-
Notifications
You must be signed in to change notification settings - Fork 0
/
food_form.js
63 lines (61 loc) · 1.44 KB
/
food_form.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
function Food(x, y, radius)
{
//没有在页面上加载这个文件浪费了多少时间
this.id = Food.uid();
this.x = x;
this.y = y;
this.radius = radius;
this.energy = radius;
this.live = true;
this.time = 0;
this.colorlist = ["#63A69F", "#F0E0AF", "#F1836A", "#C92D28"];
this.color = this.colorlist[parseInt(Math.random()*4)]
}
(function () {
var id = 0;
Food.uid = function()
{
return id++;
}
})();
Food.prototype = {
getX: function () {
return this.x;
},
getY: function () {
return this.y;
},
getLive: function () {
return this.live;
},
getRadius: function () {
return this.radius;
},
getId: function() {
return this.id;
},
draw: function (ctx) {
this.time++;
if(this.time > 100){
this.radius = 0;
this.live = false;
}
ctx.fillStyle = this.color;
ctx.strokeStyle = this.color;
ctx.globalAlpha = 0.15;//颜色进行调整
ctx.beginPath();
ctx.arc(this.x,this.y,this.radius,0,2*Math.PI);
ctx.fill();
//ctx.stroke();
},
eaten: function (butterfly, ctx){
if(this.energy > 0){
this.energy -= 3;
butterfly.setmateYear();
}
else{
this.live = false;
this.radius = 0;
}
}
}