1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
|
public class M1 extends Application {
DropShadow shadow = new DropShadow();
Label label = new Label();
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) {
stage.setTitle("SLOT8");
Group root = new Group();
Scene scene = new Scene(root, 600, 600, Color.RED);
stage.setScene(scene);
stage.setResizable(true);
stage.setWidth(600);
stage.setHeight(600);
stage.setScene(scene);
stage.sizeToScene();
//µµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµ
Rectangle fond_ = new Rectangle();
fond_.setWidth(500);
fond_.setHeight(8);
fond_.setArcWidth(30);
fond_.setArcHeight(30);
fond_.setFill(Color.BLACK);
fond_.setTranslateX(60);//on positionne le groupe plutôt que le rectangle
fond_.setTranslateY(175);
ImageView image1 = new ImageView(getClass().getResource("bell.png").toExternalForm());
ImageView image2 = new ImageView(getClass().getResource("bar.png").toExternalForm());
ImageView image3 = new ImageView(getClass().getResource("clover.png").toExternalForm());
ImageView image4 = new ImageView(getClass().getResource("banana.png").toExternalForm());
ImageView image5 = new ImageView(getClass().getResource("banana.png").toExternalForm());
ImageView image6 = new ImageView(getClass().getResource("bell.png").toExternalForm());
ImageView image7 = new ImageView(getClass().getResource("bar.png").toExternalForm());
ImageView image8 = new ImageView(getClass().getResource("clover.png").toExternalForm());
ImageView image9 = new ImageView(getClass().getResource("banana.png").toExternalForm());
ImageView image16 = new ImageView(getClass().getResource("bell.png").toExternalForm());
ImageView image15 = new ImageView(getClass().getResource("bar.png").toExternalForm());
ImageView image17 = new ImageView(getClass().getResource("clover.png").toExternalForm());
ImageView image14 = new ImageView(getClass().getResource("banana.png").toExternalForm());
ImageView image13 = new ImageView(getClass().getResource("banana.png").toExternalForm());
ImageView image18 = new ImageView(getClass().getResource("bell.png").toExternalForm());
ImageView image12 = new ImageView(getClass().getResource("bar.png").toExternalForm());
ImageView image19 = new ImageView(getClass().getResource("clover.png").toExternalForm());
ImageView image11 = new ImageView(getClass().getResource("banana.png").toExternalForm());
ImageView image21 = new ImageView(getClass().getResource("bell.png").toExternalForm());
ImageView image22 = new ImageView(getClass().getResource("bar.png").toExternalForm());
ImageView image23 = new ImageView(getClass().getResource("clover.png").toExternalForm());
ImageView image24 = new ImageView(getClass().getResource("banana.png").toExternalForm());
ImageView image25 = new ImageView(getClass().getResource("banana.png").toExternalForm());
ImageView image26 = new ImageView(getClass().getResource("bell.png").toExternalForm());
ImageView image27 = new ImageView(getClass().getResource("bar.png").toExternalForm());
ImageView image28 = new ImageView(getClass().getResource("clover.png").toExternalForm());
ImageView image29 = new ImageView(getClass().getResource("banana.png").toExternalForm());
VBox vbox1 = new VBox();
vbox1.setLayoutX(60);
vbox1.setLayoutY(10);
VBox vbox2 = new VBox();
vbox2.setLayoutX(240);
vbox2.setLayoutY(10);
VBox vbox3 = new VBox();
vbox3.setLayoutX(650);
vbox3.setLayoutY(10);
Button button33 = new Button("33");
button33.setLayoutX(400);
button33.setLayoutY(400);
button33.addEventHandler(MouseEvent.MOUSE_ENTERED,
new EventHandler<MouseEvent>() {
public void handle(MouseEvent e) {
button33.setEffect(shadow);
}
});
button33.addEventHandler(MouseEvent.MOUSE_EXITED,
new EventHandler<MouseEvent>() {
public void handle(MouseEvent e) {
button33.setEffect(shadow);
}
});
ImageView[] images = {image1, image2, image3, image4, image5, image6, image7, image8, image9};
ImageView[] images2 = {image11, image12, image13, image14, image15, image16, image17, image18, image19};
ImageView[] images3 = {image21, image22, image23, image24, image25, image26, image27, image28, image29};
for (ImageView i : images) {
vbox1.getChildren().add(i);
}
for (ImageView i2 : images2) {
vbox2.getChildren().add(i2);
}
for (ImageView i3 : images3) {
vbox2.getChildren().add(i3);
}
// for (ImageView i3 : images3) {
// for (ImageView i2 : images2) {
// for (ImageView i : images) {
// }
// }
// }
root.getChildren().add(fond_);
// root.getChildren().add(sun);
// FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
Rectangle clavier = new Rectangle();
clavier.setWidth(500);
clavier.setHeight(200);
clavier.setArcWidth(30);
clavier.setArcHeight(30);
clavier.setFill(
new LinearGradient(0f, 0f, 0f, 1f, true, CycleMethod.NO_CYCLE,
new Stop[]{
new Stop(0, Color.web("#333333")),
new Stop(1, Color.web("#000000"))
}
)
);
Reflection r = new Reflection();
r.setFraction(0.25);
r.setBottomOpacity(0);
r.setTopOpacity(0.5);
clavier.setEffect(r);
clavier.setTranslateX(50);
clavier.setTranslateY(350);
root.getChildren().add(vbox1);
root.getChildren().add(vbox2);
root.getChildren().add(vbox3);
root.getChildren().add(clavier);
stage.setScene(scene);
stage.show();
ToggleButton spinButton = new ToggleButton("Start!");
spinButton.setOnAction(actionEvent -> {
if (spinButton.isSelected()) {
spinCylinders(vbox1, vbox2, vbox3);
} else {
stopCylinders(vbox1, vbox2, vbox3);
}
});
root.getChildren().add(spinButton);
}
private Animation currentAnimation = null;
private void spinCylinders(Node... cylinders) {
if (currentAnimation != null) {
currentAnimation.pause();
currentAnimation = null;
}
// Actuellement avec cette simplification du code chaque cy;indre subit la meme animation.
// Introduire une part d'aleatoire sur chaque cylinder pour qu'ils puissent tourner indepandement les uns des autres ?
// - Duree d'animation ;
// - Offset vertical ;
// - Nombre de cycles.
ParallelTransition parallelTransition = new ParallelTransition();
for (Node cylinder : cylinders) {
TranslateTransition translateTransition
= new TranslateTransition(Duration.millis(2000), cylinder);
translateTransition.setFromX(cylinder.getTranslateX());
translateTransition.setFromY(cylinder.getTranslateY() - 800);
translateTransition.setToY(cylinder.getTranslateY() + 20);
translateTransition.setCycleCount(2);
translateTransition.setAutoReverse(true);
parallelTransition.getChildren().add(translateTransition);
}
parallelTransition.setCycleCount(Timeline.INDEFINITE);
parallelTransition.play();
currentAnimation = parallelTransition;
}
private void stopCylinders(Node... cylinders) {
if (currentAnimation == null) {
return;
}
currentAnimation.pause();
currentAnimation = null;
// Idem, introduire de l'aleatoire pour chaque cylindre:
// - Duree d'extinction ;
// - Offset vertical.
ParallelTransition parallelTransition = new ParallelTransition();
for (Node cylinder : cylinders) {
TranslateTransition translateTransition
= new TranslateTransition(Duration.millis(2000), cylinder);
translateTransition.setFromX(cylinder.getTranslateX());
translateTransition.setFromY(cylinder.getTranslateY());
// Precalculer un Y final qui soit correct !!!!!!!!!!!!!!!!
translateTransition.setToY(cylinder.getTranslateY() + 300);
// Ou un interpolateur fait maison !
translateTransition.setInterpolator(Interpolator.EASE_OUT);
parallelTransition.getChildren().add(translateTransition);
}
parallelTransition.play();
currentAnimation = parallelTransition;
}
} |
Partager