|
|
@ -1,6 +1,7 @@ |
|
|
|
"use strict"; |
|
|
|
|
|
|
|
import Vector from './Vector'; |
|
|
|
import random from './Random'; |
|
|
|
|
|
|
|
class Star |
|
|
|
{ |
|
|
@ -8,17 +9,23 @@ class Star |
|
|
|
{ |
|
|
|
this.canvas = inCanvas; |
|
|
|
|
|
|
|
this.position = inPosition; |
|
|
|
this.rotation = 0; |
|
|
|
this.rotationStep = 0; |
|
|
|
this.alpha = 1; |
|
|
|
this.position = inPosition; // The position
|
|
|
|
this.rotation = 0; // The rotation
|
|
|
|
this.rotationStep = 0; // The amount (in rads / sec) the star turns by
|
|
|
|
this.alpha = 1; // The opacity
|
|
|
|
|
|
|
|
this.pointCount = 5; |
|
|
|
this.pointCount = 5; // The number of points
|
|
|
|
|
|
|
|
this.size = inSize; |
|
|
|
this.innerRingRatio = 0.5; |
|
|
|
this.startSize = inSize; // The initial radius
|
|
|
|
this.size = this.startSize; // The current radius
|
|
|
|
this.innerRingRatio = 0.5; // The radius of the inner ring (for the inner points)
|
|
|
|
|
|
|
|
this.colour = "white"; |
|
|
|
this.twinkleSize = this.size * 2; // The size multiplier when twinkling
|
|
|
|
this.twinkling = false; // Whether we're twinkling
|
|
|
|
this.twinkleDuration = 2; // The duration of a twinkle (in seconds)
|
|
|
|
this.twinkleTimer = 0; // The current point along the twinkle we are at now
|
|
|
|
|
|
|
|
this.colour = "white"; // The colour of the star
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -52,11 +59,27 @@ class Star |
|
|
|
|
|
|
|
update(dt) |
|
|
|
{ |
|
|
|
// Rotate (slowly I hope)
|
|
|
|
this.rotation += this.rotationStep * dt; |
|
|
|
// if(this.rotation > Math.PI * 2)
|
|
|
|
// this.rotation -= Math.PI * 2;
|
|
|
|
// if(this.rotation < 0)
|
|
|
|
// this.rotation += Math.PI * 2;
|
|
|
|
|
|
|
|
// Randomly begin a twinkle
|
|
|
|
/*if(!this.twinkling && Math.floor(random(0, 50)*dt) == 0) |
|
|
|
this.twinkling = true; |
|
|
|
|
|
|
|
if(this.twinkling) |
|
|
|
{ |
|
|
|
// Calculate the new size quadratically
|
|
|
|
let sizeMultiplier = 1 + (1 - Math.pow(2*(this.twinkleTimer / this.twinkleDuration) - 1, 2)); |
|
|
|
this.size = this.startSize * sizeMultiplier; |
|
|
|
|
|
|
|
this.twinkleTimer += dt; |
|
|
|
if(this.twinkleTimer == this.twinkleDuration) |
|
|
|
this.twinkling = false, this.twinkleTimer = 0; |
|
|
|
}*/ |
|
|
|
} |
|
|
|
|
|
|
|
render(context) |
|
|
|