2 * Sixth 3D engine. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
5 package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite;
7 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
8 import eu.svjatoslav.sixth.e3d.math.Transform;
9 import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
10 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.GlowingPoint;
11 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base.AbstractCompositeShape;
13 import java.util.ArrayList;
14 import java.util.List;
15 import java.util.Random;
17 public class Galaxy extends AbstractCompositeShape {
19 private static List<Color> colors;
21 public Galaxy(final int size, final int tailCount, final int starsCount,
22 Transform transform) {
26 ensureColorsAreInitialized();
28 final double angle1 = Math.random() * 10;
29 final double angle2 = Math.random() * 10;
31 final double angleSin1 = Math.sin(angle1);
32 final double angleCos1 = Math.cos(angle1);
33 final double angleSin2 = Math.sin(angle2);
34 final double angleCos2 = Math.cos(angle2);
36 Random random = new Random();
38 for (int i = 1; i < starsCount; i++) {
39 final double b = Math.random() * 10;
41 final double s = (b * b) / 30;
43 final double v1 = (Math.random() * (11.5 - b)) / 3;
44 final double v1p = v1 / 2;
46 final double ane = ((Math.random() * (s / 2)) / tailCount) * 2;
47 final double sba = ((2 * Math.PI) / tailCount)
48 * random.nextInt(tailCount);
50 final double x = (((Math.sin((b - sba) + ane) * s) + (Math.random() * v1)) - v1p)
52 final double z = (((Math.cos((b - sba) + ane) * s) + (Math.random() * v1)) - v1p)
54 final double y = ((Math.random() * v1) - v1p) * size;
56 final double x1 = (x * angleCos1) + (z * angleSin1);
57 final double z1 = (z * angleCos1) - (x * angleSin1);
59 final double y1 = (y * angleCos2) + (z1 * angleSin2);
60 final double z2 = (z1 * angleCos2) - (y * angleSin2);
62 addStar(new Point3D(x1, y1, z2));
66 private void addStar(final Point3D starLocation) {
68 new GlowingPoint(starLocation, 10,
69 colors.get((int) (Math.random() * colors.size()))));
72 private synchronized void ensureColorsAreInitialized() {
73 if (colors != null) return;
75 colors = new ArrayList<>();
77 for (int i = 0; i < 30; i++)