Skip to content

Instantly share code, notes, and snippets.

@hamoid
Created March 25, 2023 22:07
Show Gist options
  • Save hamoid/83ec8c4e763096778d73ac2a16752246 to your computer and use it in GitHub Desktop.
Save hamoid/83ec8c4e763096778d73ac2a16752246 to your computer and use it in GitHub Desktop.
OPENRNDR experimentation session with Alessandro and aBe, day 4, episode 5
// By Alessandro and aBe
// Saturday March 25th, 2023
// https://tubedu.org/c/in_conversations_collections/videos
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.color.rgb
import org.openrndr.draw.*
import org.openrndr.extra.color.presets.BLANCHED_ALMOND
import org.openrndr.extra.noise.Random
import org.openrndr.extra.noise.simplex
import org.openrndr.extra.olive.oliveProgram
import org.openrndr.extra.shadestyles.NPointRadialGradient
import org.openrndr.extra.shapes.hobbyCurve
import org.openrndr.math.IntVector2
import org.openrndr.math.Polar
import org.openrndr.math.map
import org.openrndr.shape.ShapeContour
fun main() = application {
configure {
width = 700
height = 900
position = IntVector2(1920 - width - 60, 80)
}
oliveProgram {
val rt = renderTarget(width, height) {
colorBuffer(type = ColorType.FLOAT32)
depthBuffer()
}
val previous = colorBuffer(
width, height,
type = ColorType.FLOAT32
)
val current = colorBuffer(
width, height,
type = ColorType.FLOAT32
)
val angles = List(10) {
Random.double0(360.0)
}.sorted()
val effect = shadeStyle {
fragmentTransform = """
float t = c_contourPosition / p_length;
t = abs(t * 2 - 1);
vec3 col = mix(
vec3(1.0, 0.6, 0.1),
vec3(0.1, 0.1, 0.3),
t);
x_stroke.rgb = col;
x_stroke.a = 0.1;
""".trimIndent()
}
val gradient = NPointRadialGradient(
arrayOf(
ColorRGBa.BLANCHED_ALMOND.opacify(0.0),
ColorRGBa.BLANCHED_ALMOND.opacify(0.015),
ColorRGBa.BLANCHED_ALMOND.opacify(0.0)
),
arrayOf(0.6, 0.8, 1.0)
)
extend {
val c = ShapeContour.fromPoints(
angles.map {
Polar(
it,
200 + 100 * simplex(1, it, seconds * 0.1)
).cartesian + drawer.bounds.center
},
true
).hobbyCurve()
val length = c.length
effect.parameter("length", length)
val points = c.equidistantPositions(20)
drawer.isolatedWithTarget(rt) {
clear(rgb(0.00))
stroke = ColorRGBa.WHITE
strokeWeight = 4.0
fill = null
shadeStyle = effect
effect.parameter("time", seconds)
contour(c)
shadeStyle = gradient
stroke = null
strokeWeight = 1.0
fill = ColorRGBa.WHITE
points.forEachIndexed { i, it ->
val r = simplex(
0,
it.x * 0.05, it.y * 0.05, seconds * 0.2
).map(-1.0, 1.0, 0.2, 0.8)
val off = 0.2
gradient.points = arrayOf(r - off, r, r + off)
circle(it, 150.0)
}
}
rt.colorBuffer(0).copyTo(current)
drawer.isolatedWithTarget(rt) {
clear(ColorRGBa.TRANSPARENT)
fill = ColorRGBa.WHITE
stroke = null
shadeStyle = shadeStyle {
fragmentTransform = """
vec2 coords = c_boundsPosition.xy;
coords.y = 1.0 - coords.y;
vec4 curr = texture(p_curr, coords);
vec4 prev = texture(p_prev, coords);
x_fill = curr;
x_fill.rgb += prev.rgb * 0.95;
""".trimIndent()
parameter("curr", current)
parameter("prev", previous)
}
rectangle(drawer.bounds)
}
rt.colorBuffer(0).copyTo(previous)
drawer.image(previous)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment