use of javafx.scene.input.MouseEvent in project Malai by arnobl.
the class BaseJfXInteractionTest method createMouseDragEvent.
static MouseEvent createMouseDragEvent(final double x, final double y, final MouseButton button, final Node srcObj) {
final PickResult res = Mockito.mock(PickResult.class);
Mockito.when(res.getIntersectedNode()).thenReturn(srcObj);
Mockito.when(res.getIntersectedPoint()).thenReturn(new Point3D(x, y, 0d));
return new MouseEvent(MouseEvent.MOUSE_DRAGGED, x, y, 0d, 0d, button, 1, false, false, false, false, false, false, false, true, false, false, res);
}
use of javafx.scene.input.MouseEvent in project BachelorPraktikum by lucasbuschlinger.
the class ConflictViewController method onMouseClickedActivity.
/**
* Event handler for mouse clicks.
* @param event - event sent by the mouse click
*/
@FXML
private void onMouseClickedActivity(final MouseEvent event) {
selectedActivityKey = (conflictedActivities.keySet().toArray())[conflictedActivitiesListView.getSelectionModel().getSelectedIndex()];
places = conflictedActivities.get(selectedActivityKey);
List<String> values = places.stream().map(p -> p.name).collect(Collectors.toList());
conflictedLocationsListView.setItems(FXCollections.observableList(values));
StringBuilder urlBuilder = new StringBuilder("https://maps.googleapis.com/maps/api/staticmap?zoom=18&size=400x500&maptype=roadmap");
List<String> colors = new ArrayList<>();
colors.addAll(Arrays.asList("blue", "green", "red", "yellow"));
urlBuilder.append("¢er=").append(places.get(0).geometry.location.lat).append(",").append(places.get(0).geometry.location.lng);
for (int i = 0; i < places.size(); i++) {
urlBuilder.append("&markers=color:").append(colors.get(i % colors.size()));
urlBuilder.append("%7Clabel:").append(places.get(i).name.substring(0, 1));
urlBuilder.append("%7C").append(places.get(i).geometry.location.lat).append(",").append(places.get(i).geometry.location.lng);
}
urlBuilder.append("&key=").append(Credentials.getInstance().getAPIKey());
WebEngine webEngine = conflictedLocationWebView.getEngine();
webEngine.load(urlBuilder.toString());
}
use of javafx.scene.input.MouseEvent in project Minesweeper3D by SethDamiani.
the class Main method start.
@Override
public void start(Stage primaryStage) throws Exception {
// Main JavaFX method
// Add all sides into the cube group
cube.getChildren().addAll(sideA, sideB, sideC, sideD, sideE, sideF);
// Set proper layout
cube.setLayoutX(150);
cube.setLayoutY(190);
// Create the main cube object
createCube(cube, gX, gY, game, primaryStage);
// Properly nest cube rotation control groups
gameRoot.getChildren().add(gY);
// ||
gY.getChildren().add(gX);
// ||
gX.getChildren().add(cube);
stopwatch.setFont(new Font(45));
bombs.setFont(new Font(45));
gameRoot.getChildren().addAll(stopwatch, bombs);
timeTask = new Timeline(new KeyFrame(Duration.seconds(1), event -> {
// Task to keep track of time
time++;
stopwatch.setText("Time: " + String.valueOf(time));
}));
// Make timeTask run forever and ever
timeTask.setCycleCount(Timeline.INDEFINITE);
for (int x = 0; x < Grid.length; x++) {
// Add the cells to their proper side groups
for (int y = 0; y < Grid[x].length; y++) {
for (int z = 0; z < Grid[x][y].length; z++) {
Grid[x][y][z] = new Cell(cube, 40, 40 * y, 40 * z, x);
switch(x) {
case 0:
sideA.getChildren().add(Grid[x][y][z].cell);
break;
case 1:
sideB.getChildren().add(Grid[x][y][z].cell);
break;
case 2:
sideC.getChildren().add(Grid[x][y][z].cell);
break;
case 3:
sideD.getChildren().add(Grid[x][y][z].cell);
break;
case 4:
sideE.getChildren().add(Grid[x][y][z].cell);
break;
case 5:
sideF.getChildren().add(Grid[x][y][z].cell);
break;
}
}
}
}
// Place bombs randomly
placeBombs(100);
// Place the correct numbers according to the new bomb positions
placeNumbers();
// -------------------------------------------------------------------------------
// Confirm Exit screen setup
// new Color(1,1,1,.5)
Text confirmExitText = new Text("Quit");
confirmExitText.setFill(Color.WHITE);
confirmExitText.setFont(Font.font(80));
confirmExitText.setX(400 - confirmExitText.getLayoutBounds().getWidth() / 2);
confirmExitText.setY(200);
Text confirmExitSubText = new Text("Are you sure you would like to quit to the main menu?\nAll progress will be lost.");
confirmExitSubText.setFill(Color.WHITE);
confirmExitSubText.setFont(Font.font(20));
confirmExitSubText.setTextAlignment(TextAlignment.CENTER);
confirmExitSubText.setX(400 - confirmExitSubText.getLayoutBounds().getWidth() / 2);
confirmExitSubText.setY(300);
Text confirmExitYesText = new Text("Yes");
confirmExitYesText.setFont(Font.font(30));
confirmExitYesText.setFill(Color.WHITE);
confirmExitYesText.setX(300 - confirmExitYesText.getLayoutBounds().getWidth() / 2);
confirmExitYesText.setY(500);
Rectangle confirmExitYesButton = new Rectangle(confirmExitYesText.getBoundsInLocal().getMinX() - 20, confirmExitYesText.getBoundsInLocal().getMinY() - 20, confirmExitYesText.getLayoutBounds().getWidth() + 40, confirmExitYesText.getLayoutBounds().getHeight() + 40);
confirmExitYesButton.setFill(Color.TRANSPARENT);
confirmExitYesButton.setStroke(Color.WHITE);
confirmExitYesButton.setStrokeWidth(10);
confirmExitYesButton.setOnMouseEntered(event -> confirmExitYesButton.setFill(new Color(1, 1, 1, .5)));
confirmExitYesButton.setOnMouseExited(event -> confirmExitYesButton.setFill(Color.TRANSPARENT));
confirmExitYesText.setOnMouseEntered(event -> confirmExitYesButton.setFill(new Color(1, 1, 1, .5)));
confirmExitYesText.setOnMouseExited(event -> confirmExitYesButton.setFill(Color.TRANSPARENT));
confirmExitYesButton.setOnMouseClicked(event -> primaryStage.setScene(menu));
confirmExitYesText.setOnMouseClicked(event -> primaryStage.setScene(menu));
Text confirmExitNoText = new Text("No");
confirmExitNoText.setFont(Font.font(30));
confirmExitNoText.setFill(Color.WHITE);
confirmExitNoText.setX(500 - confirmExitYesText.getLayoutBounds().getWidth() / 2);
confirmExitNoText.setY(500);
Rectangle confirmExitNoButton = new Rectangle(confirmExitNoText.getBoundsInLocal().getMinX() - 20, confirmExitNoText.getBoundsInLocal().getMinY() - 20, confirmExitNoText.getLayoutBounds().getWidth() + 40, confirmExitNoText.getLayoutBounds().getHeight() + 40);
confirmExitNoButton.setFill(Color.TRANSPARENT);
confirmExitNoButton.setStroke(Color.WHITE);
confirmExitNoButton.setStrokeWidth(10);
confirmExitNoButton.setOnMouseEntered(event -> confirmExitNoButton.setFill(new Color(1, 1, 1, .5)));
confirmExitNoButton.setOnMouseExited(event -> confirmExitNoButton.setFill(Color.TRANSPARENT));
confirmExitNoText.setOnMouseEntered(event -> confirmExitNoButton.setFill(new Color(1, 1, 1, .5)));
confirmExitNoText.setOnMouseExited(event -> confirmExitNoButton.setFill(Color.TRANSPARENT));
confirmExitNoButton.setOnMouseClicked(event -> {
timeTask.play();
primaryStage.setScene(game);
});
confirmExitNoText.setOnMouseClicked(event -> {
timeTask.play();
primaryStage.setScene(game);
});
confirmExitRoot.getChildren().addAll(confirmExitText, confirmExitSubText, confirmExitYesText, confirmExitNoText, confirmExitYesButton, confirmExitNoButton);
// Quit screen UI setup
// Initialize and configure background
Rectangle quitBox = new Rectangle(800, 700, Color.INDIANRED);
// Initialize and configure the title
Text quitText = new Text(260, 200, "Game Over");
quitText.setFont(new Font(80));
quitText.setStroke(Color.WHITE);
quitText.setFill(Color.WHITE);
quitText.setTextAlignment(TextAlignment.CENTER);
quitText.setX(400 - quitText.getLayoutBounds().getWidth() / 2);
// Initialize and configure the time text
Text endScoreText = new Text(260, 320, "Time: ");
endScoreText.setFont(new Font(40));
endScoreText.setTextAlignment(TextAlignment.CENTER);
endScoreText.setFill(Color.WHITE);
endScoreText.setStroke(Color.WHITE);
// Center the text within the button
endScoreText.setX(350 - endScoreText.getLayoutBounds().getWidth() / 2);
// Initialize and configure first name input field
TextField firstNameInput = new TextField();
firstNameInput.setFont(new Font(24));
// Initialize and configure first name input label
Text firstNameLabel = new Text("First name: ");
firstNameLabel.setFont(new Font(28));
firstNameLabel.setFill(Color.WHITE);
// Initialize and configure horizontal box for first name input
HBox firstNameBox = new HBox(5, firstNameLabel, firstNameInput);
firstNameBox.setLayoutX(180);
firstNameBox.setLayoutY(395);
// Initialize and configure last name input field
TextField lastNameInput = new TextField();
lastNameInput.setFont(new Font(24));
// Initialize and configure last name input label
Text lastNameLabel = new Text("Last name: ");
lastNameLabel.setFont(new Font(28));
lastNameLabel.setFill(Color.WHITE);
// Initialize and configure horizontal box for last name input
HBox lastNameBox = new HBox(5, lastNameLabel, lastNameInput);
lastNameBox.setLayoutX(182);
lastNameBox.setLayoutY(450);
// Initialize and configure continue button border
Rectangle continueRect = new Rectangle(300, 550, 500, 70);
continueRect.setStroke(Color.WHITE);
continueRect.setFill(Color.TRANSPARENT);
continueRect.setStrokeWidth(5);
// Initialize and configure continue button text
Text continueText = new Text("Submit and Continue");
continueText.setFont(new Font(50));
continueText.setFill(Color.WHITE);
continueText.setY(600);
continueText.setX(400 - continueText.getLayoutBounds().getWidth() / 2);
continueRect.setWidth(continueText.getLayoutBounds().getWidth() + 40);
continueRect.setX(400 - continueRect.getLayoutBounds().getWidth() / 2);
// Advance to next field on enter press
firstNameInput.setOnAction(event -> lastNameInput.requestFocus());
game.addEventHandler(KeyEvent.KEY_PRESSED, event -> {
// Manual game-win override
if (event.getCode() == KeyCode.BACK_SLASH && event.isAltDown()) {
gameWon = true;
endScoreText.setText("Time: " + time);
endScoreText.setX(400 - endScoreText.getLayoutBounds().getWidth() / 2);
game.getOnMouseClicked().handle(mouseEvent);
}
});
lastNameInput.setOnAction(event -> {
// Submit score when enter is pressed in last name entry
if (gameWon) {
String firstName = firstNameInput.getText();
String lastName = lastNameInput.getText();
Long date = System.currentTimeMillis() / 1000;
highScoresMap.put(date, new HighScore(date, difficulty, firstName, lastName, time));
refreshTableData();
try {
writeHighScores();
} catch (IOException e) {
System.out.println("ERROR: couldn't save high scores to file.");
}
}
primaryStage.setScene(menu);
});
quitRoot.getChildren().addAll(quitBox, quitText, endScoreText, firstNameBox, lastNameBox, continueRect, continueText);
EventHandler<MouseEvent> submitScores = event -> {
// Process new high score data into table and .csv
if (gameWon) {
String firstName = firstNameInput.getText();
String lastName = lastNameInput.getText();
Long date = System.currentTimeMillis() / 1000;
highScoresMap.put(date, new HighScore(date, difficulty, firstName, lastName, time));
refreshTableData();
try {
writeHighScores();
} catch (IOException e) {
System.out.println("ERROR: couldn't save high scores to file.");
}
}
primaryStage.setScene(menu);
};
continueRect.addEventHandler(MouseEvent.MOUSE_CLICKED, submitScores);
continueText.addEventHandler(MouseEvent.MOUSE_CLICKED, submitScores);
// Pause screen UI setup
Rectangle pauseBox = new Rectangle(800, 700, Color.BLACK);
Text pauseText = new Text(260, 350, "Paused");
pauseText.setFont(new Font(80));
pauseText.setStroke(Color.WHITE);
pauseText.setFill(Color.WHITE);
pauseText.setTextAlignment(TextAlignment.CENTER);
Text timeText = new Text(260, 430, "Time: ");
timeText.setFont(new Font(40));
timeText.setTextAlignment(TextAlignment.CENTER);
timeText.setFill(Color.WHITE);
timeText.setStroke(Color.WHITE);
timeText.setX(250 - timeText.getLayoutBounds().getWidth() / 2);
Text bombsText = new Text(550, 430, bombs.getText());
bombsText.setFont(new Font(40));
bombsText.setTextAlignment(TextAlignment.CENTER);
bombsText.setFill(Color.WHITE);
bombsText.setStroke(Color.WHITE);
bombsText.setX(500 - bombsText.getLayoutBounds().getWidth() / 2);
Text infoText = new Text("Loading");
infoText.setFont(new Font(40));
infoText.setTextAlignment(TextAlignment.CENTER);
infoText.setFill(Color.WHITE);
infoText.setStroke(Color.WHITE);
infoText.setX(400 - infoText.getLayoutBounds().getWidth() / 2);
infoText.setY(430);
Rectangle resume = new Rectangle(300, 500, 200, 70);
resume.setFill(Color.TRANSPARENT);
resume.setStroke(Color.WHITE);
resume.setStrokeWidth(5);
Text resumeText = new Text("Resume");
resumeText.setFont(new Font(50));
resumeText.setFill(Color.WHITE);
resumeText.setY(550);
resumeText.setX(400 - resumeText.getLayoutBounds().getWidth() / 2);
pauseRoot.getChildren().addAll(pauseBox, pauseText, resume, resumeText, infoText);
EventHandler<MouseEvent> resumeButton = event -> {
timeTask.play();
primaryStage.setScene(game);
};
resume.addEventHandler(MouseEvent.MOUSE_CLICKED, resumeButton);
resumeText.addEventHandler(MouseEvent.MOUSE_CLICKED, resumeButton);
pause.setOnKeyPressed(event -> {
if (event.getCode() == KeyCode.SPACE) {
primaryStage.setScene(game);
timeTask.play();
} else if (event.getCode() == KeyCode.ESCAPE) {
primaryStage.setScene(confirmExit);
// primaryStage.close();
}
});
game.setOnKeyPressed(event -> {
if (event.getCode() == KeyCode.SPACE) {
timeTask.pause();
infoText.setText("Time: " + time + "s Bombs: " + flaggedCells + "/" + totalBombs);
infoText.setX(400 - infoText.getLayoutBounds().getWidth() / 2);
primaryStage.setScene(pause);
}
});
// High scores UI setup
scores.setFill(new ImagePattern(bg));
Text scoresTitle = new Text(120, 120, "High Scores");
scoresRoot.getChildren().add(scoresTitle);
scoresTitle.setFont(new Font(70));
scoresTitle.setStroke(Color.BLACK);
scoresTitle.setStrokeWidth(5);
scoresTitle.setTextAlignment(TextAlignment.CENTER);
scoresTitle.setX(400 - scoresTitle.getLayoutBounds().getWidth() / 2);
Rectangle back = new Rectangle(100, 550, 200, 70);
back.setFill(Color.TRANSPARENT);
back.setStroke(Color.BLACK);
back.setStrokeWidth(5);
back.setFill(new Color(1, 1, 1, .5));
back.setOnMouseEntered(event -> back.setFill(new Color(1, 1, 1, .8)));
back.setOnMouseExited(event -> back.setFill(new Color(1, 1, 1, .5)));
scoresRoot.getChildren().add(back);
Text backText = new Text("Back");
backText.setFont(new Font(50));
backText.setFill(Color.BLACK);
backText.setY(600);
backText.setX(200 - backText.getLayoutBounds().getWidth() / 2);
backText.setStroke(Color.BLACK);
backText.setStrokeWidth(3);
backText.setOnMouseEntered(event -> back.setFill(new Color(1, 1, 1, .8)));
backText.setOnMouseExited(event -> back.setFill(new Color(1, 1, 1, .5)));
scoresRoot.getChildren().add(backText);
EventHandler<MouseEvent> backButton = event -> primaryStage.setScene(menu);
back.addEventHandler(MouseEvent.MOUSE_CLICKED, backButton);
backText.addEventHandler(MouseEvent.MOUSE_CLICKED, backButton);
Rectangle deleteScore = new Rectangle(500, 550, 200, 70);
deleteScore.setFill(Color.TRANSPARENT);
deleteScore.setStroke(Color.BLACK);
deleteScore.setStrokeWidth(5);
deleteScore.setFill(new Color(1, 1, 1, .5));
deleteScore.setOnMouseEntered(event -> deleteScore.setFill(new Color(1, 1, 1, .8)));
deleteScore.setOnMouseExited(event -> deleteScore.setFill(new Color(1, 1, 1, .5)));
scoresRoot.getChildren().add(deleteScore);
Text deleteScoresText = new Text("Delete");
deleteScoresText.setFont(new Font(50));
deleteScoresText.setFill(Color.BLACK);
deleteScoresText.setY(600);
deleteScoresText.setX(600 - deleteScoresText.getLayoutBounds().getWidth() / 2);
deleteScoresText.setStroke(Color.BLACK);
deleteScoresText.setStrokeWidth(3);
deleteScoresText.setOnMouseEntered(event -> deleteScore.setFill(new Color(1, 1, 1, .8)));
deleteScoresText.setOnMouseExited(event -> deleteScore.setFill(new Color(1, 1, 1, .5)));
scoresRoot.getChildren().add(deleteScoresText);
EventHandler<MouseEvent> deleteScoreButton = event -> {
// Delete selected high score from table and .csv
if (table.getSelectionModel().getSelectedIndex() == -1)
return;
HighScore current = (HighScore) table.getSelectionModel().getSelectedItem();
highScoresMap.remove(Long.parseLong(current.getRawID()));
refreshTableData();
try {
writeHighScores();
} catch (IOException e) {
System.out.println("ERROR: couldn't save high scores to file.");
}
};
deleteScore.addEventHandler(MouseEvent.MOUSE_CLICKED, deleteScoreButton);
deleteScoresText.addEventHandler(MouseEvent.MOUSE_CLICKED, deleteScoreButton);
CheckBox editable = new CheckBox("Edit mode");
editable.setSelected(true);
editable.setLayoutX(630);
editable.setLayoutY(30);
editable.setFont(Font.font("Tahoma", FontWeight.BLACK, 18));
scoresRoot.getChildren().add(editable);
// High scores table setup
table = new TableView();
table.setLayoutX(100);
table.setLayoutY(200);
table.setPrefWidth(600);
table.setPrefHeight(300);
table.setEditable(true);
EventHandler<TableColumn.CellEditEvent> fieldEditCommit = event -> {
if (table.getSelectionModel().getSelectedIndex() == -1)
return;
HighScore current = (HighScore) table.getSelectionModel().getSelectedItem();
switch(event.getTableColumn().getId()) {
case "Difficulty":
highScoresMap.get(Long.parseLong(current.getRawID())).setDifficulty((String) event.getNewValue());
break;
case "First Name":
highScoresMap.get(Long.parseLong(current.getRawID())).setFirstName((String) event.getNewValue());
break;
case "Last Name":
highScoresMap.get(Long.parseLong(current.getRawID())).setLastName((String) event.getNewValue());
break;
}
try {
writeHighScores();
} catch (IOException e) {
System.out.println("Error saving scores");
}
refreshTableData();
};
table.setStyle(".list-view .scroll-bar:horizontal .increment-arrow,.list-view .scroll-bar:horizontal .decrement-arrow,.list-view .scroll-bar:horizontal .increment-button,.list-view .scroll-bar:horizontal .decrement-button {-fx-padding:0;}");
IDCol.setCellValueFactory(new PropertyValueFactory<HighScore, String>("ID"));
IDCol.prefWidthProperty().bind(table.widthProperty().multiply(0.3));
IDCol.setId("ID");
IDCol.setSortable(false);
IDCol.setResizable(false);
difficultyCol.setCellValueFactory(new PropertyValueFactory<HighScore, String>("difficulty"));
difficultyCol.setCellFactory(TextFieldTableCell.forTableColumn());
difficultyCol.setOnEditCommit(fieldEditCommit);
difficultyCol.prefWidthProperty().bind(table.widthProperty().multiply(0.175));
difficultyCol.setId("Difficulty");
difficultyCol.setSortable(false);
difficultyCol.setResizable(false);
firstNameCol.setCellValueFactory(new PropertyValueFactory<HighScore, String>("firstName"));
firstNameCol.setCellFactory(TextFieldTableCell.forTableColumn());
firstNameCol.setOnEditCommit(fieldEditCommit);
firstNameCol.prefWidthProperty().bind(table.widthProperty().multiply(0.175));
firstNameCol.setId("First Name");
firstNameCol.setSortable(false);
firstNameCol.setResizable(false);
lastNameCol.setCellValueFactory(new PropertyValueFactory<HighScore, String>("lastName"));
lastNameCol.setCellFactory(TextFieldTableCell.forTableColumn());
lastNameCol.setOnEditCommit(fieldEditCommit);
lastNameCol.prefWidthProperty().bind(table.widthProperty().multiply(0.175));
lastNameCol.setId("Last Name");
lastNameCol.setSortable(false);
lastNameCol.setResizable(false);
timeCol.setCellValueFactory(new PropertyValueFactory<HighScore, String>("time"));
timeCol.prefWidthProperty().bind(table.widthProperty().multiply(0.172));
timeCol.setId("Time");
timeCol.setSortable(true);
timeCol.setResizable(false);
table.getSortOrder().setAll(timeCol);
timeCol.setSortType(TableColumn.SortType.ASCENDING);
table.getColumns().addAll(IDCol, difficultyCol, firstNameCol, lastNameCol, timeCol);
table.setOnMousePressed(event -> table.getSortOrder().setAll(timeCol));
MenuItem tableDelete = new MenuItem("Delete");
tableDelete.setOnAction(event -> {
if (table.getSelectionModel().getSelectedIndex() == -1)
return;
HighScore current = (HighScore) table.getSelectionModel().getSelectedItem();
highScoresMap.remove(Long.parseLong(current.getRawID()));
refreshTableData();
});
editable.setOnAction(event -> {
if (event.getSource() instanceof CheckBox) {
CheckBox checkBox = (CheckBox) event.getSource();
if (checkBox.isSelected()) {
difficultyCol.setEditable(true);
firstNameCol.setEditable(true);
lastNameCol.setEditable(true);
} else {
difficultyCol.setEditable(false);
firstNameCol.setEditable(false);
lastNameCol.setEditable(false);
}
}
});
// Search abilities setup
table.setPlaceholder(new Label("Search did not return any results."));
ObservableList<String> searchOptions = FXCollections.observableArrayList("Date", "Difficulty", "First Name", "Last Name", "Time");
ComboBox searchSelector = new ComboBox(searchOptions);
searchSelector.getSelectionModel().select(2);
searchSelector.setLayoutX(585 - searchSelector.getLayoutBounds().getWidth() / 2);
searchSelector.setLayoutY(160);
TextField search = new TextField();
search.setPromptText("Search");
search.setPrefWidth(480);
search.setPrefHeight(searchSelector.getHeight());
search.setLayoutX(100);
search.setLayoutY(160);
// Execute search on selection mode change
searchSelector.setOnAction(event -> refreshTableData(search.getText(), (String) searchSelector.getSelectionModel().getSelectedItem()));
// Execute search on any keystroke
search.setOnKeyReleased(event -> {
String query = search.getText();
refreshTableData(query, (String) searchSelector.getSelectionModel().getSelectedItem());
});
scoresRoot.getChildren().addAll(table, searchSelector, search);
// Menu setup
menu.setFill(new ImagePattern(bg));
Text title = new Text(120, 120, "3D Minesweeper");
menuRoot.getChildren().add(title);
title.setFont(new Font(70));
title.setStroke(Color.BLACK);
title.setStrokeWidth(5);
title.setTextAlignment(TextAlignment.CENTER);
title.setX(400 - title.getLayoutBounds().getWidth() / 2);
Text name = new Text(150, 200, "Computer Science (ICS3U-01) FST\nBy Seth Damiani");
menuRoot.getChildren().add(name);
name.setFont(new Font(30));
name.setTextAlignment(TextAlignment.CENTER);
name.setStroke(Color.BLACK);
name.setStrokeWidth(2);
name.setX(400 - name.getLayoutBounds().getWidth() / 2);
Rectangle easy = new Rectangle(250, 300, 300, 75);
menuRoot.getChildren().add(easy);
easy.setStroke(Color.BLACK);
easy.setStrokeWidth(5);
easy.setFill(new Color(1, 1, 1, .5));
easy.setOnMouseEntered(event -> easy.setFill(new Color(1, 1, 1, .8)));
easy.setOnMouseExited(event -> easy.setFill(new Color(1, 1, 1, .5)));
Text easyText = new Text(400, 337.5, "Easy");
menuRoot.getChildren().add(easyText);
easyText.setFont(new Font(50));
easyText.setTextAlignment(TextAlignment.CENTER);
easyText.setStroke(Color.BLACK);
easyText.setStrokeWidth(3);
easyText.setX(400 - easyText.getLayoutBounds().getWidth() / 2);
easyText.setY(350);
easyText.setOnMouseEntered(event -> easy.setFill(new Color(1, 1, 1, .8)));
easyText.setOnMouseExited(event -> easy.setFill(new Color(1, 1, 1, .5)));
Rectangle medium = new Rectangle(250, 400, 300, 75);
menuRoot.getChildren().add(medium);
medium.setStroke(Color.BLACK);
medium.setStrokeWidth(5);
medium.setFill(Color.TRANSPARENT);
medium.setFill(new Color(1, 1, 1, .5));
medium.setOnMouseEntered(event -> medium.setFill(new Color(1, 1, 1, .8)));
medium.setOnMouseExited(event -> medium.setFill(new Color(1, 1, 1, .5)));
Text mediumText = new Text(400, 337.5, "Medium");
menuRoot.getChildren().add(mediumText);
mediumText.setFont(new Font(50));
mediumText.setTextAlignment(TextAlignment.CENTER);
mediumText.setStroke(Color.BLACK);
mediumText.setStrokeWidth(3);
mediumText.setX(400 - mediumText.getLayoutBounds().getWidth() / 2);
mediumText.setY(450);
mediumText.setOnMouseEntered(event -> medium.setFill(new Color(1, 1, 1, .8)));
mediumText.setOnMouseExited(event -> medium.setFill(new Color(1, 1, 1, .5)));
Rectangle hard = new Rectangle(250, 500, 300, 75);
menuRoot.getChildren().add(hard);
hard.setStroke(Color.BLACK);
hard.setStrokeWidth(5);
hard.setFill(Color.TRANSPARENT);
hard.setFill(new Color(1, 1, 1, .5));
hard.setOnMouseEntered(event -> hard.setFill(new Color(1, 1, 1, .8)));
hard.setOnMouseExited(event -> hard.setFill(new Color(1, 1, 1, .5)));
Text hardText = new Text(400, 337.5, "Hard");
menuRoot.getChildren().add(hardText);
hardText.setFont(new Font(50));
hardText.setTextAlignment(TextAlignment.CENTER);
hardText.setStroke(Color.BLACK);
hardText.setStrokeWidth(3);
hardText.setX(400 - hardText.getLayoutBounds().getWidth() / 2);
hardText.setY(550);
hardText.setOnMouseEntered(event -> hard.setFill(new Color(1, 1, 1, .8)));
hardText.setOnMouseExited(event -> hard.setFill(new Color(1, 1, 1, .5)));
Rectangle highscores = new Rectangle(600, 550, 150, 100);
menuRoot.getChildren().add(highscores);
highscores.setStroke(Color.BLACK);
highscores.setStrokeWidth(5);
highscores.setFill(Color.TRANSPARENT);
highscores.setFill(new Color(1, 1, 1, .5));
highscores.setOnMouseEntered(event -> highscores.setFill(new Color(1, 1, 1, .8)));
highscores.setOnMouseExited(event -> highscores.setFill(new Color(1, 1, 1, .5)));
Text highscoresText = new Text("High\nScores");
menuRoot.getChildren().add(highscoresText);
highscoresText.setFont(new Font(40));
highscoresText.setTextAlignment(TextAlignment.CENTER);
highscoresText.setStroke(Color.BLACK);
highscoresText.setStrokeWidth(3);
highscoresText.setX(675 - highscoresText.getLayoutBounds().getWidth() / 2);
highscoresText.setY(590);
highscoresText.setOnMouseEntered(event -> highscores.setFill(new Color(1, 1, 1, .8)));
highscoresText.setOnMouseExited(event -> highscores.setFill(new Color(1, 1, 1, .5)));
Rectangle exit = new Rectangle(50, 550, 150, 100);
menuRoot.getChildren().add(exit);
exit.setStroke(Color.BLACK);
exit.setStrokeWidth(5);
exit.setFill(Color.TRANSPARENT);
exit.setFill(new Color(1, 1, 1, .5));
exit.setOnMouseEntered(event -> exit.setFill(new Color(1, 1, 1, .8)));
exit.setOnMouseExited(event -> exit.setFill(new Color(1, 1, 1, .5)));
Text exitText = new Text("Exit");
menuRoot.getChildren().add(exitText);
exitText.setFont(new Font(40));
exitText.setTextAlignment(TextAlignment.CENTER);
exitText.setStroke(Color.BLACK);
exitText.setStrokeWidth(3);
exitText.setX(125 - exitText.getLayoutBounds().getWidth() / 2);
exitText.setY(610);
exitText.setOnMouseEntered(event -> exit.setFill(new Color(1, 1, 1, .8)));
exitText.setOnMouseExited(event -> exit.setFill(new Color(1, 1, 1, .5)));
// Handle click on easy button
EventHandler<MouseEvent> easyButton = event -> {
resetGame();
placeBombs(50);
totalBombs = 50;
flaggedCells = 0;
placeNumbers();
bombs.setText("Bombs: " + flaggedCells + "/" + totalBombs);
difficulty = "Easy";
primaryStage.setScene(game);
time = 0;
timeTask.play();
};
easy.addEventHandler(MouseEvent.MOUSE_CLICKED, easyButton);
easyText.addEventHandler(MouseEvent.MOUSE_CLICKED, easyButton);
// Handle click on medium button
EventHandler<MouseEvent> mediumButton = event -> {
resetGame();
placeBombs(100);
totalBombs = 100;
flaggedCells = 0;
placeNumbers();
bombs.setText("Bombs: " + flaggedCells + "/" + totalBombs);
difficulty = "Medium";
primaryStage.setScene(game);
time = 0;
timeTask.play();
};
medium.addEventHandler(MouseEvent.MOUSE_CLICKED, mediumButton);
mediumText.addEventHandler(MouseEvent.MOUSE_CLICKED, mediumButton);
// Handle click on hard button
EventHandler<MouseEvent> hardButton = event -> {
resetGame();
placeBombs(150);
totalBombs = 150;
flaggedCells = 0;
placeNumbers();
bombs.setText("Bombs: " + flaggedCells + "/" + totalBombs);
difficulty = "Hard";
primaryStage.setScene(game);
time = 0;
timeTask.play();
};
hard.addEventHandler(MouseEvent.MOUSE_CLICKED, hardButton);
hardText.addEventHandler(MouseEvent.MOUSE_CLICKED, hardButton);
EventHandler<MouseEvent> exitButton = event -> System.exit(0);
exit.addEventHandler(MouseEvent.MOUSE_CLICKED, exitButton);
exitText.addEventHandler(MouseEvent.MOUSE_CLICKED, exitButton);
EventHandler<MouseEvent> highScoresButton = event -> primaryStage.setScene(scores);
highscoresText.addEventHandler(MouseEvent.MOUSE_CLICKED, highScoresButton);
highscores.addEventHandler(MouseEvent.MOUSE_CLICKED, highScoresButton);
readHighScores();
refreshTableData();
// Continuously check if game has been won or lost
game.setOnMouseClicked(event -> {
if (gameLost) {
timeTask.stop();
endScoreText.setText("Time: " + time);
endScoreText.setX(400 - endScoreText.getLayoutBounds().getWidth() / 2);
quitBox.setFill(Color.INDIANRED);
quitText.setText("You Lost");
quitText.setX(400 - quitText.getLayoutBounds().getWidth() / 2);
firstNameBox.setVisible(false);
lastNameBox.setVisible(false);
endScoreText.setVisible(false);
continueText.setText("Menu");
continueText.setX(400 - continueText.getLayoutBounds().getWidth() / 2);
continueRect.setWidth(continueText.getLayoutBounds().getWidth() + 40);
continueRect.setX(400 - continueRect.getLayoutBounds().getWidth() / 2);
primaryStage.setScene(quit);
}
if (gameWon) {
timeTask.stop();
quitBox.setFill(Color.FORESTGREEN);
quitText.setText("You Won!");
quitText.setX(400 - quitText.getLayoutBounds().getWidth() / 2);
firstNameBox.setVisible(true);
lastNameBox.setVisible(true);
endScoreText.setVisible(true);
endScoreText.setText("Time: " + time);
continueText.setText("Submit & Continue");
continueText.setX(400 - continueText.getLayoutBounds().getWidth() / 2);
continueRect.setWidth(continueText.getLayoutBounds().getWidth() + 40);
continueRect.setX(400 - continueRect.getLayoutBounds().getWidth() / 2);
primaryStage.setScene(quit);
}
});
primaryStage.setTitle("Minesweeper 3D - Seth Damiani");
primaryStage.setResizable(false);
primaryStage.setScene(menu);
primaryStage.show();
}
use of javafx.scene.input.MouseEvent in project FXyzLib by Birdasaur.
the class RayTest 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.WHEAT);
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(-40);
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);
cameraTransform.getChildren().add(new AmbientLight(Color.WHITE));
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);
knot = new KnotMesh(2d, 1d, 0.4d, 2d, 3d, 100, 20, 0, 0);
// knot.setDrawMode(DrawMode.LINE);
knot.setCullFace(CullFace.NONE);
knot.setSectionType(SectionType.TRIANGLE);
spring = new CurvedSpringMesh(6d, 2d, 0.4d, 25d, 6.25d * 2d * Math.PI, 1000, 60, 0, 0);
spring.getTransforms().addAll(new Translate(6, -6, 0));
spring.setDrawMode(DrawMode.LINE);
spring.setCullFace(CullFace.NONE);
// spring.setTextureModeVertices3D(256*256,dens);
// NONE
knot.setTextureModeNone(Color.BROWN);
spring.setTextureModeNone(Color.BROWN);
knot.getTransforms().addAll(new Rotate(0, Rotate.X_AXIS), rotateY);
group.getChildren().add(knot);
group.getChildren().add(spring);
/*
Origin in knot
Target in spring
*/
org.fxyz.geometry.Point3D locOrigin = knot.getOrigin();
Point3D gloOrigin = knot.localToScene(new Point3D(locOrigin.x, locOrigin.y, locOrigin.z));
org.fxyz.geometry.Point3D locTarget1 = spring.getOrigin();
Point3D locTarget2 = new Point3D(locTarget1.x, locTarget1.y, locTarget1.z);
Point3D gloTarget = spring.localToScene(locTarget2);
Point3D gloDirection = gloTarget.subtract(gloOrigin).normalize();
Point3D gloOriginInLoc = spring.sceneToLocal(gloOrigin);
Bounds locBounds = spring.getBoundsInLocal();
Bounds gloBounds = spring.localToScene(locBounds);
Sphere s = new Sphere(0.05d);
s.getTransforms().add(new Translate(gloOrigin.getX(), gloOrigin.getY(), gloOrigin.getZ()));
s.setMaterial(new PhongMaterial(Color.GREENYELLOW));
group.getChildren().add(s);
s = new Sphere(0.05d);
s.getTransforms().add(new Translate(gloTarget.getX(), gloTarget.getY(), gloTarget.getZ()));
s.setMaterial(new PhongMaterial(Color.GREENYELLOW));
Point3D dir = gloTarget.subtract(gloOrigin).crossProduct(new Point3D(0, -1, 0));
double angle = Math.acos(gloTarget.subtract(gloOrigin).normalize().dotProduct(new Point3D(0, -1, 0)));
double h1 = gloTarget.subtract(gloOrigin).magnitude();
Cylinder c = new Cylinder(0.01d, h1);
c.getTransforms().addAll(new Translate(gloOrigin.getX(), gloOrigin.getY() - h1 / 2d, gloOrigin.getZ()), new Rotate(-Math.toDegrees(angle), 0d, h1 / 2d, 0d, new Point3D(dir.getX(), -dir.getY(), dir.getZ())));
c.setMaterial(new PhongMaterial(Color.GREEN));
group.getChildren().add(c);
group.getChildren().add(new Axes(0.02));
Box box = new Box(gloBounds.getWidth(), gloBounds.getHeight(), gloBounds.getDepth());
// If transparency is enabled (8u60+), comment:
box.setDrawMode(DrawMode.LINE);
box.setCullFace(CullFace.NONE);
// If transparency is enabled (8u60+), uncomment:
// box.setMaterial(new PhongMaterial(Color.web("8A2BE2",0.3)));
box.getTransforms().add(new Translate(gloBounds.getMinX() + gloBounds.getWidth() / 2d, gloBounds.getMinY() + gloBounds.getHeight() / 2d, gloBounds.getMinZ() + gloBounds.getDepth() / 2d));
group.getChildren().add(box);
/*
FIRST STEP; Check the ray crosses the bounding box of the shape at any of
its 6 faces
*/
List<Point3D> normals = Arrays.asList(new Point3D(-1, 0, 0), new Point3D(1, 0, 0), new Point3D(0, -1, 0), new Point3D(0, 1, 0), new Point3D(0, 0, -1), new Point3D(0, 0, 1));
List<Point3D> positions = Arrays.asList(new Point3D(locBounds.getMinX(), 0, 0), new Point3D(locBounds.getMaxX(), 0, 0), new Point3D(0, locBounds.getMinY(), 0), new Point3D(0, locBounds.getMaxY(), 0), new Point3D(0, 0, locBounds.getMinZ()), new Point3D(0, 0, locBounds.getMaxZ()));
AtomicInteger counter = new AtomicInteger();
IntStream.range(0, 6).forEach(i -> {
// ray[t]= ori+t.dir; t/ray[t]=P in plane
// plane P·N+d=0->(ori+t*dir)·N+d=0->t=-(ori.N+d)/(dir.N)
// P=P(x,y,z), N={a,b,c}, d=-a·x0-b·y0-c·z0
double d = -normals.get(i).dotProduct(positions.get(i));
double t = -(gloOriginInLoc.dotProduct(normals.get(i)) + d) / (gloDirection.dotProduct(normals.get(i)));
Point3D locInter = gloOriginInLoc.add(gloDirection.multiply(t));
if (locBounds.contains(locInter)) {
counter.getAndIncrement();
Point3D gloInter = spring.localToScene(locInter);
Sphere s2 = new Sphere(0.1d);
s2.getTransforms().add(new Translate(gloInter.getX(), gloInter.getY(), gloInter.getZ()));
s2.setMaterial(new PhongMaterial(Color.GOLD));
group.getChildren().add(s2);
}
});
if (counter.get() > 0) {
/*
SECOND STEP: Check if the ray crosses any of the triangles of the mesh
*/
// triangle mesh
org.fxyz.geometry.Point3D gloOriginInLoc1 = new org.fxyz.geometry.Point3D((float) gloOriginInLoc.getX(), (float) gloOriginInLoc.getY(), (float) gloOriginInLoc.getZ());
org.fxyz.geometry.Point3D gloDirection1 = new org.fxyz.geometry.Point3D((float) gloDirection.getX(), (float) gloDirection.getY(), (float) gloDirection.getZ());
System.out.println("inter: " + spring.getIntersections(gloOriginInLoc1, gloDirection1));
}
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 - Ray Picker Between Nodes");
primaryStage.setScene(scene);
primaryStage.show();
}
use of javafx.scene.input.MouseEvent in project FXyzLib by Birdasaur.
the class Scatter3DTest 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<>();
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))), // <-- f
i)));
ScatterMesh scatter = new ScatterMesh(data, true, 1, 0);
// NONE
// scatter.setTextureModeNone(Color.ROYALBLUE);
// scatter.setDrawMode(DrawMode.LINE);
// IMAGE
// scatter.setTextureModeImage(getClass().getResource("res/steel-background1.jpg").toExternalForm());
// scatter.setTextureModeImage(getClass().getResource("res/share-carousel2.jpg").toExternalForm());
// DENSITY
scatter.setTextureModeVertices3D(1530, p -> p.magnitude());
// scatter.setTextureModeVertices1D(1530,p->Math.sqrt(p.doubleValue()));
// scatter.setTextureModeVertices3D(1530,p->Math.sin(p.y/50)*Math.cos(p.x/40)*p.z);
// FACES
// scatter.setTextureModeFaces(Palette.ColorPalette.HSB,1530);
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();
System.out.println("time " + (System.currentTimeMillis() - time));
final Timeline rotateEffect2 = new Timeline();
TexturedMesh t1 = scatter.getMeshFromId("1");
final KeyValue kv2 = new KeyValue(t1.getRotateX().angleProperty(), 360);
final KeyFrame kf2 = new KeyFrame(Duration.millis(2000), kv2);
rotateEffect2.getKeyFrames().addAll(kf2);
// rotateEffect2.play();
//
final Timeline rotateEffect3 = new Timeline();
rotateEffect3.setCycleCount(Timeline.INDEFINITE);
TexturedMesh t5 = scatter.getMeshFromId("2");
final KeyValue kv1x = new KeyValue(t5.getScale().xProperty(), 1.2, Interpolator.EASE_BOTH);
final KeyValue kv1y = new KeyValue(t5.getScale().yProperty(), 1.2, Interpolator.EASE_BOTH);
final KeyValue kv1z = new KeyValue(t5.getScale().zProperty(), 1.2, Interpolator.EASE_BOTH);
final KeyFrame kfs1 = new KeyFrame(Duration.millis(500), kv1x, kv1y, kv1z);
final KeyValue kv2x = new KeyValue(t5.getScale().xProperty(), 0.3, Interpolator.EASE_BOTH);
final KeyValue kv2y = new KeyValue(t5.getScale().yProperty(), 0.3, Interpolator.EASE_BOTH);
final KeyValue kv2z = new KeyValue(t5.getScale().zProperty(), 0.3, Interpolator.EASE_BOTH);
final KeyFrame kfs2 = new KeyFrame(Duration.millis(2000), kv2x, kv2y, kv2z);
final KeyValue kv3x = new KeyValue(t5.getScale().xProperty(), 1, Interpolator.EASE_BOTH);
final KeyValue kv3y = new KeyValue(t5.getScale().yProperty(), 1, Interpolator.EASE_BOTH);
final KeyValue kv3z = new KeyValue(t5.getScale().zProperty(), 1, Interpolator.EASE_BOTH);
final KeyFrame kfs3 = new KeyFrame(Duration.millis(3000), kv3x, kv3y, kv3z);
rotateEffect3.getKeyFrames().addAll(kfs1, kfs2, kfs3);
// rotateEffect3.play();
final boolean constantVertices = true;
lastEffect = System.nanoTime();
AtomicInteger count = new AtomicInteger(0);
AnimationTimer timerEffect = new AnimationTimer() {
@Override
public void handle(long now) {
if (now > lastEffect + 50_000_000l) {
// if(count.get()%10<2){
// scatter.setTextureModeNone(Color.hsb(count.get()%360, 1, 1));
// } else if(count.get()%10<4){
// scatter.setTextureModeImage(getClass().getResource("res/steel-background1.jpg").toExternalForm());
// } else if(count.get()%10<8){
// scatter.setTextureModeVertices3D(1530,p->(double)(p.y/(20+count.get()%20))*(p.x/(10+count.get()%10)));
// } else {
// scatter.setTextureModeFaces(1530);
// }
//
// if(count.get()%20>15){
// scatter.setDrawMode(DrawMode.LINE);
// } else {
// scatter.setDrawMode(DrawMode.FILL);
// }
// scatter.getChildren().forEach(m->((TexturedMesh)m).setDensity(p->p.magnitude()*Math.cos(p.y/100d*(count.get()%5))));
count.getAndIncrement();
lastEffect = now;
}
}
};
// timerEffect.start();
OBJWriter writer = new OBJWriter((TriangleMesh) ((TexturedMesh) (scatter.getChildren().get(0))).getMesh(), "scatter");
writer.setTextureColors(6);
// writer.setTexturePattern();
// writer.setTextureImage(getClass().getResource("res/LaminateSteel.jpg").toExternalForm());
writer.exportMesh();
}
Aggregations