From 006585b5853331fe4e78699b5cdc70fd5fdccbc9 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Thu, 23 Feb 2023 00:12:04 +0200 Subject: [PATCH] Improved code readability --- .../sixth/e3d/examples/galaxy_demo/Galaxy.java | 15 ++++++++++++++- .../sixth/e3d/examples/launcher/Main.java | 4 ++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/galaxy_demo/Galaxy.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/galaxy_demo/Galaxy.java index 30ea58d..73764a9 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/examples/galaxy_demo/Galaxy.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/examples/galaxy_demo/Galaxy.java @@ -18,6 +18,15 @@ import static java.lang.Math.*; 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 colors; public Galaxy(final int galaxySize, final int tailCount, final int starsCount, @@ -69,12 +78,16 @@ public class Galaxy extends AbstractCompositeShape { 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, diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/Main.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/Main.java index 07e5c39..f972085 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/Main.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/Main.java @@ -9,12 +9,16 @@ package eu.svjatoslav.sixth.e3d.examples.launcher; 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"); -- 2.20.1