if (twinkle) {
// Draw a non-rotating star in the alternate "twinkling" color
gl.uniform3f(shaderProgram.colorUniform, this.twinkleR, this.twinkleG, this.twinkleB);
drawStar();
}
// All stars spin around the Z axis at the same rate
mvMatrix.rotZ(OAK.SPACE_LOCAL, spin);
// Draw the star in its main color
gl.uniform3f(shaderProgram.colorUniform, this.r, this.g, this.b);
drawStar();
// Decrease the distance, resetting the star to the outside of
// the spiral if it's at the center.
this.dist -= 0.01 * effectiveFPMS * elapsedTime;
if (this.dist < 0.0) {
this.dist += 5.0;
this.randomiseColors();
}
Star.prototype.randomiseColors = function () {
// Give the star a random color for normal
// circumstances...
this.r = Math.random();
this.g = Math.random();
this.b = Math.random();
// When the star is twinkling, we draw it twice, once
// in the color below (not spinning) and then once in the
// main color defined above.
this.twinkleR = Math.random();
this.twinkleG = Math.random();
this.twinkleB = Math.random();
};