Search in sources :

Example 21 with AnimationTimer

use of javafx.animation.AnimationTimer in project contentment by GeePawHill.

the class AnimationTimerExperiment method start.

@Override
public void start(final Stage primaryStage) {
    for (int i = 0; i < STAR_COUNT; i++) {
        nodes[i] = new Rectangle(1, 1, Color.WHITE);
        angles[i] = 2.0 * Math.PI * random.nextDouble();
        start[i] = random.nextInt(2000000000);
    }
    final Scene scene = new Scene(new Group(nodes), 800, 600, Color.BLACK);
    primaryStage.setScene(scene);
    primaryStage.show();
    new AnimationTimer() {

        @Override
        public void handle(long now) {
            final double width = 0.5 * primaryStage.getWidth();
            final double height = 0.5 * primaryStage.getHeight();
            final double radius = Math.sqrt(2) * Math.max(width, height);
            for (int i = 0; i < STAR_COUNT; i++) {
                final Node node = nodes[i];
                final double angle = angles[i];
                final long t = (now - start[i]) % 2000000000;
                final double d = t * radius / 2000000000.0;
                node.setTranslateX(Math.cos(angle) * d + width);
                node.setTranslateY(Math.sin(angle) * d + height);
            }
        }
    }.start();
}
Also used : Group(javafx.scene.Group) AnimationTimer(javafx.animation.AnimationTimer) Node(javafx.scene.Node) Rectangle(javafx.scene.shape.Rectangle) Scene(javafx.scene.Scene)

Example 22 with AnimationTimer

use of javafx.animation.AnimationTimer in project tilesfx by HanSolo.

the class Demo method init.

