Skip to content

Instantly share code, notes, and snippets.

@silmood
Created April 21, 2021 03:06
Show Gist options
  • Select an option

  • Save silmood/3fb7465c4b45782f136372a5dbe4fa0a to your computer and use it in GitHub Desktop.

Select an option

Save silmood/3fb7465c4b45782f136372a5dbe4fa0a to your computer and use it in GitHub Desktop.
fun main() = application {
configure {
width = 500
height = 500
}
program {
val size = 3 * width / 4.0
val easer = SineInOut()
val duration = 50.0
var frame = 0
val mapEase = { left: Double, right: Double, ease: Double ->
map(0.0, 1.0, left, right, ease)
}
val mapSinEase = { left: Double, right: Double, ease: Double ->
sin(mapEase(left, right, ease))
}
extend {
drawer.clear(ColorRGBa.BLACK)
drawer.translate(width / 2.0, height / 2.0)
drawer.drawStyle.blendMode = BlendMode.ADD
for (i in 1..20) {
val ringOffset = i * 48.18;
val radius = map(1.0, 20.0, 30.0, size / 2, i.toDouble())
val maxW = map(1.0, 20.0, 1.0, 7.0, i.toDouble())
val positions = ((radius / maxW) * 3.2).roundToInt()
val points = Circle(0.0, 0.0, radius).contour.equidistantPositions(positions)
val rot = (360.0 / positions) * (positions / 4)
drawer.circles {
points.forEachIndexed { index, position ->
if (index == points.size - 1) return@circles
val pos = position.rotate(rot)
val theta = atan2(pos.y, pos.x)
val maxPos = Vector2(
x = (radius * 1.3) * cos(theta),
y = (radius * 1.3) * sin(theta)
)
val pointOffset = map(0.0, positions.toDouble(), 0.0, 50.0, index.toDouble());
val pointTime = (frameCount + ringOffset + pointOffset) % duration
val ease = easer.ease(pointTime, 0.0, 1.0, duration)
val x = mapEase(pos.x, maxPos.x, ease)
val y = mapEase(pos.y, maxPos.y, ease)
val alpha1 = mapSinEase(PI * 0.65, PI.div(2.0).div(16.0), ease)
val alpha2 = mapSinEase(PI.div(2.0).div(6.0), PI * 0.4, ease)
val alpha3 = mapSinEase(0.0, PI - PI.div(2.0).div(6.0), ease)
var wAdjusted = mapSinEase(0.0, PI, ease) * maxW
wAdjusted = if (wAdjusted < 0.5) 0.0 else wAdjusted
stroke = null
fill = ColorRGBa(1.0, 0.0, 0.0, alpha1)
circle(x - (wAdjusted * 0.7), y, wAdjusted)
fill = ColorRGBa(0.0, 0.0, 1.0, alpha2)
circle(x + (wAdjusted * 0.7), y, wAdjusted)
fill = ColorRGBa(0.0, 1.0, 0.0, alpha3)
circle(x, y, wAdjusted)
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment