transformStar method

void transformStar(
  1. Star star
)

Translates the provided Star's points.

The star will either be transformed to move towards the screen or its radius will be updated to create a 'flicker' effect.

To create a transform offset, the star's current position are set in relation to the provided velocity.

The star's z value is decreased by the starfield's depth to make the star appear moving towards the screen.

Implementation

void transformStar(Star star) {
  // Transform
  star.translatedOffset =
      Offset((star.dx / star.dz + center.dx), star.dy / star.dz + center.dy);
  // Slowly move the star to the size edges.
  star.dz -= star.baseDepth;

  // If the star's z point is closer to the screen than the base depth
  if (star.dz < star.baseDepth) {
    // Accelerate it
    final Math.Random random = Math.Random();
    star.dz = random.nextDouble() * absoluteVelocity + absoluteVelocity;
    star.radius = scale;
    // Else only adjust the radius to create a 'flicker' effect.
  } else {
    star.radius = ((absoluteVelocity / 8) / star.dz + star.baseDepth) * scale;
  }
}