Skip to content

Commit

Permalink
Merge pull request #25 from MatteoBattilana/fix#18-missing-rain-blur
Browse files Browse the repository at this point in the history
Update to use new currentVelocityX/Y fields for motion blur
  • Loading branch information
MatteoBattilana committed Apr 29, 2020
2 parents 98ed123 + 5a7307e commit 3db5e6a
Showing 1 changed file with 5 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,29 @@ class WeatherConfettoGenerator(val confettoInfo: ConfettoInfo) : ConfettoGenerat
class MotionBlurBitmapConfetto(val confettoInfo: ConfettoInfo) : Confetto() {
companion object {
const val SNOW_RADIUS = 7.5f
const val RAIN_STRETCH = 1.5f
const val RAIN_STRETCH = 20f
}

private var prevX: Float? = null
private var prevY: Float? = null

override fun getHeight(): Int = 0

override fun getWidth(): Int = 0

override fun reset() {
super.reset()
prevX = null
prevY = null
}

override fun configurePaint(paint: Paint) {
super.configurePaint(paint)
paint.color = Color.WHITE
paint.isAntiAlias = true
}

override fun drawInternal(canvas: Canvas, matrix: Matrix, paint: Paint, x: Float, y: Float, rotation: Float, percentageAnimated: Float) {
if (prevX == null || prevY == null) {
prevX = x
prevY = y
}

when (confettoInfo.precipType) {
PrecipType.CLEAR -> {
}
PrecipType.RAIN -> {
val dX = x - prevX!!
val dY = y - prevY!!
val x1 = prevX!! - dX * RAIN_STRETCH
val y1 = prevY!! - dY * RAIN_STRETCH
val dX = currentVelocityX
val dY = currentVelocityY
val x1 = x - dX * RAIN_STRETCH
val y1 = y - dY * RAIN_STRETCH
val x2 = x + dX * RAIN_STRETCH
val y2 = y + dY * RAIN_STRETCH

Expand All @@ -71,8 +58,5 @@ class MotionBlurBitmapConfetto(val confettoInfo: ConfettoInfo) : Confetto() {
canvas.drawCircle(x, y, SNOW_RADIUS, paint)
}
}

prevX = x
prevY = y
}
}

0 comments on commit 3db5e6a

Please sign in to comment.