2 * Sixth 3D engine demos. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
7 package eu.svjatoslav.sixth.e3d.examples;
9 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
10 import eu.svjatoslav.sixth.e3d.gui.ViewFrame;
11 import eu.svjatoslav.sixth.e3d.gui.ViewPanel;
12 import eu.svjatoslav.sixth.e3d.gui.ViewRenderListener;
13 import eu.svjatoslav.sixth.e3d.math.Transform;
14 import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
15 import eu.svjatoslav.sixth.e3d.renderer.raster.ShapeCollection;
16 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractShape;
17 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.textcanvas.TextCanvas;
19 import java.util.Collection;
20 import java.util.Random;
22 public class RainingNumbersDemo implements ViewRenderListener {
24 private static final int NUMBERS_COUNT = 1000;
25 private final static int AREA = 600;
26 private final static int AREA_HALF = AREA / 2;
28 public static void main(final String[] args) {
29 new RainingNumbersDemo().run();
33 public boolean beforeRender(final ViewPanel viewPanel,
34 final int millisecondsSinceLastFrame) {
36 final Collection<AbstractShape> shapes = viewPanel
37 .getRootShapeCollection().getShapes();
39 final double translateAmount = millisecondsSinceLastFrame / 50d;
41 shapes.stream().filter(shape -> shape instanceof TextCanvas).forEach(shape -> {
42 final TextCanvas block = (TextCanvas) shape;
43 final Point3D location = block.getLocation();
44 location.translateY(translateAmount);
46 if (location.y > AREA_HALF)
54 final ViewFrame viewFrame = new ViewFrame();
56 final ShapeCollection geometryCollection = viewFrame.getViewPanel()
57 .getRootShapeCollection();
59 Random random = new Random();
61 for (int i = 0; i < NUMBERS_COUNT; i++) {
62 final Point3D location = new Point3D((Math.random() * AREA)
63 - AREA_HALF, (Math.random() * AREA) - AREA_HALF,
64 (Math.random() * AREA) - AREA_HALF);
66 final Color color = new Color(Math.random(), Math.random(),
67 Math.random(), Math.random());
69 final TextCanvas textCanvas = new TextCanvas(
70 new Transform(location), String.valueOf(random.nextInt(10)), color,
73 geometryCollection.addShape(textCanvas);
76 viewFrame.getViewPanel().addViewUpdateListener(this);