Skip to content

Instantly share code, notes, and snippets.

@ylegall
Created August 21, 2020 15:39
Show Gist options
  • Save ylegall/83802ef02e5ab8c87cde4912cd4b1230 to your computer and use it in GitHub Desktop.
Save ylegall/83802ef02e5ab8c87cde4912cd4b1230 to your computer and use it in GitHub Desktop.
triangle spiral
package org.ygl.openrndr.demos
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.color.rgb
import org.openrndr.draw.LineCap
import org.openrndr.draw.LineJoin
import org.openrndr.extra.compositor.compose
import org.openrndr.extra.compositor.draw
import org.openrndr.extra.compositor.post
import org.openrndr.extra.fx.antialias.FXAA
import org.openrndr.extra.shapes.regularPolygonRounded
import org.openrndr.ffmpeg.ScreenRecorder
import org.openrndr.math.Vector2
import org.openrndr.math.transforms.transform
import org.openrndr.shape.ShapeContour
import org.openrndr.shape.compound
import org.openrndr.shape.contour
import org.ygl.openrndr.demos.util.GlamourBlur
import kotlin.math.PI
import kotlin.math.sin
private const val WIDTH = 920
private const val HEIGHT = 920
private const val TOTAL_FRAMES = 360
private const val RECORDING = true
fun main() = application {
configure {
width = WIDTH
height = HEIGHT
}
program {
var time = 0.0
val bgColor = rgb("EDE8C1")
val fgColor = rgb("2e294e")
val numPoints = 8000
val shape = regularPolygonRounded(3, radius = 20.0)
val points = MutableList(numPoints) { Vector2.ZERO }
val turns = 60
fun computePath() {
for (i in 0 until numPoints) {
val pct = i / (numPoints - 0.0)
val position = (time + turns * pct) % 1.0
points[i] = shape.position(position).rotate(15 * sin(2 * PI * (pct + time))) * (pct * 80)
}
}
val frame = compound {
difference {
shape(drawer.bounds.moved(-drawer.bounds.center).shape)
shape(drawer.bounds.moved(-drawer.bounds.center).offsetEdges(-50.0).shape)
}
}
val composite = compose {
draw {
drawer.clear(bgColor)
drawer.lineCap = LineCap.ROUND
drawer.lineJoin = LineJoin.ROUND
drawer.stroke = fgColor//.opacify(0.8)
drawer.strokeWeight = 6.0
drawer.contour(ShapeContour.fromPoints(points, false))
drawer.stroke = fgColor
drawer.fill = bgColor
drawer.shapes(frame)
}
}
if (RECORDING) {
extend(ScreenRecorder()) {
outputFile = "video/TriangleSpiral.mp4"
frameRate = 60
frameClock = true
}
}
extend {
drawer.translate(drawer.bounds.center)
time = ((frameCount - 1) % TOTAL_FRAMES) / TOTAL_FRAMES.toDouble()
computePath()
composite.draw(drawer)
if (RECORDING) {
if (frameCount >= TOTAL_FRAMES) {
application.exit()
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment