Skip to content

Commit

Permalink
Some minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
igr committed May 5, 2024
1 parent b9db910 commit 57d6892
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
4 changes: 2 additions & 2 deletions arts/falllines/src/main/kotlin/dev/oblac/gart/Falllines.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import dev.oblac.gart.color.alpha
import dev.oblac.gart.color.rgb
import dev.oblac.gart.gfx.fillOf
import dev.oblac.gart.math.GOLDEN_RATIO
import dev.oblac.gart.pixels.scrollPixelsUp
import dev.oblac.gart.pixels.scrollUp
import org.jetbrains.skia.Canvas
import org.jetbrains.skia.Rect
import kotlin.random.Random
Expand Down Expand Up @@ -104,7 +104,7 @@ private fun <T> Array<T>.switch(a: Int, b: Int): Array<T> {

fun draw(canvas: Canvas) {
b.updatePixelsFromCanvas()
scrollPixelsUp(b, 1)
b.scrollUp(1)

for (x in 0 until w) {
val g = Random.nextInt(30)
Expand Down
9 changes: 9 additions & 0 deletions gart/src/main/kotlin/dev/oblac/gart/gfx/points.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dev.oblac.gart.gfx

import dev.oblac.gart.Dimension
import dev.oblac.gart.math.Vector
import dev.oblac.gart.math.dist
import org.jetbrains.skia.Point

fun Point.isInside(dimension: Dimension) =
Expand All @@ -16,3 +17,11 @@ fun Point.fromCenter(d: Dimension, fl: Float = 1f): Point {
val y = d.cy + y * fl
return Point(x, y)
}

/**
* Returns the distance between two points.
* @see dist
*/
fun Point.distanceTo(p: Point): Float {
return dist(this, p)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,3 @@ fun dist(p1: Point, p2: Point): Float {
return dist(p1.x, p1.y, p2.x, p2.y)
}

/**
* Returns the distance between two points.
* @see dist
*/
fun Point.distanceTo(p: Point): Float {
return dist(this, p)
}
11 changes: 7 additions & 4 deletions gart/src/main/kotlin/dev/oblac/gart/pixels/pixelsScroller.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package dev.oblac.gart.pixels

import dev.oblac.gart.Pixels

fun scrollPixelsUp(p: Pixels, delta: Int) {
for (y in delta until p.d.h) {
for (x in 0 until p.d.w) {
p[x, y - delta] = p[x, y]
/**
* Scrolls the pixels up by the given delta.
*/
fun Pixels.scrollUp(delta: Int) {
for (y in delta until this.d.h) {
for (x in 0 until this.d.w) {
this[x, y - delta] = this[x, y]
}
}
}

0 comments on commit 57d6892

Please sign in to comment.