forked from Borian23/dump1090
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparticle.js
149 lines (132 loc) · 3.47 KB
/
particle.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
let system;
var c;
var select;
var area;
function setup() {
c = createCanvas(196, 128);
// c.position(0,0);
// c.style('position','absolute');
c.parent('#info');
c.style('top','100%');
c.style('left','0%');
// c.style('height','100%');
// c.style('width','100%');
c.style('zIndex','30');
// background(51);
area = createDiv();
area.parent('#info');
area.style('position','absolute');
area.style('top','100%');
// area.style('width','196');
area.style('background-color', color(255,255,255,127));
c.parent(area);
select = createSelect();
// select.parent('#info');
select.parent(area);
select.option('data age');
select.option('altitude');
select.option('lat');
select.option('speed');
select.option('heading');
system = new ParticleSystem(createVector(width-2, height/2));
var count = 0;
window.setInterval(function() {
drawer();
}, 100);
}
function drawer() {
// background(51);
// clear();
// c.claer();
system.addParticle();
system.run();
var c = document.getElementById("defaultCanvas0");
var ctx = c.getContext("2d");
ctx.globalCompositeOperation = "copy";
ctx.drawImage(ctx.canvas,-1, 0);
// reset back to normal for subsequent operations.
ctx.globalCompositeOperation = "source-over"
}
// A simple Particle class
let Particle = function(position) {
// this.acceleration = createVector(0, random(-0.05, 0.05));
// this.velocity = createVector(0, random(-0.1, 0.1));
// this.position = position.copy();
var y;
// y = height/2;
this.acceleration = createVector(0, random(-0.05, 0.05));
// this.acceleration = createVector(0, 0);
this.velocity = createVector(0, random(-0.1, 0.1));
this.position = position.copy();
var p;
// Selected = 'a1741a';
if (Planes[Selected]){
p = Planes[Selected];
item = select.value();
console.log(item);
// console.log("alt:" + p.altitude);
if(item == 'altitude'){
y = height*(1-(p.altitude/40000));
console.log(":" + p.altitude);
}
if(item == 'lat'){
y = height*(40.02-p.lat)*10 + height/2;
console.log(":"+p.lat);
}
if(item == 'speed'){
y = height*(1-(p.speed/600));
console.log(":"+p.speed);
}
if(item == 'data age'){
var age_sec = (Date.now()-p.seen*1000)*0.001;
y = height*(1-(age_sec)/15);
console.log(":"+age_sec);
}
if(item == 'heading'){
y = height*(1-(p.track/360));
console.log(":"+p.track);
}
// this.position=y;
}
// else
this.position = createVector(width-2, y);
this.lifespan = 2;
};
Particle.prototype.run = function() {
this.update();
this.display();
};
// Method to update position
Particle.prototype.update = function(){
this.velocity.add(this.acceleration);
this.position.add(this.velocity);
this.lifespan -= 2;
};
// Method to display
Particle.prototype.display = function() {
// stroke(200, this.lifespan);
// strokeWeight(2);
strokeWeight(0);
fill(255,0,0,255);
ellipse(this.position.x, this.position.y, 2, 2);
};
// Is the particle still useful?
Particle.prototype.isDead = function(){
return this.lifespan < 0;
};
let ParticleSystem = function(position) {
this.origin = position.copy();
this.particles = [];
};
ParticleSystem.prototype.addParticle = function() {
this.particles.push(new Particle(this.origin));
};
ParticleSystem.prototype.run = function() {
for (let i = this.particles.length-1; i >= 0; i--) {
let p = this.particles[i];
p.run();
if (p.isDead()) {
this.particles.splice(i, 1);
}
}
};