public class Galaxy extends AbstractCompositeShape {
+ /**
+ * The number of unique colors used in the galaxy.
+ */
+ public static final int UNIQUE_COLORS_COUNT = 30;
+
+ /**
+ * A list of all colors used in the galaxy.
+ * Used to reuse textures of glowing points of the same color.
+ */
private static List<Color> colors;
public Galaxy(final int galaxySize, final int tailCount, final int starsCount,
addShape(new GlowingPoint(starLocation, size, colors.get((int) (random() * colors.size()))));
}
+ /**
+ * Initializes the list of colors used in the galaxy.
+ * Used to reuse textures of glowing points of the same color.
+ */
private synchronized void ensureColorsAreInitialized() {
if (colors != null) return;
colors = new ArrayList<>();
- for (int i = 0; i < 30; i++)
+ for (int i = 0; i < UNIQUE_COLORS_COUNT; i++)
colors.add(
new Color(
random() + 0.5,
import javax.swing.*;
import java.awt.*;
+
class Main {
public static void main(final String[] args) {
buildAndShowGuiWindow();
}
+ /**
+ * Builds and shows the main window of the application.
+ */
private static void buildAndShowGuiWindow() {
JFrame frame = new JFrame("Sixth 3D engine demos");