-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
209 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
visualizer/src/main/java/io/github/jeffshee/visualizer/painters/misc/Background.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.github.jeffshee.visualizer.painters.misc | ||
|
||
import android.graphics.* | ||
import io.github.jeffshee.visualizer.painters.Painter | ||
import io.github.jeffshee.visualizer.utils.VisualizerHelper | ||
import kotlin.math.max | ||
|
||
class Background( | ||
var bitmap: Bitmap, | ||
var xR: Float = .5f, | ||
var yR: Float = .5f, | ||
var wR: Float = 1f | ||
) : Painter() { | ||
|
||
private val matrix = Matrix() | ||
|
||
override fun draw(canvas: Canvas, helper: VisualizerHelper) { | ||
bitmap.apply bitmap@{ | ||
matrix.apply { | ||
val scale = max( | ||
canvas.width.toFloat() * wR / this@bitmap.width, | ||
canvas.height.toFloat() * wR / this@bitmap.height | ||
) | ||
postScale(scale, scale) | ||
postTranslate(-scale * this@bitmap.width / 2f, -scale * this@bitmap.height.toFloat() / 2f) | ||
} | ||
drawHelper(canvas, "a", xR, yR) { | ||
canvas.drawBitmap(this, matrix, null) | ||
} | ||
matrix.reset() | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
visualizer/src/main/java/io/github/jeffshee/visualizer/painters/modifier/Move.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.github.jeffshee.visualizer.painters.modifier | ||
|
||
import android.graphics.Canvas | ||
import io.github.jeffshee.visualizer.painters.Painter | ||
import io.github.jeffshee.visualizer.utils.VisualizerHelper | ||
|
||
class Move : Painter { | ||
var painters: List<Painter> | ||
var xR: Float | ||
var yR: Float | ||
|
||
constructor(painters: List<Painter>, xR: Float = 0f, yR: Float = 0f) { | ||
this.painters = painters | ||
this.xR = xR | ||
this.yR = yR | ||
} | ||
|
||
constructor(painter: Painter, xR: Float = 0f, yR: Float = 0f) : this( | ||
listOf(painter), xR, yR | ||
) | ||
|
||
override fun draw(canvas: Canvas, helper: VisualizerHelper) { | ||
canvas.save() | ||
canvas.translate(canvas.width * xR, canvas.height * yR) | ||
painters.forEach { painter -> | ||
painter.draw(canvas, helper) | ||
} | ||
canvas.restore() | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
visualizer/src/main/java/io/github/jeffshee/visualizer/painters/modifier/Scale.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.github.jeffshee.visualizer.painters.modifier | ||
|
||
import android.graphics.Canvas | ||
import io.github.jeffshee.visualizer.painters.Painter | ||
import io.github.jeffshee.visualizer.utils.VisualizerHelper | ||
|
||
class Scale : Painter { | ||
var painters: List<Painter> | ||
var wR: Float | ||
var hR: Float | ||
var pxR: Float | ||
var pyR: Float | ||
|
||
constructor(painters: List<Painter>, wR: Float = 1f, hR: Float = 1f, pxR: Float = .5f, pyR: Float = .5f) { | ||
this.painters = painters | ||
this.wR = wR | ||
this.hR = hR | ||
this.pxR = pxR | ||
this.pyR = pyR | ||
|
||
} | ||
|
||
constructor(painter: Painter, wR: Float = 1f, hR: Float = 1f, pxR: Float = .5f, pyR: Float = .5f) : this( | ||
listOf(painter), wR, hR, pxR, pyR | ||
) | ||
|
||
override fun draw(canvas: Canvas, helper: VisualizerHelper) { | ||
canvas.save() | ||
canvas.scale(wR, hR, pxR * canvas.width, pyR * canvas.height) | ||
painters.forEach { painter -> | ||
painter.draw(canvas, helper) | ||
} | ||
canvas.restore() | ||
} | ||
} |
This file contains 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
61 changes: 61 additions & 0 deletions
61
visualizer/src/main/java/io/github/jeffshee/visualizer/painters/modifier/Shake.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package io.github.jeffshee.visualizer.painters.modifier | ||
|
||
import android.graphics.Canvas | ||
import io.github.jeffshee.visualizer.painters.Painter | ||
import io.github.jeffshee.visualizer.utils.VisualizerHelper | ||
import kotlin.math.* | ||
import kotlin.random.Random | ||
|
||
class Shake : Painter { | ||
var painters: List<Painter> | ||
var xR: Float | ||
var yR: Float | ||
var shaker: Shaker | ||
|
||
constructor(painters: List<Painter>, xR: Float = .05f, yR: Float = .05f, shaker: Shaker = Shaker()) { | ||
this.painters = painters | ||
this.xR = xR | ||
this.yR = yR | ||
this.shaker = shaker | ||
} | ||
|
||
constructor(painter: Painter, xR: Float = .05f, yR: Float = .05f, shaker: Shaker = Shaker()) : this( | ||
listOf(painter), xR, yR, shaker | ||
) | ||
|
||
override fun draw(canvas: Canvas, helper: VisualizerHelper) { | ||
shaker.update() | ||
drawHelper(canvas, "a", xR * shaker.x, yR * shaker.y) { | ||
painters.forEach { painter -> | ||
painter.draw(canvas, helper) | ||
} | ||
} | ||
} | ||
|
||
class Shaker { | ||
var x = 0f | ||
var y = 0f | ||
var v = .01f | ||
var theta = 0f | ||
|
||
private val range = toRad(60f) | ||
private val pi = PI.toFloat() | ||
|
||
fun update() { | ||
if (x * x + y * y >= 1f) { | ||
theta = toCenter() + range * Random.nextFloat() - range / 2f | ||
} | ||
x += v * cos(theta) | ||
y += v * sin(theta) | ||
} | ||
|
||
private fun toCenter(): Float { | ||
return pi + atan2(y, x) | ||
} | ||
|
||
private fun toRad(deg: Float): Float { | ||
return deg / 180f * PI.toFloat() | ||
} | ||
|
||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
visualizer/src/main/java/io/github/jeffshee/visualizer/painters/modifier/Zoom.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.github.jeffshee.visualizer.painters.modifier | ||
|
||
import android.graphics.Canvas | ||
import io.github.jeffshee.visualizer.painters.Painter | ||
import io.github.jeffshee.visualizer.utils.VisualizerHelper | ||
import kotlin.math.* | ||
import kotlin.random.Random | ||
|
||
class Zoom : Painter { | ||
var painters: List<Painter> | ||
var xR: Float | ||
var yR: Float | ||
var zoomer: Zoomer | ||
|
||
constructor(painters: List<Painter>, xR: Float = .05f, yR: Float = .05f, zoomer: Zoomer = Zoomer()) { | ||
this.painters = painters | ||
this.xR = xR | ||
this.yR = yR | ||
this.zoomer = zoomer | ||
} | ||
|
||
constructor(painter: Painter, xR: Float = .05f, yR: Float = .05f, zoomer: Zoomer = Zoomer()) : this( | ||
listOf(painter), xR, yR, zoomer | ||
) | ||
|
||
override fun draw(canvas: Canvas, helper: VisualizerHelper) { | ||
zoomer.update() | ||
canvas.save() | ||
canvas.scale(1f + .1f*zoomer.x,1f + .1f*zoomer.x, canvas.width/2f, canvas.height/2f) | ||
painters.forEach { painter -> | ||
painter.draw(canvas, helper) | ||
} | ||
canvas.restore() | ||
} | ||
|
||
class Zoomer { | ||
var x = 0f | ||
var v = .01f | ||
|
||
fun update() { | ||
if (abs(x) >= 1f) { | ||
v = -v | ||
} | ||
x += v | ||
} | ||
|
||
} | ||
} |