Skip to content

Instantly share code, notes, and snippets.

@silmood
Last active June 1, 2021 21:27
Show Gist options
  • Select an option

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

Select an option

Save silmood/b84df9d4a80fc451dbdf6e9d91a2393f to your computer and use it in GitHub Desktop.
fun main() = application {
configure {
width = 520
height = 520
}
program {
val size = 5 * width / 6.0
val xOffset = -size / 2.0
val yOffset = -size / 2.0
val frame = Circle(0.0, 0.0, size/2.0)
val easer = SineInOut()
val easerOut = CubicOut()
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))
}
val points = poissonDiskSampling(size, size, size/9.0).map {
it.minus(Vector2(size/2.0, size/2.0))
}.filter { frame.contains(it) }
val deluanay = Delaunay.from(points + frame.contour.equidistantPositions(20))
val triangles = deluanay.triangles()
extend {
drawer.drawStyle.blendMode = BlendMode.ADD
drawer.clear(ColorRGBa.BLACK)
drawer.translate(width / 2.0, height / 2.0)
drawer.circles {
triangles.forEach { triangle ->
val triangleOffset =
Vector2(0.0, triangle.centroid.y).distanceTo(Vector2(0.0, frame.radius)) * -0.2549
triangle.contour.equidistantPositions(25).forEachIndexed { index, start ->
val segment = Segment(start, triangle.centroid)
val segmentOffset = index * -1.204933 //(index * map( 0.0, width.toDouble(), -2.0, 2.0, mouse.position.y ))
for (point in 0 until 15) {
val pointTimeOffset = point * 1.5
val pointTime = (frameCount + pointTimeOffset + triangleOffset + segmentOffset) % 100.0
val pointEase = easer.ease(pointTime, 0.0, 1.0, 100.0)
val inverseEase = mapEase(1.0, 0.0, pointEase)
val position = segment.position(pointEase)
val alpha1 = mapSinEase(PI * 0.0, PI, pointEase)
val alpha2 = mapSinEase(PI * 0.0, PI, pointEase)
val alpha3 = mapSinEase(PI * 0.0, PI, pointEase)
val offset = mapSinEase(PI * 0.0, PI, pointEase) * 0.055
val rPos = segment.position(pointEase - offset)
val bPos = segment.position(pointEase + offset)
val radius = mapSinEase(PI * 0.4, PI, pointEase) * 1.2
if (radius > 0.5) {
stroke = null
fill = ColorRGBa(1.0, 0.0, 0.0, alpha1)
circle(rPos, radius)
fill = ColorRGBa(0.0, 0.0, 1.0, alpha2)
circle(bPos, radius)
fill = ColorRGBa(0.0, 1.0, 0.0, alpha3)
circle(position, radius)
}
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment