2 * Sixth - System for data storage, computation, exploration and interaction.
3 * Copyright ©2012-2016, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 3 of the GNU Lesser General Public License
7 * or later as published by the Free Software Foundation.
10 package eu.svjatoslav.sixth.e3d.examples;
12 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
13 import eu.svjatoslav.sixth.e3d.geometry.Transform;
14 import eu.svjatoslav.sixth.e3d.gui.ViewContext;
15 import eu.svjatoslav.sixth.e3d.gui.ViewFrame;
16 import eu.svjatoslav.sixth.e3d.gui.ViewUpdateListener;
17 import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
18 import eu.svjatoslav.sixth.e3d.renderer.raster.ShapeCollection;
19 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractShape;
20 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.textcanvas.TextCanvas;
22 import java.io.IOException;
23 import java.util.Collection;
24 import java.util.Random;
26 public class RainingNumbersDemo implements ViewUpdateListener {
28 private static final int NUMBERS_COUNT = 1000;
29 private final static int AREA = 600;
30 private final static int AREA_HALF = AREA / 2;
32 public static void main(final String[] args) throws IOException {
33 new RainingNumbersDemo().run();
37 public boolean beforeViewUpdate(final ViewContext viewContext,
38 final int millisecondsSinceLastFrame) {
40 final Collection<AbstractShape> shapes = viewContext
41 .getRootShapeCollection().getShapes();
43 final double translateAmount = millisecondsSinceLastFrame / 50d;
45 shapes.stream().filter(shape -> shape instanceof TextCanvas).forEach(shape -> {
46 final TextCanvas block = (TextCanvas) shape;
47 final Point3D location = block.getLocation();
48 location.translateY(translateAmount);
50 if (location.y > AREA_HALF)
57 private void run() throws IOException {
58 final ViewFrame viewFrame = new ViewFrame();
60 final ShapeCollection geometryCollection = viewFrame.getView()
61 .getContext().getRootShapeCollection();
63 Random random = new Random();
65 for (int i = 0; i < NUMBERS_COUNT; i++) {
66 final Point3D location = new Point3D((Math.random() * AREA)
67 - AREA_HALF, (Math.random() * AREA) - AREA_HALF,
68 (Math.random() * AREA) - AREA_HALF);
70 final Color color = new Color(Math.random(), Math.random(),
71 Math.random(), Math.random());
73 final TextCanvas textCanvas = new TextCanvas(
74 new Transform(location), String.valueOf(random.nextInt(10)), color,
77 geometryCollection.addShape(textCanvas);
80 viewFrame.getView().addViewUpdateListener(this);