2014-07-24 05:35:57 +02:00
|
|
|
(function(
|
|
|
|
Engine,
|
|
|
|
Vector
|
|
|
|
){
|
|
|
|
|
2014-07-28 02:19:01 +02:00
|
|
|
Engine.Polygon = function(a, b, c, color, strokeColor){
|
2014-07-24 05:35:57 +02:00
|
|
|
this.a = a;
|
|
|
|
this.b = b;
|
|
|
|
this.c = c;
|
|
|
|
|
2014-07-24 09:37:27 +02:00
|
|
|
this.color = Engine.clone(color);
|
2014-07-28 02:19:01 +02:00
|
|
|
this.strokeColor = strokeColor ? Engine.clone(strokeColor) : Engine.clone(color);
|
2014-07-25 09:04:54 +02:00
|
|
|
|
2014-07-28 02:19:01 +02:00
|
|
|
if (strokeColor) {
|
|
|
|
this.strokeColor = Engine.clone(strokeColor);
|
2014-07-25 09:04:54 +02:00
|
|
|
} else {
|
2014-07-28 02:19:01 +02:00
|
|
|
this.strokeColor = Engine.clone(color);
|
2014-07-25 09:04:54 +02:00
|
|
|
}
|
2014-07-24 05:35:57 +02:00
|
|
|
|
2014-07-28 02:49:02 +02:00
|
|
|
this.strokeWidth = 0.25;
|
|
|
|
this.maxStrokeS = this.strokeColor.s;
|
2014-07-28 02:19:01 +02:00
|
|
|
this.maxStrokeL = this.strokeColor.l;
|
|
|
|
this.maxColorL = this.color.l;
|
|
|
|
|
|
|
|
this.strokeColor.s = 0;
|
|
|
|
this.strokeColor.l = 100;
|
|
|
|
this.color.l = 0;
|
|
|
|
|
2014-07-24 05:35:57 +02:00
|
|
|
this.fillStyle = this.hslaTemplate.substitute(this.color);
|
2014-07-24 09:37:27 +02:00
|
|
|
this.strokeStyle = this.hslaTemplate.substitute(this.strokeColor);
|
2014-07-24 05:35:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Engine.Polygon.prototype = {
|
|
|
|
|
|
|
|
rgbaTemplate: 'rgba({r},{g},{b},{a})',
|
|
|
|
hslaTemplate: 'hsla({h},{s}%,{l}%,{a})',
|
|
|
|
|
|
|
|
hueShiftSpeed: 20,
|
2014-07-24 07:28:16 +02:00
|
|
|
duration: 2,
|
|
|
|
delay: 0,
|
|
|
|
start: 0,
|
2014-07-24 05:35:57 +02:00
|
|
|
|
|
|
|
// Determine color fill?
|
|
|
|
update: function(engine){
|
|
|
|
var delta;
|
|
|
|
|
2014-07-25 09:04:54 +02:00
|
|
|
if (this.simple) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-24 07:28:16 +02:00
|
|
|
this.start += engine.tick;
|
|
|
|
|
|
|
|
delta = this.start;
|
2014-07-24 05:35:57 +02:00
|
|
|
|
|
|
|
if (
|
|
|
|
delta > this.delay &&
|
|
|
|
delta < this.delay + this.duration + 1 &&
|
2014-07-28 02:19:01 +02:00
|
|
|
this.color.l < this.maxColorL
|
2014-07-24 05:35:57 +02:00
|
|
|
) {
|
2014-07-28 02:19:01 +02:00
|
|
|
this.color.l = this.maxColorL * (delta - this.delay) / this.duration;
|
2014-07-24 05:35:57 +02:00
|
|
|
|
2014-07-28 02:49:02 +02:00
|
|
|
this.strokeColor.s = this.maxStrokeS * (delta - this.delay) / this.duration;
|
2014-07-28 02:19:01 +02:00
|
|
|
this.strokeColor.l = (this.maxStrokeL - 100) * (delta - this.delay) / this.duration + 100;
|
2014-07-24 07:28:16 +02:00
|
|
|
|
2014-07-28 02:49:02 +02:00
|
|
|
this.strokeWidth = 1.5 * (delta - this.delay) / this.duration + 0.25;
|
|
|
|
|
2014-07-28 02:19:01 +02:00
|
|
|
if (this.color.l > this.maxColorL) {
|
|
|
|
this.color.l = this.maxColorL;
|
|
|
|
this.strokeColor.l = this.maxStrokeL;
|
2014-07-28 02:49:02 +02:00
|
|
|
this.strokeWidth = 1.5;
|
2014-07-24 05:35:57 +02:00
|
|
|
}
|
|
|
|
|
2014-07-24 07:28:16 +02:00
|
|
|
this.strokeStyle = this.hslaTemplate.substitute(this.strokeColor);
|
2014-07-24 05:35:57 +02:00
|
|
|
this.fillStyle = this.hslaTemplate.substitute(this.color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
})(window.Engine, window.Vector);
|