Views
2 weeks ago

tornadofx-guide

9. Shapes and Animation

9. Shapes and Animation Interpolators You can also specify an Interpolator which can add subtle effects to the animation. For instance, you can specify Interpolator.EASE_BOTH to accelerate and decelerate the value change at the beginning and end of the animation gracefully. val rectangle = rectangle(width = 60.0, height = 40.0) { } padding = Insets(20.0) timeline { keyframe(5.seconds) { keyvalue(rectangle.rotateProperty(), 180.0, interpolator = Interpolator.EASE_B OTH) } } Cycles and AutoReverse You can modify other attributes of the timeline() such as cycleCount and autoReverse . The cycleCount will repeat the animation a specified number of times, and setting the isAutoReverse to true will cause it to revert back with each cycle. timeline { keyframe(5.seconds) { keyvalue(rectangle.rotateProperty(), 180.0, interpolator = Interpolator.EASE_B OTH) } isAutoReverse = true cycleCount = 3 } To repeat the animation indefinitely, set the cycleCount to Timeline.INDEFINITE . Shorthand Animation 142

9. Shapes and Animation If you want to animate a single property, you can quickly animate it without declaring a timeline() , keyframe() , and keyset() . Call the animate() extension function on that propert and provide the endValue , the duration , and optionally the interoplator . This is much shorter and cleaner if you are animating just one property. rectangle.rotateProperty().animate(endValue = 180.0, duration = 5.seconds) Summary In this chapter we covered builders for shape and animation. We did not cover JavaFX's Canvas as this is beyond the scope of the TornadoFX framework. It could easily take up more than several chapters on its own. But the shapes and animation should allow you to do basic custom graphics for a majority of tasks. This concludes our coverage of TornadoFX builders for now. Next we will cover FXML for those of us that have need to use it. 143

GUIDE
GUIDE
GUIDE
Guide
Guide
GUIDE
guide
guide
Guide
Guide
GUIDE
GUIDE
GUIDE
Guide
Guide
Guide
GUIDE TO
GUIDE
GUIDE
GUIDE