Crawler Demo 3
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
import javafx.animation.Animation; | |
import javafx.animation.Interpolator; | |
import javafx.animation.KeyFrame; | |
import javafx.animation.KeyValue; | |
import javafx.animation.ParallelTransition; | |
import javafx.animation.PauseTransition; | |
import javafx.animation.SequentialTransition; | |
import javafx.animation.Timeline; | |
import javafx.animation.TranslateTransition; | |
import javafx.application.Application; | |
import static javafx.application.Application.launch; | |
import javafx.scene.Group; | |
import javafx.scene.Scene; | |
import javafx.scene.effect.PerspectiveTransform; | |
import javafx.scene.paint.Color; | |
import javafx.scene.text.Font; | |
import javafx.scene.text.FontPosture; | |
import javafx.scene.text.Text; | |
import javafx.scene.text.TextAlignment; | |
import javafx.scene.transform.Scale; | |
import javafx.scene.transform.Transform; | |
import javafx.stage.Stage; | |
import javafx.stage.StageStyle; | |
import javafx.util.Duration; | |
public class TextCrawler3 extends Application { | |
private static final String crawl = "Episode IV\n" | |
+ "A NEW HOPE\n\n" | |
+ "It is a period of civil war.\n" | |
+ "Rebel spaceships, striking\n" | |
+ "from a hidden base, have won\n" | |
+ "their first victory against\n" | |
+ "the evil Galactic Empire.\n" | |
+ "\n" | |
+ "During the battle, Rebel\n" | |
+ "spies managed to steal secret\n" | |
+ "plans to the Empire's\n" | |
+ "ultimate weapon, the DEATH\n" | |
+ "STAR, an armored space\n" | |
+ "station with enough power\n" | |
+ "to destroy an entire planet.\n" | |
+ "\n" | |
+ "Pursued by the Empire's\n" | |
+ "sinister agents, Princess\n" | |
+ "Leia races home aboard her\n" | |
+ "starship, custodian of the\n" | |
+ "stolen plans that can save her\n" | |
+ "people and restore\n" | |
+ "freedom to the galaxy...."; | |
@Override | |
public void start(Stage stage) throws Exception { | |
Group root = new Group(); | |
Scene scene = new Scene(root); | |
scene.setFill(Color.BLACK); | |
stage.setScene(scene); | |
stage.setWidth(800); | |
stage.setHeight(600); | |
stage.initStyle(StageStyle.UNDECORATED); | |
stage.show(); | |
Text text = new Text(crawl); | |
text.setTextAlignment(TextAlignment.CENTER); | |
text.setFill(Color.YELLOW); | |
text.setFont(Font.font("Arial", FontPosture.REGULAR, 24)); | |
PerspectiveTransform perspective = new PerspectiveTransform(); | |
perspective.setUlx(300.0); | |
perspective.setUly(200.0); | |
perspective.setUrx(500.0); | |
perspective.setUry(200.0); | |
perspective.setLlx(0.0); | |
perspective.setLly(500.0); | |
perspective.setLrx(800.0); | |
perspective.setLry(500.0); | |
text.setEffect(perspective); | |
root.getChildren().add(text); | |
TranslateTransition trans = new TranslateTransition(Duration.millis(20_000), text); | |
trans.setFromY(400); | |
trans.setToY(0); | |
trans.setInterpolator(Interpolator.EASE_OUT); | |
trans.setCycleCount(Animation.INDEFINITE); | |
trans.play(); | |
Scale scale = Transform.scale(4.0, 4.0, 400.0, 200.0); | |
text.getTransforms().add(scale); | |
Timeline timeline = new Timeline( | |
new KeyFrame(Duration.millis(19_000), | |
new KeyValue(scale.xProperty(), 0.3), | |
new KeyValue(scale.yProperty(), 0.3)), | |
new KeyFrame(Duration.millis(20_000), | |
new KeyValue(scale.xProperty(), 0.001), | |
new KeyValue(scale.yProperty(), 0.001)) | |
); | |
timeline.setCycleCount(Animation.INDEFINITE); | |
timeline.play(); | |
} | |
public static void main(String... args) { | |
launch(args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment