mirror of
https://github.com/wassname/cardsforscience.git
synced 2026-07-02 22:28:14 +08:00
Generate more tracks at once in all directions
This commit is contained in:
+10
-5
@@ -258,10 +258,15 @@ var detector =
|
||||
|
||||
addEvent: function()
|
||||
{
|
||||
var index = Math.round(Math.random() * (detector.tracks.length - 1));
|
||||
var event = new ParticleEvent(detector.tracks[index]);
|
||||
var num = Math.ceil(10 * Math.random());
|
||||
|
||||
detector.events.list.push(event);
|
||||
console.log(num);
|
||||
|
||||
for (var i = 0; i < num; i++) {
|
||||
var index = Math.round(Math.random() * (detector.tracks.length - 1));
|
||||
var event = new ParticleEvent(detector.tracks[index], num);
|
||||
detector.events.list.push(event);
|
||||
}
|
||||
},
|
||||
|
||||
draw: function()
|
||||
@@ -273,12 +278,12 @@ var detector =
|
||||
if (detector.events.list[e].alpha > 0) {
|
||||
detector.events.list[e].draw();
|
||||
} else {
|
||||
del = e;
|
||||
del = detector.events.list[e].count;
|
||||
}
|
||||
}
|
||||
|
||||
if (del >= 0) {
|
||||
detector.events.list.splice(0, del + 1);
|
||||
detector.events.list.splice(0, del);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
+6
-3
@@ -1,15 +1,17 @@
|
||||
function ParticleEvent(type)
|
||||
function ParticleEvent(type, count)
|
||||
{
|
||||
this.type = type;
|
||||
this.length = 0;
|
||||
this.radius = 0;
|
||||
this.direction = 0;
|
||||
this.sign = (Math.random() - 0.5 >= 0) ? 1 : -1;
|
||||
this.alpha = 1;
|
||||
this.count = count;
|
||||
|
||||
switch (this.type.name)
|
||||
{
|
||||
case 'electron':
|
||||
this.length = detector.radius.siliconSpace + Math.round((detector.radius.ecal - detector.radius.siliconSpace) * Math.random());
|
||||
this.length = detector.radius.siliconSpace + Math.round((detector.radius.ecal + 10 - detector.radius.siliconSpace) * Math.random());
|
||||
this.direction = Math.random() * Math.PI * 2;
|
||||
this.radius = 20 + Math.round((100 - 20) * Math.random());
|
||||
break;
|
||||
@@ -41,13 +43,14 @@ ParticleEvent.prototype.draw = function(init)
|
||||
ctx.globalAlpha = this.alpha;
|
||||
ctx.strokeStyle = this.type.color;
|
||||
ctx.fillStyle = this.type.color;
|
||||
ctx.lineWidth = 2;
|
||||
|
||||
ctx.translate(cx, cy);
|
||||
ctx.rotate(this.direction);
|
||||
ctx.translate(-cx, -cy);
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.arc(cx + this.length / 2, cy + Math.round(Math.sqrt(Math.abs(this.radius * this.radius - this.length * this.length / 4))), this.radius, -Math.PI / 2 - Math.asin(this.length / (2 * this.radius)), -Math.PI / 2 + Math.asin(this.length / (2 * this.radius)), false);
|
||||
ctx.arc(cx + this.length / 2, cy + this.sign * Math.round(Math.sqrt(Math.abs(this.radius * this.radius - this.length * this.length / 4))), this.radius, - this.sign * Math.PI / 2 - Math.asin(this.length / (2 * this.radius)), - this.sign * Math.PI / 2 + Math.asin(this.length / (2 * this.radius)), false);
|
||||
ctx.stroke();
|
||||
|
||||
ctx.restore();
|
||||
|
||||
Reference in New Issue
Block a user