@Override
public void init() {
    value = new SimpleDoubleProperty(0);
    // AreaChart Data
    XYChart.Series<String, Number> series1 = new XYChart.Series();
    series1.setName("Whatever");
    series1.getData().add(new XYChart.Data("MO", 23));
    series1.getData().add(new XYChart.Data("TU", 21));
    series1.getData().add(new XYChart.Data("WE", 20));
    series1.getData().add(new XYChart.Data("TH", 22));
    series1.getData().add(new XYChart.Data("FR", 24));
    series1.getData().add(new XYChart.Data("SA", 22));
    series1.getData().add(new XYChart.Data("SU", 20));
    // LineChart Data
    XYChart.Series<String, Number> series2 = new XYChart.Series();
    series2.setName("Inside");
    series2.getData().add(new XYChart.Data("MO", 8));
    series2.getData().add(new XYChart.Data("TU", 5));
    series2.getData().add(new XYChart.Data("WE", 0));
    series2.getData().add(new XYChart.Data("TH", 2));
    series2.getData().add(new XYChart.Data("FR", 4));
    series2.getData().add(new XYChart.Data("SA", 3));
    series2.getData().add(new XYChart.Data("SU", 5));
    XYChart.Series<String, Number> series3 = new XYChart.Series();
    series3.setName("Outside");
    series3.getData().add(new XYChart.Data("MO", 8));
    series3.getData().add(new XYChart.Data("TU", 5));
    series3.getData().add(new XYChart.Data("WE", 0));
    series3.getData().add(new XYChart.Data("TH", 2));
    series3.getData().add(new XYChart.Data("FR", 4));
    series3.getData().add(new XYChart.Data("SA", 3));
    series3.getData().add(new XYChart.Data("SU", 5));
    // WorldMap Data
    for (int i = 0; i < Country.values().length; i++) {
        double value = RND.nextInt(10);
        Color color;
        if (value > 8) {
            color = Tile.RED;
        } else if (value > 6) {
            color = Tile.ORANGE;
        } else if (value > 4) {
            color = Tile.YELLOW_ORANGE;
        } else if (value > 2) {
            color = Tile.GREEN;
        } else {
            color = Tile.BLUE;
        }
        Country.values()[i].setColor(color);
    }
    // TimeControl Data
    TimeSection timeSection = TimeSectionBuilder.create().start(LocalTime.now().plusSeconds(20)).stop(LocalTime.now().plusHours(1)).color(Tile.GRAY).highlightColor(Tile.RED).build();
    timeSection.setOnTimeSectionEntered(e -> System.out.println("Section ACTIVE"));
    timeSection.setOnTimeSectionLeft(e -> System.out.println("Section INACTIVE"));
    // Weather (You can get a DarkSky API key here: https://darksky.net/dev/ )
    DarkSky darkSky = new DarkSky("YOUR DARKSKY API KEY", Unit.CA, Language.ENGLISH, 51.911858, 7.632815);
    // darkSky.update();
    // BarChart Items
    barChartItem1 = new BarChartItem("Gerrit", 47, Tile.BLUE);
    barChartItem2 = new BarChartItem("Sandra", 43, Tile.RED);
    barChartItem3 = new BarChartItem("Lilli", 12, Tile.GREEN);
    barChartItem4 = new BarChartItem("Anton", 8, Tile.ORANGE);
    barChartItem1.setFormatString("%.1f kWh");
    // LeaderBoard Items
    leaderBoardItem1 = new LeaderBoardItem("Gerrit", 47);
    leaderBoardItem2 = new LeaderBoardItem("Sandra", 43);
    leaderBoardItem3 = new LeaderBoardItem("Lilli", 12);
    leaderBoardItem4 = new LeaderBoardItem("Anton", 8);
    // Chart Data
    chartData1 = new ChartData("Item 1", 24.0, Tile.GREEN);
    chartData2 = new ChartData("Item 2", 10.0, Tile.BLUE);
    chartData3 = new ChartData("Item 3", 12.0, Tile.RED);
    chartData4 = new ChartData("Item 4", 13.0, Tile.YELLOW_ORANGE);
    chartData5 = new ChartData("Item 5", 13.0, Tile.BLUE);
    chartData6 = new ChartData("Item 6", 13.0, Tile.BLUE);
    chartData7 = new ChartData("Item 7", 13.0, Tile.BLUE);
    chartData8 = new ChartData("Item 8", 13.0, Tile.BLUE);
    // ChartData.animated = false;
    smoothChartData1 = new ChartData("Item 1", RND.nextDouble() * 25, Tile.BLUE);
    smoothChartData2 = new ChartData("Item 2", RND.nextDouble() * 25, Tile.BLUE);
    smoothChartData3 = new ChartData("Item 3", RND.nextDouble() * 25, Tile.BLUE);
    smoothChartData4 = new ChartData("Item 4", RND.nextDouble() * 25, Tile.BLUE);
    // Creating Tiles
    percentageTile = TileBuilder.create().skinType(SkinType.PERCENTAGE).prefSize(TILE_WIDTH, TILE_HEIGHT).title("Percentage Tile").unit("\u0025").description("Test").maxValue(60).build();
    clockTile = TileBuilder.create().skinType(SkinType.CLOCK).prefSize(TILE_WIDTH, TILE_HEIGHT).title("Clock Tile").text("Whatever text").dateVisible(true).locale(Locale.US).running(true).build();
    gaugeTile = TileBuilder.create().skinType(SkinType.GAUGE).prefSize(TILE_WIDTH, TILE_HEIGHT).title("Gauge Tile").unit("V").threshold(75).build();
    sparkLineTile = TileBuilder.create().skinType(SkinType.SPARK_LINE).prefSize(TILE_WIDTH, TILE_HEIGHT).title("SparkLine Tile").unit("mb").gradientStops(new Stop(0, Tile.GREEN), new Stop(0.5, Tile.YELLOW), new Stop(1.0, Tile.RED)).strokeWithGradient(true).build();
    // sparkLineTile.valueProperty().bind(value);
    areaChartTile = TileBuilder.create().skinType(SkinType.SMOOTHED_CHART).prefSize(TILE_WIDTH, TILE_HEIGHT).title("SmoothedChart Tile").chartType(ChartType.AREA).smoothing(true).tooltipTimeout(1000).tilesFxSeries(new TilesFXSeries<>(series1, Tile.BLUE, new LinearGradient(0, 0, 0, 1, true, CycleMethod.NO_CYCLE, new Stop(0, Tile.BLUE), new Stop(1, Color.TRANSPARENT)))).build();
    lineChartTile = TileBuilder.create().skinType(SkinType.SMOOTHED_CHART).prefSize(TILE_WIDTH, TILE_HEIGHT).title("SmoothedChart Tile").smoothing(false).series(series2, series3).build();
    highLowTile = TileBuilder.create().skinType(SkinType.HIGH_LOW).prefSize(TILE_WIDTH, TILE_HEIGHT).title("HighLow Tile").unit("\u20AC").description("Test").text("Whatever text").referenceValue(6.7).value(8.2).build();
    timerControlTile = TileBuilder.create().skinType(SkinType.TIMER_CONTROL).prefSize(TILE_WIDTH, TILE_HEIGHT).title("TimerControl Tile").text("Whatever text").secondsVisible(true).dateVisible(true).timeSections(timeSection).running(true).build();
    numberTile = TileBuilder.create().skinType(SkinType.NUMBER).prefSize(TILE_WIDTH, TILE_HEIGHT).title("Number Tile").text("Whatever text").value(13).unit("mb").description("Test").textVisible(true).build();
    textTile = TileBuilder.create().skinType(SkinType.TEXT).prefSize(TILE_WIDTH, TILE_HEIGHT).title("Text Tile").text("Whatever text").description("May the force be with you\n...always").descriptionAlignment(Pos.TOP_LEFT).textVisible(true).build();
    plusMinusTile = TileBuilder.create().skinType(SkinType.PLUS_MINUS).prefSize(TILE_WIDTH, TILE_HEIGHT).maxValue(30).minValue(0).title("PlusMinus Tile").text("Whatever text").description("Test").unit("\u00B0C").build();
    sliderTile = TileBuilder.create().skinType(SkinType.SLIDER).prefSize(TILE_WIDTH, TILE_HEIGHT).title("Slider Tile").text("Whatever text").description("Test").unit("\u00B0C").barBackgroundColor(Tile.FOREGROUND).build();
    switchTile = TileBuilder.create().skinType(SkinType.SWITCH).prefSize(TILE_WIDTH, TILE_HEIGHT).title("Switch Tile").text("Whatever text").build();
    switchTile.setOnSwitchPressed(e -> System.out.println("Switch pressed"));
    switchTile.setOnSwitchReleased(e -> System.out.println("Switch released"));
    worldTile = TileBuilder.create().prefSize(300, TILE_HEIGHT).skinType(SkinType.WORLDMAP).title("WorldMap Tile").text("Whatever text").textVisible(false).build();
    // Update the weather information by calling weatherTile.updateWeather()
    weatherTile = TileBuilder.create().skinType(SkinType.WEATHER).prefSize(TILE_WIDTH, TILE_HEIGHT).title("YOUR CITY NAME").text("Whatever text").darkSky(darkSky).build();
    timeTile = TileBuilder.create().skinType(SkinType.TIME).prefSize(TILE_WIDTH, TILE_HEIGHT).title("Time Tile").text("Whatever text").duration(LocalTime.of(1, 22)).description("Average reply time").textVisible(true).build();
    barChartTile = TileBuilder.create().skinType(SkinType.BAR_CHART).prefSize(TILE_WIDTH, TILE_HEIGHT).title("BarChart Tile").text("Whatever text").barChartItems(barChartItem1, barChartItem2, barChartItem3, barChartItem4).decimals(0).build();
    customTile = TileBuilder.create().skinType(SkinType.CUSTOM).prefSize(TILE_WIDTH, TILE_HEIGHT).title("Custom Tile").text("Whatever text").graphic(new Button("Click Me")).roundedCorners(false).build();
    leaderBoardTile = TileBuilder.create().skinType(SkinType.LEADER_BOARD).prefSize(TILE_WIDTH, TILE_HEIGHT).title("LeaderBoard Tile").text("Whatever text").leaderBoardItems(leaderBoardItem1, leaderBoardItem2, leaderBoardItem3, leaderBoardItem4).build();
    mapTile = TileBuilder.create().skinType(SkinType.MAP).prefSize(TILE_WIDTH, TILE_HEIGHT).title("Map").text("Some text").description("Description").currentLocation(new Location(51.91178, 7.63379, "Home", TileColor.MAGENTA.color)).pointsOfInterest(new Location(51.914405, 7.635732, "POI 1", TileColor.RED.color), new Location(51.912529, 7.631752, "POI 2", TileColor.BLUE.color), new Location(51.923993, 7.628906, "POI 3", TileColor.YELLOW_ORANGE.color)).mapProvider(MapProvider.TOPO).build();
    radialChartTile = TileBuilder.create().skinType(SkinType.RADIAL_CHART).prefSize(TILE_WIDTH, TILE_HEIGHT).title("RadialChart").text("Some text").textVisible(false).chartData(chartData1, chartData2, chartData3, chartData4).build();
    donutChartTile = TileBuilder.create().skinType(SkinType.DONUT_CHART).prefSize(TILE_WIDTH, TILE_HEIGHT).title("DonutChart").text("Some text").textVisible(false).chartData(chartData1, chartData2, chartData3, chartData4).build();
    circularProgressTile = TileBuilder.create().skinType(SkinType.CIRCULAR_PROGRESS).prefSize(TILE_WIDTH, TILE_HEIGHT).title("CircularProgress").text("Some text").unit("\u0025").build();
    stockTile = TileBuilder.create().skinType(SkinType.STOCK).prefSize(TILE_WIDTH, TILE_HEIGHT).title("Stock").minValue(0).maxValue(1000).averagingPeriod(100).build();
    gaugeSparkLineTile = TileBuilder.create().skinType(SkinType.GAUGE_SPARK_LINE).prefSize(TILE_WIDTH, TILE_HEIGHT).title("GaugeSparkLine").animated(true).textVisible(false).averagingPeriod(25).autoReferenceValue(true).barColor(Tile.YELLOW_ORANGE).barBackgroundColor(Color.rgb(255, 255, 255, 0.1)).sections(new eu.hansolo.tilesfx.Section(0, 33, Tile.LIGHT_GREEN), new eu.hansolo.tilesfx.Section(33, 67, Tile.YELLOW), new eu.hansolo.tilesfx.Section(67, 100, Tile.LIGHT_RED)).sectionsVisible(true).highlightSections(true).strokeWithGradient(true).gradientStops(new Stop(0.0, Tile.LIGHT_GREEN), new Stop(0.33, Tile.LIGHT_GREEN), new Stop(0.33, Tile.YELLOW), new Stop(0.67, Tile.YELLOW), new Stop(0.67, Tile.LIGHT_RED), new Stop(1.0, Tile.LIGHT_RED)).build();
    radarChartTile1 = TileBuilder.create().skinType(SkinType.RADAR_CHART).prefSize(TILE_WIDTH, TILE_HEIGHT).minValue(0).maxValue(50).title("RadarChart Sector").unit("Unit").radarChartMode(Mode.SECTOR).gradientStops(new Stop(0.00000, Color.TRANSPARENT), new Stop(0.00001, Color.web("#3552a0")), new Stop(0.09090, Color.web("#456acf")), new Stop(0.27272, Color.web("#45a1cf")), new Stop(0.36363, Color.web("#30c8c9")), new Stop(0.45454, Color.web("#30c9af")), new Stop(0.50909, Color.web("#56d483")), new Stop(0.72727, Color.web("#9adb49")), new Stop(0.81818, Color.web("#efd750")), new Stop(0.90909, Color.web("#ef9850")), new Stop(1.00000, Color.web("#ef6050"))).text("Test").chartData(chartData1, chartData2, chartData3, chartData4, chartData5, chartData6, chartData7, chartData8).tooltipText("").animated(true).build();
    radarChartTile2 = TileBuilder.create().skinType(SkinType.RADAR_CHART).prefSize(TILE_WIDTH, TILE_HEIGHT).minValue(0).maxValue(50).title("RadarChart Polygon").unit("Unit").radarChartMode(Mode.POLYGON).gradientStops(new Stop(0.00000, Color.TRANSPARENT), new Stop(0.00001, Color.web("#3552a0")), new Stop(0.09090, Color.web("#456acf")), new Stop(0.27272, Color.web("#45a1cf")), new Stop(0.36363, Color.web("#30c8c9")), new Stop(0.45454, Color.web("#30c9af")), new Stop(0.50909, Color.web("#56d483")), new Stop(0.72727, Color.web("#9adb49")), new Stop(0.81818, Color.web("#efd750")), new Stop(0.90909, Color.web("#ef9850")), new Stop(1.00000, Color.web("#ef6050"))).text("Test").chartData(chartData1, chartData2, chartData3, chartData4, chartData5, chartData6, chartData7, chartData8).tooltipText("").animated(true).build();
    smoothAreaChartTile = TileBuilder.create().skinType(SkinType.SMOOTH_AREA_CHART).prefSize(TILE_WIDTH, TILE_HEIGHT).minValue(0).maxValue(40).title("SmoothAreaChart").unit("Unit").text("Test").chartData(smoothChartData1, smoothChartData2, smoothChartData3, smoothChartData4).tooltipText("").animated(true).build();
    countryTile = TileBuilder.create().skinType(SkinType.COUNTRY).prefSize(TILE_WIDTH, TILE_HEIGHT).minValue(0).maxValue(40).title("Country").unit("Unit").country(Country.DE).tooltipText("").animated(true).build();
    ephemerisTile = TileBuilder.create().skinType(SkinType.EPHEMERIS).prefSize(TILE_WIDTH, TILE_HEIGHT).title("Ephemeris").currentLocation(new Location(51.911515, 7.6340026, "Hiltrup")).text("Hiltrup").build();
    characterTile = TileBuilder.create().skinType(SkinType.CHARACTER).prefSize(TILE_WIDTH, TILE_HEIGHT).title("Character").titleAlignment(TextAlignment.CENTER).description("G").build();
    flipTile = TileBuilder.create().skinType(SkinType.FLIP).prefSize(TILE_WIDTH, TILE_HEIGHT).characters(Helper.TIME_0_TO_5).flipTimeInMS(500).flipText(" ").build();
    switchSliderTile = TileBuilder.create().skinType(SkinType.SWITCH_SLIDER).prefSize(TILE_WIDTH, TILE_HEIGHT).title("SwitchSlider").text("Test").build();
    dateTile = TileBuilder.create().skinType(SkinType.DATE).prefSize(TILE_WIDTH, TILE_HEIGHT).build();
    ZonedDateTime now = ZonedDateTime.now();
    List<ChartData> calendarData = new ArrayList<>(10);
    calendarData.add(new ChartData("Item 1", now.minusDays(1).toInstant()));
    calendarData.add(new ChartData("Item 2", now.plusDays(2).toInstant()));
    calendarData.add(new ChartData("Item 3", now.plusDays(10).toInstant()));
    calendarData.add(new ChartData("Item 4", now.plusDays(15).toInstant()));
    calendarData.add(new ChartData("Item 5", now.plusDays(15).toInstant()));
    calendarData.add(new ChartData("Item 6", now.plusDays(20).toInstant()));
    calendarData.add(new ChartData("Item 7", now.plusDays(7).toInstant()));
    calendarData.add(new ChartData("Item 8", now.minusDays(1).toInstant()));
    calendarData.add(new ChartData("Item 9", now.toInstant()));
    calendarData.add(new ChartData("Item 10", now.toInstant()));
    calendarTile = TileBuilder.create().skinType(SkinType.CALENDAR).prefSize(TILE_WIDTH, TILE_HEIGHT).chartData(calendarData).build();
    TreeNode tree = new TreeNode(new ChartData("ROOT"));
    TreeNode first = new TreeNode(new ChartData("1st", 8.3, Tile.BLUE), tree);
    TreeNode second = new TreeNode(new ChartData("2nd", 2.2, Tile.ORANGE), tree);
    TreeNode third = new TreeNode(new ChartData("3rd", 1.4, Tile.PINK), tree);
    TreeNode fourth = new TreeNode(new ChartData("4th", 1.2, Tile.LIGHT_GREEN), tree);
    TreeNode jan = new TreeNode(new ChartData("Jan", 3.5), first);
    TreeNode feb = new TreeNode(new ChartData("Feb", 3.1), first);
    TreeNode mar = new TreeNode(new ChartData("Mar", 1.7), first);
    TreeNode apr = new TreeNode(new ChartData("Apr", 1.1), second);
    TreeNode may = new TreeNode(new ChartData("May", 0.8), second);
    TreeNode jun = new TreeNode(new ChartData("Jun", 0.3), second);
    TreeNode jul = new TreeNode(new ChartData("Jul", 0.7), third);
    TreeNode aug = new TreeNode(new ChartData("Aug", 0.6), third);
    TreeNode sep = new TreeNode(new ChartData("Sep", 0.1), third);
    TreeNode oct = new TreeNode(new ChartData("Oct", 0.5), fourth);
    TreeNode nov = new TreeNode(new ChartData("Nov", 0.4), fourth);
    TreeNode dec = new TreeNode(new ChartData("Dec", 0.3), fourth);
    sunburstTile = TileBuilder.create().skinType(SkinType.SUNBURST).prefSize(TILE_WIDTH, TILE_HEIGHT).title("SunburstTile").textVisible(false).sunburstTree(tree).sunburstBackgroundColor(Tile.BACKGROUND).sunburstTextColor(Tile.BACKGROUND).sunburstUseColorFromParent(true).sunburstTextOrientation(TextOrientation.TANGENT).sunburstAutoTextColor(true).sunburstUseChartDataTextColor(true).sunburstInteractive(true).build();
    matrixTile = TileBuilder.create().skinType(SkinType.MATRIX).prefSize(TILE_WIDTH, TILE_HEIGHT).title("MatrixTileSkin").text("Any Text").textVisible(false).animated(true).matrixSize(8, 50).chartData(chartData1, chartData2, chartData3, chartData4, chartData5, chartData6, chartData7, chartData8).build();
    radialPercentageTile = TileBuilder.create().skinType(SkinType.RADIAL_PERCENTAGE).prefSize(TILE_WIDTH, TILE_HEIGHT).backgroundColor(Color.web("#26262D")).maxValue(1000).title("RadialPercentageSkin").description("Product 1").textVisible(false).chartData(chartData1, chartData2, chartData3).animated(true).referenceValue(100).value(chartData1.getValue()).descriptionColor(Tile.GRAY).barColor(Tile.BLUE).decimals(0).build();
    lastTimerCall = System.nanoTime();
    timer = new AnimationTimer() {

        @Override
        public void handle(long now) {
            if (now > lastTimerCall + 3_500_000_000L) {
                percentageTile.setValue(RND.nextDouble() * percentageTile.getRange() * 1.5 + percentageTile.getMinValue());
                gaugeTile.setValue(RND.nextDouble() * gaugeTile.getRange() * 1.5 + gaugeTile.getMinValue());
                sparkLineTile.setValue(RND.nextDouble() * sparkLineTile.getRange() * 1.5 + sparkLineTile.getMinValue());
                // value.set(RND.nextDouble() * sparkLineTile.getRange() * 1.5 + sparkLineTile.getMinValue());
                // sparkLineTile.setValue(20);
                highLowTile.setValue(RND.nextDouble() * 10);
                series1.getData().forEach(data -> data.setYValue(RND.nextInt(100)));
                series2.getData().forEach(data -> data.setYValue(RND.nextInt(30)));
                series3.getData().forEach(data -> data.setYValue(RND.nextInt(10)));
                chartData1.setValue(RND.nextDouble() * 50);
                chartData2.setValue(RND.nextDouble() * 50);
                chartData3.setValue(RND.nextDouble() * 50);
                chartData4.setValue(RND.nextDouble() * 50);
                chartData5.setValue(RND.nextDouble() * 50);
                chartData6.setValue(RND.nextDouble() * 50);
                chartData7.setValue(RND.nextDouble() * 50);
                chartData8.setValue(RND.nextDouble() * 50);
                barChartTile.getBarChartItems().get(RND.nextInt(3)).setValue(RND.nextDouble() * 80);
                leaderBoardTile.getLeaderBoardItems().get(RND.nextInt(3)).setValue(RND.nextDouble() * 80);
                circularProgressTile.setValue(RND.nextDouble() * 120);
                stockTile.setValue(RND.nextDouble() * 50 + 500);
                gaugeSparkLineTile.setValue(RND.nextDouble() * 100);
                countryTile.setValue(RND.nextDouble() * 100);
                smoothChartData1.setValue(smoothChartData2.getValue());
                smoothChartData2.setValue(smoothChartData3.getValue());
                smoothChartData3.setValue(smoothChartData4.getValue());
                smoothChartData4.setValue(RND.nextDouble() * 25);
                characterTile.setDescription(Helper.ALPHANUMERIC[RND.nextInt(Helper.ALPHANUMERIC.length - 1)]);
                flipTile.setFlipText(Helper.TIME_0_TO_5[RND.nextInt(Helper.TIME_0_TO_5.length - 1)]);
                radialPercentageTile.setValue(chartData1.getValue());
                lastTimerCall = now;
            }
        }
    };
}
Also used : Button(javafx.scene.control.Button) DarkSky(eu.hansolo.tilesfx.weather.DarkSky) Pos(javafx.geometry.Pos) Scene(javafx.scene.Scene) Location(eu.hansolo.tilesfx.tools.Location) TreeNode(eu.hansolo.tilesfx.tools.TreeNode) TileColor(eu.hansolo.tilesfx.Tile.TileColor) CycleMethod(javafx.scene.paint.CycleMethod) ZonedDateTime(java.time.ZonedDateTime) BarChartItem(eu.hansolo.tilesfx.skins.BarChartItem) DoubleProperty(javafx.beans.property.DoubleProperty) LinearGradient(javafx.scene.paint.LinearGradient) Random(java.util.Random) Mode(eu.hansolo.tilesfx.chart.RadarChart.Mode) Unit(eu.hansolo.tilesfx.weather.DarkSky.Unit) XYChart(javafx.scene.chart.XYChart) MapProvider(eu.hansolo.tilesfx.Tile.MapProvider) ArrayList(java.util.ArrayList) Application(javafx.application.Application) Parent(javafx.scene.Parent) PerspectiveCamera(javafx.scene.PerspectiveCamera) ChartData(eu.hansolo.tilesfx.chart.ChartData) Insets(javafx.geometry.Insets) Helper(eu.hansolo.tilesfx.tools.Helper) FlowGridPane(eu.hansolo.tilesfx.tools.FlowGridPane) BackgroundFill(javafx.scene.layout.BackgroundFill) Locale(java.util.Locale) TilesFXSeries(eu.hansolo.tilesfx.chart.TilesFXSeries) Country(eu.hansolo.tilesfx.tools.Country) LocalTime(java.time.LocalTime) TextAlignment(javafx.scene.text.TextAlignment) Language(eu.hansolo.tilesfx.weather.DarkSky.Language) TextOrientation(eu.hansolo.tilesfx.chart.SunburstChart.TextOrientation) Color(javafx.scene.paint.Color) ChartType(eu.hansolo.tilesfx.Tile.ChartType) Stop(javafx.scene.paint.Stop) Node(javafx.scene.Node) Background(javafx.scene.layout.Background) AnimationTimer(javafx.animation.AnimationTimer) List(java.util.List) Stage(javafx.stage.Stage) SkinType(eu.hansolo.tilesfx.Tile.SkinType) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) ObservableList(javafx.collections.ObservableList) LeaderBoardItem(eu.hansolo.tilesfx.skins.LeaderBoardItem) CornerRadii(javafx.scene.layout.CornerRadii) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) Stop(javafx.scene.paint.Stop) BarChartItem(eu.hansolo.tilesfx.skins.BarChartItem) ArrayList(java.util.ArrayList) DarkSky(eu.hansolo.tilesfx.weather.DarkSky) Button(javafx.scene.control.Button) ZonedDateTime(java.time.ZonedDateTime) TreeNode(eu.hansolo.tilesfx.tools.TreeNode) ChartData(eu.hansolo.tilesfx.chart.ChartData) AnimationTimer(javafx.animation.AnimationTimer) TileColor(eu.hansolo.tilesfx.Tile.TileColor) Color(javafx.scene.paint.Color) TilesFXSeries(eu.hansolo.tilesfx.chart.TilesFXSeries) LinearGradient(javafx.scene.paint.LinearGradient) XYChart(javafx.scene.chart.XYChart) LeaderBoardItem(eu.hansolo.tilesfx.skins.LeaderBoardItem) Location(eu.hansolo.tilesfx.tools.Location)

