class AnimationDemo : Fragment() { override val root=group { val circle = Circle(200.0, 200.0, 10.0) class AniTimer: AnimationTimer(){ var lastTime=0L var step=1 override fun handle(now: Long) { if((now-lastTime)> 10000000){ lastTime=now }else{ return } if (circle.radius > 200 || circle.radius < 0) { step *= -1 } circle.radius = circle.radius + step } } class ColorChanger: AnimationTimer(){ var lastTime=0L var red = 10 var green = 10 var blue = 60 var direction=1 override fun handle(now: Long) { if((now-lastTime)> 10000000){ lastTime=now }else{ return } circle.fill = Color.rgb(red, green, blue) if (red > 254 || red < 1) { direction *= -1 blue += 2 green += 10 } red += direction } } add(circle) ColorChanger().start() AniTimer().start() } }