private Node motionBlur() { Text t = new Text(); t.setX(10.0f); t.setY(150.0f); t.setText("Motion Blur"); t.setFill(Color.RED); t.setFont(Font.font("null", FontWeight.BOLD, 60)); MotionBlur mb = new MotionBlur(); mb.setRadius(15.0f); mb.setAngle(45.0f); t.setEffect(mb); //t.setTranslateX(300); // t.setTranslateY(150); return t; }
private void addMotionBlurEffect(Shape organShape, double zoomLevel, boolean effectsOn) { organShape.setEffect(null); if (!effectsOn) return; if (zoomLevel < MOTION_BLUR_DISTANCE) return; Vector movement = calculateMovement(); if (movement.equals(Vector.ZERO)) return; double velocity = movement.getLength(); if (velocity < MOTION_BLUR_THRESHOLD) return; try { organShape.setEffect(new MotionBlur(movement.getAngle(), velocity / MOTION_BLUR_THRESHOLD * MOTION_BLUR_INTENSITY)); } catch (ZeroVectorAngleException e) { } }
/** * Not the most useful feature, nor is it the most reliable */ public void motionBlur() { if (!bluring) { bluring = true; Thread t = new Thread(new Runnable() { double angle = 0, radius = 0; @Override public void run() { for (radius = 0; radius < 15; radius = radius + 0.01) rotate(); for (int i = 0; i < 100; i++) rotate(); for (radius = 15; radius > 0; radius = radius - 0.01) rotate(); setEffect(null); bluring = false; } private void rotate() { angle += 1; if (angle > 360) angle = 0f; MotionBlur mb = new MotionBlur(); mb.setRadius(radius); mb.setAngle(angle); setEffect(mb); try { Thread.sleep(10); } catch (Exception e) { UIUtils.showExceptionDialog(e); } } }, "Motion-Blur"); t.setDaemon(true); t.start(); } }
static void showMessage( String text, MessageLevel level ) { Platform.runLater( () -> { Text messageText = new Text( text ); Dialog dialog = new Dialog( messageText ); dialog.setStyle( StageStyle.TRANSPARENT ); dialog.getBox().setSpacing( 0 ); dialog.getBox().getStyleClass().addAll( "message", level.name().toLowerCase() ); MotionBlur blurText = new MotionBlur(); blurText.setAngle( 0 ); blurText.setRadius( 0 ); messageText.setEffect( blurText ); Animation blurAnimation = new Timeline( new KeyFrame( Duration.millis( 450 ), new KeyValue( blurText.angleProperty(), 45.0 ), new KeyValue( blurText.radiusProperty(), 20.0 ) ) ); blurAnimation.setDelay( Duration.millis( 500 ) ); FadeTransition hideAnimation = new FadeTransition( Duration.seconds( 1 ), dialog.getBox() ); hideAnimation.setFromValue( 1.0 ); hideAnimation.setToValue( 0.1 ); hideAnimation.setInterpolator( Interpolator.EASE_IN ); ParallelTransition allAnimations = new ParallelTransition( hideAnimation, blurAnimation ); allAnimations.setDelay( Duration.seconds( 3 ) ); allAnimations.setOnFinished( event -> { dialog.hide(); currentMessageStages.remove( dialog.dialogStage ); } ); dialog.getBox().setOnMouseClicked( event -> { allAnimations.setDelay( Duration.seconds( 0 ) ); allAnimations.stop(); allAnimations.play(); } ); dialog.show( DialogPosition.TOP_CENTER ); allAnimations.play(); double yShift = 20 + currentMessageStages.stream() .mapToDouble( stage -> stage.getHeight() + 5.0 ) .sum(); StageTranslateTransition shiftDown = new StageTranslateTransition( dialog.dialogStage ); shiftDown.setToY( yShift ); shiftDown.setDuration( Duration.millis( 250.0 ) ); shiftDown.setInterpolator( Interpolator.EASE_BOTH ); shiftDown.play(); currentMessageStages.add( dialog.dialogStage ); } ); }