Skip to content

Commit

Permalink
feat: added AnimatedImage which animates between corresponding pixels…
Browse files Browse the repository at this point in the history
… to produce a new image
  • Loading branch information
AlmasB committed Apr 3, 2023
1 parent 5de0727 commit e539eba
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
package com.almasb.fxgl.animation

import com.almasb.fxgl.core.math.FXGLMath
import com.almasb.fxgl.texture.getPixel
import com.almasb.fxgl.texture.map
import javafx.animation.Interpolator
import javafx.animation.PathTransition
import javafx.geometry.Point2D
import javafx.geometry.Point3D
import javafx.scene.image.Image
import javafx.scene.paint.Color
import javafx.scene.shape.CubicCurve
import javafx.scene.shape.QuadCurve
Expand Down Expand Up @@ -200,3 +203,14 @@ class AnimatedStringDecreasing(value: String) : AnimatedValue<String>("", value)
return anim.animate(val1, val2, 1 - progress, interpolator)
}
}

class AnimatedImage(image1: Image, image2: Image) : AnimatedValue<Image>(image1, image2) {
override fun animate(val1: Image, val2: Image, progress: Double, interpolator: Interpolator): Image {
return val1.map { p ->
val animatedColor = AnimatedColor(p.color, val2.getPixel(p.x, p.y).color)
val color = animatedColor.getValue(progress, interpolator)

p.copy(color)
}
}
}

0 comments on commit e539eba

Please sign in to comment.