Example 23 with AnimationTimer

use of javafx.animation.AnimationTimer in project FXyzLib by Birdasaur.

the class CSVScatter3DTest method start.

@Override
public void start(Stage primaryStage) throws Exception {
    Group sceneRoot = new Group();
    Scene scene = new Scene(sceneRoot, sceneWidth, sceneHeight, true, SceneAntialiasing.BALANCED);
    scene.setFill(Color.BLACK);
    camera = new PerspectiveCamera(true);
    // setup camera transform for rotational support
    cameraTransform.setTranslate(0, 0, 0);
    cameraTransform.getChildren().add(camera);
    camera.setNearClip(0.1);
    camera.setFarClip(10000.0);
    camera.setTranslateX(0);
    camera.setTranslateZ(-1000);
    cameraTransform.ry.setAngle(-25.0);
    cameraTransform.rx.setAngle(-10.0);
    // add a Point Light for better viewing of the grid coordinate system
    PointLight light = new PointLight(Color.WHITE);
    cameraTransform.getChildren().add(new AmbientLight());
    light.setTranslateX(camera.getTranslateX());
    light.setTranslateY(camera.getTranslateY());
    light.setTranslateZ(camera.getTranslateZ());
    scene.setCamera(camera);
    long time = System.currentTimeMillis();
    Group group = new Group(cameraTransform);
    List<Point3D> data = new ArrayList<>();
    // // create some data
    // IntStream.range(0,100000)
    // .forEach(i->data.add(new Point3D((float)(30*Math.sin(50*i)),
    // (float)(Math.sin(i)*(100+30*Math.cos(100*i))),
    // (float)(Math.cos(i)*(100+30*Math.cos(200*i))),
    // i))); // <-- f
    // // and write to csv file
    // Path out = Paths.get("output.txt");
    // Files.write(out,data.stream().map(p3d->p3d.toCSV()).collect(Collectors.toList()),Charset.defaultCharset());
    // read from csv file
    Path out = getCSVFile(0);
    if (out != null) {
        Files.lines(out).map(s -> s.split(";")).forEach(s -> data.add(new Point3D(Float.parseFloat(s[0]), Float.parseFloat(s[1]), Float.parseFloat(s[2]), Float.parseFloat(s[3]))));
    }
    ScatterMesh scatter = new ScatterMesh(data, true, 1, 0);
    // DENSITY
    // texture is given by p.f value, don't change this!
    scatter.setTextureModeVertices3D(1530, p -> p.f);
    group.getChildren().add(scatter);
    sceneRoot.getChildren().addAll(group);
    // First person shooter keyboard movement
    scene.setOnKeyPressed(event -> {
        double change = 10.0;
        // Add shift modifier to simulate "Running Speed"
        if (event.isShiftDown()) {
            change = 50.0;
        }
        // What key did the user press?
        KeyCode keycode = event.getCode();
        // Step 2c: Add Zoom controls
        if (keycode == KeyCode.W) {
            camera.setTranslateZ(camera.getTranslateZ() + change);
        }
        if (keycode == KeyCode.S) {
            camera.setTranslateZ(camera.getTranslateZ() - change);
        }
        // Step 2d:  Add Strafe controls
        if (keycode == KeyCode.A) {
            camera.setTranslateX(camera.getTranslateX() - change);
        }
        if (keycode == KeyCode.D) {
            camera.setTranslateX(camera.getTranslateX() + change);
        }
    });
    scene.setOnMousePressed((MouseEvent me) -> {
        mousePosX = me.getSceneX();
        mousePosY = me.getSceneY();
        mouseOldX = me.getSceneX();
        mouseOldY = me.getSceneY();
    });
    scene.setOnMouseDragged((MouseEvent me) -> {
        mouseOldX = mousePosX;
        mouseOldY = mousePosY;
        mousePosX = me.getSceneX();
        mousePosY = me.getSceneY();
        mouseDeltaX = (mousePosX - mouseOldX);
        mouseDeltaY = (mousePosY - mouseOldY);
        double modifier = 10.0;
        double modifierFactor = 0.1;
        if (me.isControlDown()) {
            modifier = 0.1;
        }
        if (me.isShiftDown()) {
            modifier = 50.0;
        }
        if (me.isPrimaryButtonDown()) {
            // +
            cameraTransform.ry.setAngle(((cameraTransform.ry.getAngle() + mouseDeltaX * modifierFactor * modifier * 2.0) % 360 + 540) % 360 - 180);
            // -
            cameraTransform.rx.setAngle(((cameraTransform.rx.getAngle() - mouseDeltaY * modifierFactor * modifier * 2.0) % 360 + 540) % 360 - 180);
        } else if (me.isSecondaryButtonDown()) {
            double z = camera.getTranslateZ();
            double newZ = z + mouseDeltaX * modifierFactor * modifier;
            camera.setTranslateZ(newZ);
        } else if (me.isMiddleButtonDown()) {
            // -
            cameraTransform.t.setX(cameraTransform.t.getX() + mouseDeltaX * modifierFactor * modifier * 0.3);
            // -
            cameraTransform.t.setY(cameraTransform.t.getY() + mouseDeltaY * modifierFactor * modifier * 0.3);
        }
    });
    primaryStage.setTitle("F(X)yz - ScatterMesh Test");
    primaryStage.setScene(scene);
    primaryStage.show();
    final boolean constantVertices = true;
    lastEffect = System.nanoTime();
    AtomicInteger count = new AtomicInteger(0);
    List<List<Number>> fullData = new ArrayList<>();
    if (constantVertices) {
        // if possible we can cache all the data
        Stream.of(0, 1, 2, 3, 4, 3, 2, 1).forEach(i -> {
            Path out2 = getCSVFile(i);
            if (out2 != null) {
                try {
                    List<Number> data2 = new ArrayList<>();
                    Files.lines(out2).map(s -> s.split(";")).forEach(s -> {
                        float f = Float.parseFloat(s[3]);
                        // 4 vertices tetrahedra
                        data2.add(f);
                        data2.add(f);
                        data2.add(f);
                        data2.add(f);
                    });
                    fullData.add(data2);
                } catch (IOException ex) {
                }
            }
        });
    }
    AnimationTimer timerEffect = new AnimationTimer() {

        @Override
        public void handle(long now) {
            if (now > lastEffect + 50_000_000l) {
                try {
                    // long t=System.currentTimeMillis();
                    if (constantVertices && fullData != null) {
                        // Vertices coordinates are always the same: mesh is tha same, we only
                        // need to update F on each element
                        scatter.setFunctionData(fullData.get(count.get() % 8));
                    // System.out.println("t "+(System.currentTimeMillis()-t));
                    } else {
                        // vertices coordinates may change in time, we need to create them all over again reading the files:
                        Path out2 = getCSVFile((int) (Stream.of(0, 1, 2, 3, 4, 3, 2, 1).toArray()[count.get() % 8]));
                        if (out2 != null) {
                            List<Point3D> data2 = new ArrayList<>();
                            Files.lines(out2).map(s -> s.split(";")).forEach(s -> data2.add(new Point3D(Float.parseFloat(s[0]), Float.parseFloat(s[1]), Float.parseFloat(s[2]), Float.parseFloat(s[3]))));
                            scatter.setScatterData(data2);
                            scatter.setTextureModeVertices1D(1530, p -> p);
                        }
                    // System.out.println("t "+(System.currentTimeMillis()-t));
                    }
                } catch (IOException ex) {
                }
                count.getAndIncrement();
                lastEffect = now;
            }
        }
    };
    timerEffect.start();
}
Also used : Path(java.nio.file.Path) Scene(javafx.scene.Scene) ScatterMesh(org.fxyz.shapes.primitives.ScatterMesh) Palette(org.fxyz.utils.Palette) URISyntaxException(java.net.URISyntaxException) MouseEvent(javafx.scene.input.MouseEvent) PointLight(javafx.scene.PointLight) ArrayList(java.util.ArrayList) Application(javafx.application.Application) PerspectiveCamera(javafx.scene.PerspectiveCamera) CameraTransformer(org.fxyz.cameras.CameraTransformer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Path(java.nio.file.Path) KeyCode(javafx.scene.input.KeyCode) Color(javafx.scene.paint.Color) Files(java.nio.file.Files) IOException(java.io.IOException) Group(javafx.scene.Group) AnimationTimer(javafx.animation.AnimationTimer) List(java.util.List) Stream(java.util.stream.Stream) Stage(javafx.stage.Stage) Paths(java.nio.file.Paths) SceneAntialiasing(javafx.scene.SceneAntialiasing) Point3D(org.fxyz.geometry.Point3D) AmbientLight(javafx.scene.AmbientLight) Group(javafx.scene.Group) MouseEvent(javafx.scene.input.MouseEvent) AnimationTimer(javafx.animation.AnimationTimer) ArrayList(java.util.ArrayList) PerspectiveCamera(javafx.scene.PerspectiveCamera) IOException(java.io.IOException) Scene(javafx.scene.Scene) ScatterMesh(org.fxyz.shapes.primitives.ScatterMesh) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Point3D(org.fxyz.geometry.Point3D) KeyCode(javafx.scene.input.KeyCode) ArrayList(java.util.ArrayList) List(java.util.List) PointLight(javafx.scene.PointLight) AmbientLight(javafx.scene.AmbientLight)

Example 24 with AnimationTimer

use of javafx.animation.AnimationTimer in project FXyzLib by Birdasaur.

the class IcosahedronTest method start.

@Override
public void start(Stage primaryStage) throws Exception {
    Group sceneRoot = new Group();
    Scene scene = new Scene(sceneRoot, sceneWidth, sceneHeight, true, SceneAntialiasing.BALANCED);
    // scene.setFill(Color.BLACK);
    camera = new PerspectiveCamera(true);
    // setup camera transform for rotational support
    cameraTransform.setTranslate(0, 0, 0);
    cameraTransform.getChildren().add(camera);
    camera.setNearClip(0.001);
    camera.setFarClip(10000.0);
    camera.setTranslateZ(-10);
    cameraTransform.ry.setAngle(-45.0);
    cameraTransform.rx.setAngle(-10.0);
    // add a Point Light for better viewing of the grid coordinate system
    // PointLight light = new PointLight(Color.WHITE);
    // cameraTransform.getChildren().add(light);
    // light.setTranslateX(camera.getTranslateX());
    // light.setTranslateY(camera.getTranslateY());
    // light.setTranslateZ(camera.getTranslateZ());
    scene.setCamera(camera);
    rotateY = new Rotate(0, 0, 0, 0, Rotate.Y_AXIS);
    Group group = new Group();
    group.getChildren().add(cameraTransform);
    ico = new IcosahedronMesh(5, 1f);
    // ico.setDrawMode(DrawMode.LINE);
    ico.setCullFace(CullFace.NONE);
    // NONE
    // ico.setTextureModeNone(Color.ROYALBLUE);
    // IMAGE
    // ico.setTextureModeImage(getClass().getResource("res/0ZKMx.png").toExternalForm());
    // PATTERN
    // ico.setTextureModePattern(2d);
    // DENSITY
    ico.setTextureModeVertices3D(1530, dens);
    // FACES
    // ico.setTextureModeFaces(256);
    ico.getTransforms().addAll(new Rotate(30, Rotate.X_AXIS), rotateY);
    group.getChildren().add(ico);
    sceneRoot.getChildren().addAll(group);
    // First person shooter keyboard movement
    scene.setOnKeyPressed(event -> {
        double change = 10.0;
        // Add shift modifier to simulate "Running Speed"
        if (event.isShiftDown()) {
            change = 50.0;
        }
        // What key did the user press?
        KeyCode keycode = event.getCode();
        // Step 2c: Add Zoom controls
        if (keycode == KeyCode.W) {
            camera.setTranslateZ(camera.getTranslateZ() + change);
        }
        if (keycode == KeyCode.S) {
            camera.setTranslateZ(camera.getTranslateZ() - change);
        }
        // Step 2d:  Add Strafe controls
        if (keycode == KeyCode.A) {
            camera.setTranslateX(camera.getTranslateX() - change);
        }
        if (keycode == KeyCode.D) {
            camera.setTranslateX(camera.getTranslateX() + change);
        }
    });
    scene.setOnMousePressed((MouseEvent me) -> {
        mousePosX = me.getSceneX();
        mousePosY = me.getSceneY();
        mouseOldX = me.getSceneX();
        mouseOldY = me.getSceneY();
    });
    scene.setOnMouseDragged((MouseEvent me) -> {
        mouseOldX = mousePosX;
        mouseOldY = mousePosY;
        mousePosX = me.getSceneX();
        mousePosY = me.getSceneY();
        mouseDeltaX = (mousePosX - mouseOldX);
        mouseDeltaY = (mousePosY - mouseOldY);
        double modifier = 10.0;
        double modifierFactor = 0.1;
        if (me.isControlDown()) {
            modifier = 0.1;
        }
        if (me.isShiftDown()) {
            modifier = 50.0;
        }
        if (me.isPrimaryButtonDown()) {
            // +
            cameraTransform.ry.setAngle(((cameraTransform.ry.getAngle() + mouseDeltaX * modifierFactor * modifier * 2.0) % 360 + 540) % 360 - 180);
            // -
            cameraTransform.rx.setAngle(((cameraTransform.rx.getAngle() - mouseDeltaY * modifierFactor * modifier * 2.0) % 360 + 540) % 360 - 180);
        } else if (me.isSecondaryButtonDown()) {
            double z = camera.getTranslateZ();
            double newZ = z + mouseDeltaX * modifierFactor * modifier;
            camera.setTranslateZ(newZ);
        } else if (me.isMiddleButtonDown()) {
            // -
            cameraTransform.t.setX(cameraTransform.t.getX() + mouseDeltaX * modifierFactor * modifier * 0.3);
            // -
            cameraTransform.t.setY(cameraTransform.t.getY() + mouseDeltaY * modifierFactor * modifier * 0.3);
        }
    });
    lastEffect = System.nanoTime();
    AtomicInteger count = new AtomicInteger();
    AnimationTimer timerEffect = new AnimationTimer() {

        @Override
        public void handle(long now) {
            if (now > lastEffect + 100_000_000l) {
                double cont1 = 0.1 + (count.get() % 60) / 10d;
                double cont2 = 0.1 + (count.getAndIncrement() % 30) / 10d;
                // dens = p->(float)(3d*Math.pow(Math.sin(p.phi),2)*Math.pow(Math.abs(Math.cos(p.theta)),cont1)+
                // Math.pow(Math.cos(p.phi),2)*Math.pow(Math.abs(Math.sin(p.theta)),cont2));
                // dens = p->10*cont1*Math.pow(Math.abs(p.x),cont1)*Math.pow(Math.abs(p.y),cont2)*Math.pow(p.z,2);
                double t = count.getAndIncrement() % 10;
                dens = p -> (double) (p.x + t) * (p.y + t) * (p.z + t);
                ico.setDensity(dens);
                // ico.setColors((int)Math.pow(2,count.get()%16));
                // ico.setLevel(count.get()%8);
                // ico.setDiameter(0.5f+10*(float)cont1);
                lastEffect = now;
            }
        }
    };
    Timeline timeline = new Timeline();
    timeline.setCycleCount(Timeline.INDEFINITE);
    timeline.getKeyFrames().add(new KeyFrame(Duration.seconds(50), new KeyValue(rotateY.angleProperty(), 360)));
    primaryStage.setTitle("F(X)yz - Moving Contour Plot Test");
    primaryStage.setScene(scene);
    primaryStage.show();
    timerEffect.start();
// timeline.play();
}
Also used : Group(javafx.scene.Group) MouseEvent(javafx.scene.input.MouseEvent) KeyValue(javafx.animation.KeyValue) Rotate(javafx.scene.transform.Rotate) AnimationTimer(javafx.animation.AnimationTimer) PerspectiveCamera(javafx.scene.PerspectiveCamera) Scene(javafx.scene.Scene) Timeline(javafx.animation.Timeline) IcosahedronMesh(org.fxyz.shapes.primitives.IcosahedronMesh) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KeyFrame(javafx.animation.KeyFrame) KeyCode(javafx.scene.input.KeyCode)

Example 25 with AnimationTimer

use of javafx.animation.AnimationTimer in project FXyzLib by Birdasaur.

the class PrismTest method start.

@Override
public void start(Stage primaryStage) throws Exception {
    Group sceneRoot = new Group();
    Scene scene = new Scene(sceneRoot, sceneWidth, sceneHeight, true, SceneAntialiasing.BALANCED);
    scene.setFill(Color.WHITESMOKE);
    camera = new PerspectiveCamera(true);
    // setup camera transform for rotational support
    cameraTransform.setTranslate(0, 0, 0);
    cameraTransform.getChildren().add(camera);
    camera.setNearClip(0.1);
    camera.setFarClip(10000.0);
    camera.setTranslateZ(-30);
    // cameraTransform.ry.setAngle(-45.0);
    // cameraTransform.rx.setAngle(-10.0);
    // add a Point Light for better viewing of the grid coordinate system
    PointLight light = new PointLight(Color.WHITE);
    cameraTransform.getChildren().add(light);
    light.setTranslateX(camera.getTranslateX());
    light.setTranslateY(camera.getTranslateY());
    light.setTranslateZ(10 * camera.getTranslateZ());
    scene.setCamera(camera);
    rotateY = new Rotate(0, 0, 0, 0, Rotate.Y_AXIS);
    Group group = new Group();
    group.getChildren().add(cameraTransform);
    cylinder = new PrismMesh(2, 5, 4);
    // cylinder = new PrismMesh(0.2,2,3); //,new Point3D(-5,5,0),new Point3D(0,0,5));
    // cylinder.setDrawMode(DrawMode.LINE);
    // SECTION TYPE
    cylinder.setSectionType(TriangleMeshHelper.SectionType.TRIANGLE);
    // NONE
    // cylinder.setTextureModeNone(Color.ROYALBLUE);
    // IMAGE
    // cylinder.setTextureModeImage(getClass().getResource("res/netCylinder.png").toExternalForm());
    cylinder.setTextureModeVertices1D(6, t -> t);
    // cylinder.setColorPalette(ColorPalette.GREEN);
    // DENSITY
    // cylinder.setTextureModeVertices3D(1530,p->(double)p.magnitude());
    // cylinder.setTextureModeVertices3D(1530,p->(double)cylinder.unTransform(p).magnitude());
    // FACES
    // cylinder.setTextureModeFaces(1530);
    cylinder.getTransforms().addAll(new Rotate(0, Rotate.X_AXIS), rotateY);
    group.getChildren().add(cylinder);
    boolean showKnots = true;
    if (showKnots) {
        Sphere s = new Sphere(cylinder.getRadius() / 10d);
        Point3D k0 = cylinder.getAxisOrigin();
        s.getTransforms().add(new Translate(k0.x, k0.y, k0.z));
        s.setMaterial(new PhongMaterial(Color.GREENYELLOW));
        group.getChildren().add(s);
        s = new Sphere(cylinder.getRadius() / 10d);
        Point3D k3 = cylinder.getAxisEnd();
        s.getTransforms().add(new Translate(k3.x, k3.y, k3.z));
        s.setMaterial(new PhongMaterial(Color.ROSYBROWN));
        group.getChildren().add(s);
    }
    sceneRoot.getChildren().addAll(group);
    // First person shooter keyboard movement
    scene.setOnKeyPressed(event -> {
        double change = 10.0;
        // Add shift modifier to simulate "Running Speed"
        if (event.isShiftDown()) {
            change = 50.0;
        }
        // What key did the user press?
        KeyCode keycode = event.getCode();
        // Step 2c: Add Zoom controls
        if (keycode == KeyCode.W) {
            camera.setTranslateZ(camera.getTranslateZ() + change);
        }
        if (keycode == KeyCode.S) {
            camera.setTranslateZ(camera.getTranslateZ() - change);
        }
        // Step 2d:  Add Strafe controls
        if (keycode == KeyCode.A) {
            camera.setTranslateX(camera.getTranslateX() - change);
        }
        if (keycode == KeyCode.D) {
            camera.setTranslateX(camera.getTranslateX() + change);
        }
    });
    scene.setOnMousePressed((MouseEvent me) -> {
        mousePosX = me.getSceneX();
        mousePosY = me.getSceneY();
        mouseOldX = me.getSceneX();
        mouseOldY = me.getSceneY();
    });
    scene.setOnMouseDragged((MouseEvent me) -> {
        mouseOldX = mousePosX;
        mouseOldY = mousePosY;
        mousePosX = me.getSceneX();
        mousePosY = me.getSceneY();
        mouseDeltaX = (mousePosX - mouseOldX);
        mouseDeltaY = (mousePosY - mouseOldY);
        double modifier = 10.0;
        double modifierFactor = 0.1;
        if (me.isControlDown()) {
            modifier = 0.1;
        }
        if (me.isShiftDown()) {
            modifier = 50.0;
        }
        if (me.isPrimaryButtonDown()) {
            // +
            cameraTransform.ry.setAngle(((cameraTransform.ry.getAngle() + mouseDeltaX * modifierFactor * modifier * 2.0) % 360 + 540) % 360 - 180);
            // -
            cameraTransform.rx.setAngle(((cameraTransform.rx.getAngle() - mouseDeltaY * modifierFactor * modifier * 2.0) % 360 + 540) % 360 - 180);
        } else if (me.isSecondaryButtonDown()) {
            double z = camera.getTranslateZ();
            double newZ = z + mouseDeltaX * modifierFactor * modifier;
            camera.setTranslateZ(newZ);
        } else if (me.isMiddleButtonDown()) {
            // -
            cameraTransform.t.setX(cameraTransform.t.getX() + mouseDeltaX * modifierFactor * modifier * 0.3);
            // -
            cameraTransform.t.setY(cameraTransform.t.getY() + mouseDeltaY * modifierFactor * modifier * 0.3);
        }
    });
    primaryStage.setTitle("F(X)yz - Cylinder Test");
    primaryStage.setScene(scene);
    primaryStage.show();
    // OBJWriter writer=new OBJWriter((TriangleMesh) cylinder.getMesh(),"cylinder2");
    // //        writer.setMaterialColor(Color.AQUA);
    // //        writer.setTextureImage(getClass().getResource("res/netCylinder.png").toExternalForm());
    // writer.setTextureColors(6,ColorPalette.GREEN);
    // writer.exportMesh();
    lastEffect = System.nanoTime();
    AtomicInteger count = new AtomicInteger(0);
    AnimationTimer timerEffect = new AnimationTimer() {

        @Override
        public void handle(long now) {
            if (now > lastEffect + 100_000_000l) {
                // <=1/6d)?1d:0d;
                func = t -> Math.pow(Math.sin(8d * Math.PI * (10d * (1 - t.doubleValue()) + count.get() % 11) / 20d), 6);
                // cylinder.setFunction(func);
                // mapBez.values().forEach(b->b.setDensity(dens));
                count.getAndIncrement();
                lastEffect = now;
            }
        }
    };
// timerEffect.start();
}
Also used : Group(javafx.scene.Group) MouseEvent(javafx.scene.input.MouseEvent) Rotate(javafx.scene.transform.Rotate) AnimationTimer(javafx.animation.AnimationTimer) PerspectiveCamera(javafx.scene.PerspectiveCamera) Scene(javafx.scene.Scene) Sphere(javafx.scene.shape.Sphere) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PrismMesh(org.fxyz.shapes.primitives.PrismMesh) Point3D(org.fxyz.geometry.Point3D) KeyCode(javafx.scene.input.KeyCode) PointLight(javafx.scene.PointLight) PhongMaterial(javafx.scene.paint.PhongMaterial) Translate(javafx.scene.transform.Translate)

Aggregations

AnimationTimer (javafx.animation.AnimationTimer)52 Scene (javafx.scene.Scene)17 Group (javafx.scene.Group)15 PerspectiveCamera (javafx.scene.PerspectiveCamera)15 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)14 KeyCode (javafx.scene.input.KeyCode)14 MouseEvent (javafx.scene.input.MouseEvent)14 PointLight (javafx.scene.PointLight)13 Rotate (javafx.scene.transform.Rotate)11 Point3D (org.fxyz.geometry.Point3D)8 Section (eu.hansolo.enzo.common.Section)7 AmbientLight (javafx.scene.AmbientLight)7 Color (javafx.scene.paint.Color)7 ArrayList (java.util.ArrayList)6 KeyFrame (javafx.animation.KeyFrame)5 KeyValue (javafx.animation.KeyValue)5 Timeline (javafx.animation.Timeline)5 Stage (javafx.stage.Stage)5 OBJWriter (org.fxyz.utils.OBJWriter)5 Random (java.util.Random)4