-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add EventStreams.animationTicks() and FPSDemo.
- Loading branch information
1 parent
b136ffe
commit 92c5306
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.reactfx.demo; | ||
import javafx.application.Application; | ||
import javafx.scene.Scene; | ||
import javafx.scene.control.Label; | ||
import javafx.scene.layout.StackPane; | ||
import javafx.stage.Stage; | ||
|
||
import org.reactfx.EventStreams; | ||
|
||
public class FPSDemo extends Application { | ||
|
||
@Override | ||
public void start(Stage primaryStage) { | ||
Label label = new Label(); | ||
|
||
EventStreams.animationTicks() | ||
.latestN(100) | ||
.map(ticks -> { | ||
int n = ticks.size() - 1; | ||
return n * 1_000_000_000.0 / (ticks.get(n) - ticks.get(0)); | ||
}) | ||
.map(d -> String.format("FPS: %.3f", d)) | ||
.feedTo(label.textProperty()); | ||
|
||
primaryStage.setScene(new Scene(new StackPane(label), 250, 150)); | ||
primaryStage.show(); | ||
} | ||
|
||
public static void main(String[] args) { | ||
launch(args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters