Sunday, June 19, 2016

49. MotionBlur

MotionBlur gives the blur a direction as specified by the angle.


It should be noted that +y refers to the downwards direction with an angle of 90. In comparison the +x refers to the rightwards direction with an angle of 0.


package ex49;

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.effect.MotionBlur;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class Ex49 extends Application {
    
    @Override
    public void start(Stage stage) {
        VBox root = new VBox(50);
        root.setAlignment(Pos.CENTER);
        
        MotionBlur motionBlur1 = new MotionBlur();
        motionBlur1.setRadius(7);
        motionBlur1.setAngle(0);
        
        Text text1 = new Text("blur1 (+x)");
        text1.setFont(Font.font("Georgia", FontWeight.BOLD, 32));
        text1.setFill(Color.GREEN);
        text1.setEffect(motionBlur1);
        
        MotionBlur motionBlur2 = new MotionBlur();
        motionBlur2.setRadius(7);
        motionBlur2.setAngle(90);
        
        Text text2 = new Text("blur2 (+y)");
        text2.setFont(Font.font("Georgia", FontWeight.BOLD, 32));
        text2.setFill(Color.GREEN);
        text2.setEffect(motionBlur2);
        
        MotionBlur motionBlur3 = new MotionBlur();
        motionBlur3.setRadius(7);
        motionBlur3.setAngle(180);
        
        Text text3 = new Text("blur3 (-x)");
        text3.setFont(Font.font("Georgia", FontWeight.BOLD, 32));
        text3.setFill(Color.GREEN);
        text3.setEffect(motionBlur3);
        
        MotionBlur motionBlur4 = new MotionBlur();
        motionBlur4.setRadius(7);
        motionBlur4.setAngle(270);
        
        Text text4 = new Text("blur4 (-y)");
        text4.setFont(Font.font("Georgia", FontWeight.BOLD, 32));
        text4.setFill(Color.GREEN);
        text4.setEffect(motionBlur4);
        
        root.getChildren().addAll(text1, text2,
                text3, text4);
        Scene scene = new Scene(root, 500, 400, Color.YELLOW);
        stage.setTitle("Example 49. MotionBlur");
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        Application.launch(args);
    }
}

This is the output:


No comments:

Post a Comment