Skip to content

Instantly share code, notes, and snippets.

@AvneeshSarwate
Last active February 11, 2022 06:01
Show Gist options
  • Save AvneeshSarwate/fa3488ecd0d52ea6545924dcbfbe51fd to your computer and use it in GitHub Desktop.
Save AvneeshSarwate/fa3488ecd0d52ea6545924dcbfbe51fd to your computer and use it in GitHub Desktop.
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.animatable.Animatable
import org.openrndr.animatable.easing.Easing
import org.openrndr.draw.*
import org.openrndr.extra.olive.oliveProgram
fun main(args: Array<String>) {
application {
configure {
width = (1920 * .9).toInt()
height = (1080 * .9).toInt()
}
class AnimatedPosition(x: Double, y: Double ) : Animatable() {
var x = x
var y = y
var radius = 8.0
fun square() {
::x.cancel()
::y.cancel()
::x.animate(program.width.toDouble() - radius, 1000, Easing.CubicInOut)
::x.complete()
::y.animate(program.height.toDouble() - radius, 1000, Easing.CubicInOut)
::y.complete()
::x.animate(0.0 + radius, 1000, Easing.CubicInOut)
::x.complete()
::y.animate(0.0 + radius, 1000, Easing.CubicInOut)
::y.complete()
}
}
class AnimatedRadius() : Animatable() {
var radius = 10.0
fun radiusChange() {
::radius.cancel()
::radius.animate(50.0, 2000, Easing.CubicInOut)
::radius.complete()
::radius.animate(10.0, 2000, Easing.CubicInOut)
::radius.complete()
}
}
class PosRad(x: Double, y: Double, delay: Long) {
var pos = AnimatedPosition(x, y)
var rad = AnimatedRadius()
var delay = delay
fun update() {
pos.updateAnimation()
rad.updateAnimation()
if(!pos.hasAnimations()) {
pos.square()
}
if(!rad.hasAnimations()) {
rad.radiusChange()
}
}
fun startWithDelay(): PosRad{
if(!pos.hasAnimations()) {
pos.delay(delay)
pos.square()
}
if(!rad.hasAnimations()) {
rad.delay(delay)
rad.radiusChange()
}
return this
}
val x: Double
get() = this.pos.x
val y: Double
get() = this.pos.y
val radius
get() = this.rad.radius
}
val numCircles = 10
val animatedCircles = List(numCircles) { i -> PosRad(0.0, 0.0, i*50.toLong()) }
program {
animatedCircles.forEach { ac -> ac.startWithDelay() }
extend {
drawer.clear(ColorRGBa.BLACK)
drawer.fill = ColorRGBa.PINK
drawer.stroke = null
animatedCircles.forEach { ac -> ac.update() }
drawer.circles {
animatedCircles.forEach { ac -> circle(ac.x, ac.y, ac.radius) }
}
}
extend(FPSDisplay())
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment