2 * Sixth 3D engine demos. Copyright ©2012-2019, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of version 3 of the GNU Lesser General Public License
6 * or later as published by the Free Software Foundation.
9 package eu.svjatoslav.sixth.e3d.examples;
11 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
12 import eu.svjatoslav.sixth.e3d.gui.ViewFrame;
13 import eu.svjatoslav.sixth.e3d.gui.ViewPanel;
14 import eu.svjatoslav.sixth.e3d.gui.ViewRenderListener;
15 import eu.svjatoslav.sixth.e3d.math.Transform;
16 import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
17 import eu.svjatoslav.sixth.e3d.renderer.raster.ShapeCollection;
18 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractShape;
19 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.textcanvas.TextCanvas;
21 import java.util.Collection;
22 import java.util.Random;
24 public class RainingNumbersDemo implements ViewRenderListener {
26 private static final int NUMBERS_COUNT = 1000;
27 private final static int AREA = 600;
28 private final static int AREA_HALF = AREA / 2;
30 public static void main(final String[] args) {
31 new RainingNumbersDemo().run();
35 public boolean beforeRender(final ViewPanel viewPanel,
36 final int millisecondsSinceLastFrame) {
38 final Collection<AbstractShape> shapes = viewPanel
39 .getRootShapeCollection().getShapes();
41 final double translateAmount = millisecondsSinceLastFrame / 50d;
43 shapes.stream().filter(shape -> shape instanceof TextCanvas).forEach(shape -> {
44 final TextCanvas block = (TextCanvas) shape;
45 final Point3D location = block.getLocation();
46 location.translateY(translateAmount);
48 if (location.y > AREA_HALF)
56 final ViewFrame viewFrame = new ViewFrame();
58 final ShapeCollection geometryCollection = viewFrame.getViewPanel()
59 .getRootShapeCollection();
61 Random random = new Random();
63 for (int i = 0; i < NUMBERS_COUNT; i++) {
64 final Point3D location = new Point3D((Math.random() * AREA)
65 - AREA_HALF, (Math.random() * AREA) - AREA_HALF,
66 (Math.random() * AREA) - AREA_HALF);
68 final Color color = new Color(Math.random(), Math.random(),
69 Math.random(), Math.random());
71 final TextCanvas textCanvas = new TextCanvas(
72 new Transform(location), String.valueOf(random.nextInt(10)), color,
75 geometryCollection.addShape(textCanvas);
78 viewFrame.getViewPanel().addViewUpdateListener(this);