Created
August 3, 2020 13:50
-
-
Save EnzDev/760ef2c228ad913f536fc58c5f41607f to your computer and use it in GitHub Desktop.
L'implémentation qui marche pas
This file contains hidden or 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 org.openrndr.animatable.Animatable | |
| import org.openrndr.draw.Drawer | |
| abstract class DrawableAnimatable : Animatable() { | |
| abstract fun draw(drawer: Drawer) | |
| } | |
| class Toaster(private val message: String): DrawableAnimatable() { | |
| private val y: Double = -10.0 | |
| init { | |
| animate("y", 30.0, 400) | |
| complete() | |
| delay(1000) | |
| animate("y", -10.0, 400) | |
| complete() | |
| } | |
| override fun draw(drawer: Drawer) { | |
| drawer.text(message, 7.0, y) | |
| } | |
| } | |
| class Animator { | |
| private val animationPool = mutableListOf<DrawableAnimatable>() | |
| private var currentAnimation: DrawableAnimatable? = null | |
| fun addAnimation(animation: DrawableAnimatable) { | |
| animationPool.add(animation) | |
| } | |
| @ExperimentalStdlibApi | |
| fun nextFrame(drawer: Drawer) { | |
| currentAnimation?.let { if(!it.hasAnimations()) currentAnimation = null } | |
| // Try to fetch the next animation if the current one is empty | |
| currentAnimation = | |
| currentAnimation ?: animationPool.removeFirstOrNull() | |
| currentAnimation?.apply { | |
| updateAnimation() | |
| draw(drawer) | |
| } | |
| } | |
| } |
This file contains hidden or 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 org.openrndr.application | |
| import org.openrndr.color.ColorRGBa | |
| import org.openrndr.draw.loadFont | |
| @ExperimentalStdlibApi | |
| fun main() = application { | |
| program { | |
| val animator = Animator() | |
| var counter = 0 | |
| val font = loadFont("data/IBMPlexMono-Bold.ttf", 48.0) | |
| keyboard.character.listen { | |
| when (it.character) { | |
| 'n' -> animator.addAnimation(Toaster("${counter++}")) | |
| } | |
| } | |
| extend { | |
| drawer.clear(ColorRGBa.PINK) | |
| drawer.fontMap = font | |
| drawer.fill = ColorRGBa.BLACK | |
| animator.nextFrame(drawer) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment