2 * Sixth 3D engine demos. Copyright ©2012-2016, 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.geometry.Transform;
13 import eu.svjatoslav.sixth.e3d.gui.ViewContext;
14 import eu.svjatoslav.sixth.e3d.gui.ViewFrame;
15 import eu.svjatoslav.sixth.e3d.gui.ViewUpdateListener;
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.io.IOException;
22 import java.util.Collection;
23 import java.util.Random;
25 public class RainingNumbersDemo implements ViewUpdateListener {
27 private static final int NUMBERS_COUNT = 1000;
28 private final static int AREA = 600;
29 private final static int AREA_HALF = AREA / 2;
31 public static void main(final String[] args) throws IOException {
32 new RainingNumbersDemo().run();
36 public boolean beforeViewUpdate(final ViewContext viewContext,
37 final int millisecondsSinceLastFrame) {
39 final Collection<AbstractShape> shapes = viewContext
40 .getRootShapeCollection().getShapes();
42 final double translateAmount = millisecondsSinceLastFrame / 50d;
44 shapes.stream().filter(shape -> shape instanceof TextCanvas).forEach(shape -> {
45 final TextCanvas block = (TextCanvas) shape;
46 final Point3D location = block.getLocation();
47 location.translateY(translateAmount);
49 if (location.y > AREA_HALF)
56 private void run() throws IOException {
57 final ViewFrame viewFrame = new ViewFrame();
59 final ShapeCollection geometryCollection = viewFrame.getView()
60 .getContext().getRootShapeCollection();
62 Random random = new Random();
64 for (int i = 0; i < NUMBERS_COUNT; i++) {
65 final Point3D location = new Point3D((Math.random() * AREA)
66 - AREA_HALF, (Math.random() * AREA) - AREA_HALF,
67 (Math.random() * AREA) - AREA_HALF);
69 final Color color = new Color(Math.random(), Math.random(),
70 Math.random(), Math.random());
72 final TextCanvas textCanvas = new TextCanvas(
73 new Transform(location), String.valueOf(random.nextInt(10)), color,
76 geometryCollection.addShape(textCanvas);
79 viewFrame.getView().addViewUpdateListener(this);