|
1 | 1 | # Animatronics |
2 | 2 |
|
| 3 | +[](https://opensource.org/licenses/Apache-2.0) |
| 4 | +[](https://travis-ci.org/tbressler/java-animatronics) |
| 5 | + |
3 | 6 | A very simple and low-level animation library for your Java project. |
4 | 7 |
|
| 8 | +The name *Animatronic* is a homage to mechatronic puppets which are often used in films and in theme park attractions. |
| 9 | + |
| 10 | +## Usage |
| 11 | + |
| 12 | +The library requires JDK 9 or higher. |
| 13 | + |
| 14 | +### Animate a simple value |
| 15 | + |
| 16 | +```Java |
| 17 | + |
| 18 | +// Initialize and configure your animation (timeline). |
| 19 | +AnimatronicDouble animation = new AnimatronicDouble(1.0d) |
| 20 | + .keyframe(1.3d, 5000, Easings.easeInOutBack()) |
| 21 | + .keyframe(5.4d, 3000, Easings.easeInOutCubic()) |
| 22 | + .play(); |
| 23 | + |
| 24 | +// ... |
| 25 | + |
| 26 | +// Start the animation at some point in time. |
| 27 | +animation.play(); |
| 28 | + |
| 29 | +// ... |
| 30 | + |
| 31 | +// Use the current (interpolated) value when drawing. |
| 32 | +double currentValue = animation.getValue(); |
| 33 | + |
| 34 | +``` |
| 35 | + |
| 36 | +### Animate any object |
| 37 | + |
| 38 | +Use the abstract class ```Animatronic<T>``` in order to animate any object you want. Simply create a class which extends ```Animatronic``` and implement the ```calculateValueInBetween()``` method. The method calculates the interpolated value with the given factor. You can use the helper method ```calculateValue()``` to calculate the interpolated value without any hustle. |
| 39 | + |
| 40 | +A good example is the ```AnimatronicPoint2D``` class: |
| 41 | + |
| 42 | +```Java |
| 43 | + |
| 44 | +public class AnimatronicPoint2D extends Animatronic<Point2D> { |
| 45 | + |
| 46 | + // ... |
| 47 | + |
| 48 | + @Override |
| 49 | + protected Point2D calculateValueInBetween(Point2D lastValue, Point2D nextValue, double factor) { |
| 50 | + return new Point2D.Double( |
| 51 | + // Calculate the interpolated coordinates: |
| 52 | + calculateValue(lastValue.getX(), nextValue.getX(), factor), |
| 53 | + calculateValue(lastValue.getY(), nextValue.getY(), factor) |
| 54 | + ); |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +``` |
| 59 | + |
| 60 | +The library has different default implementations: |
| 61 | + |
| 62 | +* Double with ```AnimatronicDouble``` |
| 63 | +* Float with ```AnimatronicFloat``` |
| 64 | +* Integer with ```AnimatronicInteger``` |
| 65 | +* Color with ```AnimatronicColor``` |
| 66 | +* Point2D with ```AnimatronicPoint2D``` |
| 67 | + |
| 68 | + |
| 69 | +### Easing functions |
| 70 | + |
| 71 | +The library comes with different predefined easing functions. |
| 72 | + |
| 73 | +```Java |
| 74 | + |
| 75 | +Easing e1 = Easings.easeInBack(); |
| 76 | +Easing e2 = Easings.easeInOutCubic(); |
| 77 | +// ... and so on. |
| 78 | + |
| 79 | +``` |
| 80 | + |
5 | 81 | ## License |
6 | 82 |
|
7 | 83 | ``` |
8 | | - Copyright 2021 Tobias Bressler |
| 84 | + Copyright 2021 Tobias Breßler |
9 | 85 |
|
10 | 86 | Licensed under the Apache License, Version 2.0 (the "License"); |
11 | 87 | you may not use this file except in compliance with the License. |
|
0 commit comments