Skip to content

Commit

Permalink
Change to dark color theme. Should probably depend on WPIRoboticsProj…
Browse files Browse the repository at this point in the history
…ects#832

Small improvements to hex grid placement, no more weird boders
  • Loading branch information
SamCarlberg committed Mar 30, 2017
1 parent d96bc87 commit 89e0367
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@

import javafx.animation.Animation;
import javafx.animation.FillTransition;
import javafx.application.Platform;
import javafx.application.Preloader;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.util.Duration;

public final class GripPreloader extends Preloader {

private static final Color primaryColor = Color.color(0.5, 0.8, 0.5);
private static final Color secondaryColor = primaryColor.deriveColor(1, 1, 0.75, 1);
private static final Color primaryColor = Color.gray(0.075);
private static final Color secondaryColor = Color.gray(0.1);

// Animation timings
private static final double minTime = 0.25;
private static final double maxTime = 0.50;
private static final double minTime = 1 / 3.0;
private static final double maxTime = 2 / 3.0;

private static final double HEXAGON_RADIUS = 16;
private static final double HEXAGON_RADIUS = 12;

private Stage preloaderStage;

Expand All @@ -37,35 +37,32 @@ public static void main(String[] args) {
public void start(Stage preloaderStage) throws IOException {
final StackPane root = FXMLLoader.load(GripPreloader.class.getResource("Preloader.fxml"));

Screen screen = Screen.getPrimary();

// Animated hexagon grid background

Random random = new Random(System.currentTimeMillis() ^ (System.currentTimeMillis() >> 16));
HexagonGrid hexagonGrid = new HexagonGrid(
(int) ((screen.getBounds().getWidth() / 4) / HEXAGON_RADIUS),
(int) ((screen.getBounds().getHeight() / 4) / HEXAGON_RADIUS),
HEXAGON_RADIUS,
2);
// animate the hexagons
hexagonGrid.hexagons()
.stream()
.map(h -> new FillTransition(
Duration.seconds(
clamp(random.nextGaussian() + 1, 0, 2) * (maxTime - minTime) + minTime),
h, primaryColor, secondaryColor))
.peek(t -> t.setCycleCount(Animation.INDEFINITE))
.peek(t -> t.setAutoReverse(true))
.forEach(t -> t.playFrom(Duration.seconds(random.nextDouble() * maxTime * 16)));
Pane backgroundContainer = new Pane(hexagonGrid);

// bring the hexagons to the top and left edges to avoid weird blank spots
hexagonGrid.setTranslateX(-HEXAGON_RADIUS * 2);
hexagonGrid.setTranslateY(-HEXAGON_RADIUS * 2);

// make the background as small as possible (avoids whitespace on bottom and right edges)
backgroundContainer.setPrefSize(0, 0);
root.getChildren().add(0, backgroundContainer);
// wrap in runLater so we can get the size of the scene
Platform.runLater(() -> {
Random random = new Random(System.currentTimeMillis() ^ (System.currentTimeMillis() >> 16));
HexagonGrid hexagonGrid = new HexagonGrid(
(int) (preloaderStage.getScene().getWidth() / HEXAGON_RADIUS),
(int) (preloaderStage.getScene().getHeight() / HEXAGON_RADIUS),
HEXAGON_RADIUS,
0);
// animate the hexagons
hexagonGrid.hexagons()
.stream()
.map(h -> new FillTransition(
Duration.seconds(
clamp(random.nextGaussian() + 1, 0, 2) * (maxTime - minTime) + minTime),
h, primaryColor, secondaryColor))
.peek(t -> t.setCycleCount(Animation.INDEFINITE))
.peek(t -> t.setAutoReverse(true))
.forEach(t -> t.playFrom(Duration.seconds(random.nextDouble() * maxTime * 16)));
Pane backgroundContainer = new Pane(hexagonGrid);

// bring the hexagons to the top edge to avoid weird blank spots
backgroundContainer.setTranslateY(-HEXAGON_RADIUS);

root.getChildren().add(0, backgroundContainer);
});

Scene scene = new Scene(root);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.root {
-fx-padding: 25;
-fx-background-color: darkseagreen;
-fx-background-color: #111111;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<?import javafx.scene.layout.VBox?>
<?import javafx.stage.Screen?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.geometry.Insets?>
<StackPane id="root" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1">
<children>
<VBox alignment="CENTER">
Expand All @@ -17,6 +18,9 @@
<Screen fx:factory="getPrimary" fx:id="screen"/>
</fx:define>
</ImageView>
<padding>
<Insets topRightBottomLeft="25"/>
</padding>
</VBox>
</children>
<stylesheets>
Expand Down

0 comments on commit 89e0367

Please sign in to comment.