Skip to content

Commit

Permalink
add dots
Browse files Browse the repository at this point in the history
  • Loading branch information
igr committed Feb 3, 2024
1 parent c9a10e7 commit 94a998d
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 5 deletions.
1 change: 1 addition & 0 deletions arts/circledots/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# gȧrt : Dots. Wave. Flash.

![](circledots.png)
![](circledots2.png)
Binary file added arts/circledots/circledots2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import dev.oblac.gart.gfx.fillOfWhite
import dev.oblac.gart.skia.Rect
import kotlin.time.Duration.Companion.seconds

val gart = Gart.of(
private val gart = Gart.of(
"CircleDots",
640, 640,
50
)

const val rowCount = 25
val gap = gart.d.w / (rowCount - 2)
private const val rowCount = 25
private val gap = gart.d.w / (rowCount - 2)

val ctx = Context(gart.g)
private val ctx = Context(gart.g)

val circles = Array(rowCount * rowCount) {
private val circles = Array(rowCount * rowCount) {
val row = it.div(rowCount)
val column = it.mod(rowCount)
Circle(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package dev.oblac.gart.circledots.v2

import dev.oblac.gart.circledots.Context
import dev.oblac.gart.gfx.Colors
import dev.oblac.gart.gfx.Palettes
import dev.oblac.gart.gfx.fillOf
import dev.oblac.gart.gfx.fillOfBlack

data class Circle2Anim(private val ctx: Context, val x: Float, val y: Float, val r: Float, var deg: Float, var speed: Float = 3f, val from: Int) {
var tick = 0
private val fill = fillOf(palette.getSafe(from))
fun draw() {
tick++
//ctx.g.canvas.drawCircle(x, y, r, blackStroke)

val x2 = x + ctx.mcos[deg] * r
val y2 = y - ctx.msin[deg] * r

ctx.g.canvas.drawCircle(x2, y2, 20f, fill)

if (tick > from) {
deg += speed
}
}

companion object {
private val blackFill = fillOfBlack()
private val palette = Palettes.gradient(Colors.black, Colors.white, 110) +
Palettes.gradient(Colors.white, Colors.black, 110)

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package dev.oblac.gart.circledots.v2

import dev.oblac.gart.Gart
import dev.oblac.gart.Media
import dev.oblac.gart.circledots.Context
import dev.oblac.gart.gfx.Colors
import kotlin.math.PI
import kotlin.math.cos
import kotlin.math.sin

private val gart = Gart.of(
"CircleDots2",
640, 640,
50
)
private val ctx = Context(gart.g)

fun main() {
with(gart) {

println(name)

var tick = 0

val ccs = createAnimation(320, 320, 220)

w.show()
a.draw {
tick++
if (tick > 440) {
a.record()
}
g.fill(Colors.black)
for (cc in ccs) {
cc.draw()
}
if (tick == 2000) {
a.stop()
return@draw
}
}
Media.saveImage(this, "circledots2.png")
Media.saveVideo(this, "circledots2.mp4")
}

}

private fun createAnimation(x: Int, y: Int, count: Int): Array<Circle2Anim> {
val delta = 2 * PI / count
var offset = 0.0
return Array(count) {
val angle = it * delta + offset
offset += delta
Circle2Anim(
ctx = ctx,
x = (x + 200 * cos(angle)).toFloat(),
y = (y + 200 * sin(angle)).toFloat(),
r = 80f,
deg = it * PI.toFloat() * 2,
speed = 4f,
it * 2
)
}
}

0 comments on commit 94a998d

Please sign in to comment.