2 * Sixth 3D engine. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
8 package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite;
10 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
11 import eu.svjatoslav.sixth.e3d.math.Transform;
12 import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
13 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.GlowingPoint;
14 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base.AbstractCompositeShape;
16 import java.util.ArrayList;
17 import java.util.List;
18 import java.util.Random;
20 public class Galaxy extends AbstractCompositeShape {
22 private static List<Color> colors;
24 public Galaxy(final int size, final int tailCount, final int starsCount,
25 Transform transform) {
29 ensureColorsAreInitialized();
31 final double angle1 = Math.random() * 10;
32 final double angle2 = Math.random() * 10;
34 final double angleSin1 = Math.sin(angle1);
35 final double angleCos1 = Math.cos(angle1);
36 final double angleSin2 = Math.sin(angle2);
37 final double angleCos2 = Math.cos(angle2);
39 Random random = new Random();
41 for (int i = 1; i < starsCount; i++) {
42 final double b = Math.random() * 10;
44 final double s = (b * b) / 30;
46 final double v1 = (Math.random() * (11.5 - b)) / 3;
47 final double v1p = v1 / 2;
49 final double ane = ((Math.random() * (s / 2)) / tailCount) * 2;
50 final double sba = ((2 * Math.PI) / tailCount)
51 * random.nextInt(tailCount);
53 final double x = (((Math.sin((b - sba) + ane) * s) + (Math.random() * v1)) - v1p)
55 final double z = (((Math.cos((b - sba) + ane) * s) + (Math.random() * v1)) - v1p)
57 final double y = ((Math.random() * v1) - v1p) * size;
59 final double x1 = (x * angleCos1) + (z * angleSin1);
60 final double z1 = (z * angleCos1) - (x * angleSin1);
62 final double y1 = (y * angleCos2) + (z1 * angleSin2);
63 final double z2 = (z1 * angleCos2) - (y * angleSin2);
65 addStar(new Point3D(x1, y1, z2));
69 private void addStar(final Point3D starLocation) {
71 new GlowingPoint(starLocation, 10,
72 colors.get((int) (Math.random() * colors.size()))));
75 private synchronized void ensureColorsAreInitialized() {
76 if (colors != null) return;
78 colors = new ArrayList<>();
80 for (int i = 0; i < 30; i++)