Created
August 26, 2020 16:06
-
-
Save ylegall/3511bc37ce3f2b7d70fe646d37fefab4 to your computer and use it in GitHub Desktop.
openRNDR code for https://imgur.com/gallery/pyhAILS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.ygl.openrndr.demos | |
import org.openrndr.Application | |
import org.openrndr.application | |
import org.openrndr.draw.shadeStyle | |
import org.openrndr.extra.compositor.compose | |
import org.openrndr.extra.compositor.draw | |
import org.openrndr.extra.compositor.post | |
import org.openrndr.extra.fx.blur.ZoomBlur | |
import org.openrndr.ffmpeg.ScreenRecorder | |
import org.ygl.openrndr.utils.colorMapBufferTextureFromStrings | |
import org.ygl.openrndr.utils.doubleArrayBufferTexture | |
import org.ygl.openrndr.utils.shaderColorMap | |
import java.io.File | |
import kotlin.random.Random | |
private const val WIDTH = 920 | |
private const val HEIGHT = 920 | |
private const val TOTAL_FRAMES = 360 * 4 | |
private const val RECORDING = true | |
fun main() = application { | |
configure { | |
width = WIDTH | |
height = HEIGHT | |
} | |
program { | |
var time = 0.0 | |
val rays = 48 | |
val rng = Random(6) | |
val colors = listOf( | |
"233041","4979a1","8674a3","e88873","ffd6b4" | |
) | |
val colorBufferTexture = colorMapBufferTextureFromStrings(colors) | |
val offsets = doubleArrayBufferTexture(List(rays) { rng.nextDouble() }) | |
val noiseFragShader = Application::class.java.getResource("/shaders/simplexNoise2D.glsl").readText() | |
val composite = compose { | |
draw { | |
drawer.shadeStyle = shadeStyle { | |
fragmentPreamble = shaderColorMap(colors.size) + noiseFragShader + | |
""" | |
float cubicPulse(float c, float w, float x) { | |
x = abs(x - c); | |
if (x > w) return 0.0; | |
x /= w; | |
return 1.0 - x * x * (3.0 - 2.0 * x); | |
} | |
""".trimIndent() | |
fragmentTransform = """ | |
const float PI = 3.14159265359; | |
vec2 pos = vec2(c_boundsPosition.x - 0.5, 1 - c_boundsPosition.y - 0.5); | |
float d = length(pos); | |
float dist = mix(sqrt(d), 0.2 / d, smoothstep(0.0, 0.2, d)); | |
float noiseAngle = 2 * PI * (dist + p_time); | |
vec2 noiseInput = vec2( | |
0.4 * cos(noiseAngle), | |
0.4 * sin(noiseAngle) | |
); | |
float noiseValue = 0.1 * snoise(noiseInput); | |
float angle = 0.5 + 0.5 * (atan(pos.y, pos.x) / PI); | |
float phase = fract(angle + noiseValue); | |
int colorIndex = int(phase * p_rays); | |
vec4 color = getColor(texelFetch(p_offsets, colorIndex).r); | |
color *= smoothstep(0.0, 0.04, d); | |
color += (-0.05 + 0.1 * cubicPulse(0.5, 0.5, fract(angle + 0.25))); | |
color *= clamp(0.55 + cubicPulse(0.5, 0.5, fract(angle + 0.25)), 0, 1); | |
x_fill = color; | |
""".trimIndent() | |
parameter("time", (2 * time)) | |
parameter("colorMap", colorBufferTexture) | |
parameter("offsets", offsets) | |
parameter("rays", rays) | |
} | |
drawer.rectangle(drawer.bounds) | |
} | |
} | |
if (RECORDING) { | |
extend(ScreenRecorder()) { | |
outputFile = "video/ColorRadials.mp4" | |
frameRate = 60 | |
frameClock = true | |
} | |
} | |
extend { | |
time = ((frameCount - 1) % TOTAL_FRAMES) / TOTAL_FRAMES.toDouble() | |
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