Demos: ensure 720px wide, reduce indentation

openrndr-demos, orx-color, orx-jumpflood, orx-no-clear
This commit is contained in:
Abe Pazos
2025-01-25 13:30:18 +01:00
parent f84bf69713
commit fc4f7275fb
74 changed files with 1314 additions and 1293 deletions

View File

@@ -1,16 +1,13 @@
import org.openrndr.application import org.openrndr.application
import org.openrndr.draw.loadImage import org.openrndr.draw.loadImage
fun main() { fun main() = application {
application { program {
program { val image16 = loadImage("demo-data/images/16-bit.png")
val image16 = loadImage("demo-data/images/16-bit.png") val image8 = loadImage("demo-data/images/image-001.png")
val image8 = loadImage("demo-data/images/image-001.png") extend {
extend { drawer.image(image16)
drawer.image(image16) drawer.image(image8, 320.0, 0.0)
drawer.image(image8, 320.0, 0.0)
}
} }
} }
} }

View File

@@ -1,15 +1,13 @@
import org.openrndr.application import org.openrndr.application
import org.openrndr.internal.colorBufferLoader import org.openrndr.internal.colorBufferLoader
fun main() { fun main() = application {
application { program {
program { extend {
extend { val proxy = colorBufferLoader.loadFromUrl("https://avatars3.githubusercontent.com/u/31103334?s=200&v=4")
val proxy = colorBufferLoader.loadFromUrl("https://avatars3.githubusercontent.com/u/31103334?s=200&v=4") proxy.colorBuffer?.let {
proxy.colorBuffer?.let { drawer.image(it)
drawer.image(it)
}
} }
} }
} }
} }

View File

@@ -11,14 +11,12 @@ import org.openrndr.math.Vector3
fun main() = application { fun main() = application {
configure { configure {
multisample = WindowMultisample.SampleCount(8) multisample = WindowMultisample.SampleCount(8)
} }
program { program {
extend(Orbital()) extend(Orbital())
val circlePositions = vertexBuffer(vertexFormat { val circlePositions = vertexBuffer(vertexFormat {
attribute("position", VertexElementType.VECTOR3_FLOAT32) attribute("position", VertexElementType.VECTOR3_FLOAT32)
attribute("scale", VertexElementType.FLOAT32) attribute("scale", VertexElementType.FLOAT32)
@@ -31,7 +29,6 @@ fun main() = application {
} }
} }
extend { extend {
drawer.perspective(90.0, width*1.0/height*1.0, 0.1, 100.0) drawer.perspective(90.0, width*1.0/height*1.0, 0.1, 100.0)

View File

@@ -9,7 +9,9 @@ import org.openrndr.shape.ShapeContour
fun main() = application { fun main() = application {
program { program {
val points = List(6) { Polar(it * 70.0, 100.0).cartesian + drawer.bounds.center } val points = List(6) {
Polar(it * 70.0, 100.0).cartesian + drawer.bounds.center
}
val cmr = CatmullRomChain2(points, 1.0, loop = true) val cmr = CatmullRomChain2(points, 1.0, loop = true)
val contour = ShapeContour.fromPoints(cmr.positions(200), true) val contour = ShapeContour.fromPoints(cmr.positions(200), true)

View File

@@ -10,7 +10,6 @@ This program demonstrates dynamic circle batches
fun main() = application { fun main() = application {
program { program {
extend { extend {
drawer.clear(ColorRGBa.GRAY) drawer.clear(ColorRGBa.GRAY)
drawer.circles { drawer.circles {

View File

@@ -12,7 +12,6 @@ fun main() {
} }
program { program {
val cs = Rectangle(0.0, 0.0, 200.0, 200.0).contour val cs = Rectangle(0.0, 0.0, 200.0, 200.0).contour
val cc = Circle(100.0, 0.0, 100.0).contour val cc = Circle(100.0, 0.0, 100.0).contour

View File

@@ -5,33 +5,35 @@ import org.openrndr.shape.Circle
import org.openrndr.shape.Rectangle import org.openrndr.shape.Rectangle
import org.openrndr.shape.intersections import org.openrndr.shape.intersections
fun main() { fun main() = application {
application { program {
program { extend {
extend { val circle = Circle(mouse.position, 200.0).contour
val circle = Circle(mouse.position, 200.0).contour
drawer.fill = null drawer.fill = null
for (y in 50 until height step 100) { for (y in 50 until height step 100) {
for (x in 50 until width step 100) { for (x in 50 until width step 100) {
for (ring in 0 until 10) { for (ring in 0 until 10) {
val r = Rectangle.fromCenter(Vector2(x * 1.0, y * 1.0), 90.0 - ring * 8.0, 90.0 - ring * 8.0).contour val r = Rectangle.fromCenter(
Vector2(x * 1.0, y * 1.0),
90.0 - ring * 8.0,
90.0 - ring * 8.0
).contour
val ints = intersections(circle, r) val ints = intersections(circle, r)
if (ints.isEmpty()) { if (ints.isEmpty()) {
drawer.stroke = ColorRGBa.GREEN drawer.stroke = ColorRGBa.GREEN
drawer.contour(r) drawer.contour(r)
} else { } else {
drawer.stroke = ColorRGBa.WHITE drawer.stroke = ColorRGBa.WHITE
ints.map { it.b.contourT }.let { it + it.take(1) }.zipWithNext().forEach { ints.map { it.b.contourT }.let { it + it.take(1) }.zipWithNext().forEach {
val end = if (it.second <= it.first) it.second + 1.0 else it.second val end = if (it.second <= it.first) it.second + 1.0 else it.second
val sub = r.sub(it.first, end) val sub = r.sub(it.first, end)
val length = sub.length val length = sub.length
val ta = sub.tForLength(2.0) val ta = sub.tForLength(2.0)
val tb = sub.tForLength(length - 2.0) val tb = sub.tForLength(length - 2.0)
drawer.contour(sub.sub(ta, tb)) drawer.contour(sub.sub(ta, tb))
}
} }
} }
} }
@@ -39,4 +41,4 @@ fun main() {
} }
} }
} }
} }

View File

@@ -12,12 +12,12 @@ fun main() = application {
val points = 200 val points = 200
extend { extend {
val contour = ShapeContour.fromPoints( val contour = ShapeContour.fromPoints(
List(points) { List(points) {
val a = PI * 2 * it / points val a = PI * 2 * it / points
val x = (200 + 50 * cos(a * 2)) * sin(a * 3 + sin(a)) val x = (200 + 50 * cos(a * 2)) * sin(a * 3 + sin(a))
val y = 150 * cos(a * 2 + seconds * 0.2) val y = 150 * cos(a * 2 + seconds * 0.2)
Vector2(x, y) Vector2(x, y)
}, closed = true }, closed = true
) )
val ints = intersections(contour, contour) val ints = intersections(contour, contour)
drawer.run { drawer.run {

View File

@@ -1,16 +1,17 @@
import org.openrndr.application import org.openrndr.application
import org.openrndr.draw.* import org.openrndr.draw.DrawPrimitive
import org.openrndr.draw.Session
import org.openrndr.draw.loadCubemap
import org.openrndr.draw.shadeStyle
import org.openrndr.extra.camera.Orbital import org.openrndr.extra.camera.Orbital
import org.openrndr.extra.meshgenerators.boxMesh import org.openrndr.extra.meshgenerators.boxMesh
fun main() = application { fun main() = application {
program { program {
val cubemap = loadCubemap("demo-data/cubemaps/garage_iem.dds", null, session = Session.active) val cubemap = loadCubemap("demo-data/cubemaps/garage_iem.dds", null, session = Session.active)
val cube = boxMesh() val cube = boxMesh()
extend(Orbital()) {
} extend(Orbital())
extend { extend {
drawer.shadeStyle = shadeStyle { drawer.shadeStyle = shadeStyle {
fragmentTransform = """ fragmentTransform = """

View File

@@ -7,13 +7,17 @@ fun main() = application {
program { program {
val cubemap1 = loadCubemap("demo-data/cubemaps/garage_iem.dds", null, session = Session.active) val cubemap1 = loadCubemap("demo-data/cubemaps/garage_iem.dds", null, session = Session.active)
val cube = boxMesh() val cube = boxMesh()
val cubemap2 = cubemap(cubemap1.width, format = cubemap1.format, type = cubemap1.type, levels = 2, session = Session.active) val cubemap2 = cubemap(
cubemap1.width,
format = cubemap1.format,
type = cubemap1.type,
levels = 2,
session = Session.active
)
cubemap1.copyTo(cubemap2, 0, 0) cubemap1.copyTo(cubemap2, 0, 0)
cubemap2.generateMipmaps() cubemap2.generateMipmaps()
extend(Orbital()) { extend(Orbital())
}
extend { extend {
drawer.shadeStyle = shadeStyle { drawer.shadeStyle = shadeStyle {
fragmentTransform = """ fragmentTransform = """

View File

@@ -7,7 +7,13 @@ fun main() = application {
program { program {
val cubemap1 = loadCubemap("demo-data/cubemaps/garage_iem.dds", null, session = Session.active) val cubemap1 = loadCubemap("demo-data/cubemaps/garage_iem.dds", null, session = Session.active)
val cube = boxMesh() val cube = boxMesh()
val cubemap2 = cubemap(cubemap1.width, format = cubemap1.format, type = cubemap1.type, levels = 2, session = Session.active) val cubemap2 = cubemap(
cubemap1.width,
format = cubemap1.format,
type = cubemap1.type,
levels = 2,
session = Session.active
)
cubemap1.copyTo(cubemap2, 0, 0) cubemap1.copyTo(cubemap2, 0, 0)
cubemap2.generateMipmaps() cubemap2.generateMipmaps()
@@ -18,9 +24,7 @@ fun main() = application {
cma.generateMipmaps() cma.generateMipmaps()
extend(Orbital()) { extend(Orbital())
}
extend { extend {
drawer.shadeStyle = shadeStyle { drawer.shadeStyle = shadeStyle {
fragmentTransform = """ fragmentTransform = """

View File

@@ -1,15 +1,13 @@
import org.openrndr.application import org.openrndr.application
import org.openrndr.draw.loadImage import org.openrndr.draw.loadImage
fun main() { fun main() = application {
application { program {
program { val image = loadImage("demo-data/images/image-001.dds")
val image = loadImage("demo-data/images/image-001.dds") println(image.format)
println(image.format) println(image.type)
println(image.type) extend {
extend { drawer.image(image)
drawer.image(image)
}
} }
} }
} }

View File

@@ -6,27 +6,25 @@ import org.openrndr.extra.camera.Orbital
import org.openrndr.extra.meshgenerators.boxMesh import org.openrndr.extra.meshgenerators.boxMesh
import org.openrndr.resourceText import org.openrndr.resourceText
fun main() { fun main() = application {
application { program {
program { val vb = boxMesh()
val vb = boxMesh() val shader = Shader.createFromCode(
val shader = Shader.createFromCode( vsCode = resourceText("/shaders/gs-01.vert"),
vsCode = resourceText("/shaders/gs-01.vert"), gsCode = resourceText("/shaders/gs-01.geom"),
gsCode = resourceText("/shaders/gs-01.geom"), fsCode = resourceText("/shaders/gs-01.frag"),
fsCode = resourceText("/shaders/gs-01.frag"), name = "x"
name = "x" )
) extend(Orbital())
extend(Orbital()) extend {
extend { drawer.clear(ColorRGBa.PINK)
drawer.clear(ColorRGBa.PINK) shader.begin()
shader.begin() shader.uniform("offset", mouse.position.xy0)
shader.uniform("offset", mouse.position.xy0) shader.uniform("view", drawer.view)
shader.uniform("view", drawer.view) shader.uniform("proj", drawer.projection)
shader.uniform("proj", drawer.projection) shader.uniform("model", drawer.model)
shader.uniform("model", drawer.model) driver.drawVertexBuffer(shader, listOf(vb), DrawPrimitive.TRIANGLES, 0, vb.vertexCount)
driver.drawVertexBuffer(shader, listOf(vb), DrawPrimitive.TRIANGLES, 0, vb.vertexCount) shader.end()
shader.end()
}
} }
} }
} }

View File

@@ -5,12 +5,11 @@ import org.openrndr.extra.meshgenerators.planeMesh
import org.openrndr.internal.Driver import org.openrndr.internal.Driver
import org.openrndr.math.Vector3 import org.openrndr.math.Vector3
fun main() = application { fun main() = application {
program { program {
val shader = Shader.createFromCode(
val shader = Shader.createFromCode(vsCode = vsCode =
"""${Driver.instance.shaderConfiguration()} """${Driver.instance.shaderConfiguration(ShaderType.VERTEX)}
in vec3 a_position; in vec3 a_position;
in vec2 a_texCoord0; in vec2 a_texCoord0;
in vec3 a_normal; in vec3 a_normal;
@@ -21,14 +20,15 @@ void main() {
gl_Position = projMatrix * vec4(a_position, 1.0); gl_Position = projMatrix * vec4(a_position, 1.0);
} }
""", """,
fsCode = """${Driver.instance.shaderConfiguration()} fsCode = """${Driver.instance.shaderConfiguration(ShaderType.FRAGMENT)}
out vec4 o_color; out vec4 o_color;
layout(rgba8) uniform writeonly image2D bla; layout(rgba8) uniform writeonly image2D bla;
void main() { void main() {
imageStore(bla, ivec2(30,30), vec4(1.0, 0.0, 0.0, 1.0)); imageStore(bla, ivec2(30,30), vec4(1.0, 0.0, 0.0, 1.0));
o_color = vec4(1.0); o_color = vec4(1.0);
} }
""", name = "ils") """, name = "ils"
)
val cb = colorBuffer(128, 128, type = ColorType.UINT8) val cb = colorBuffer(128, 128, type = ColorType.UINT8)
val mesh = planeMesh(Vector3.ZERO, Vector3.UNIT_X, Vector3.UNIT_Y, -Vector3.UNIT_Z, 100.0, 100.0) val mesh = planeMesh(Vector3.ZERO, Vector3.UNIT_X, Vector3.UNIT_Y, -Vector3.UNIT_Z, 100.0, 100.0)
@@ -44,6 +44,5 @@ void main() {
drawer.clear(ColorRGBa.BLACK) drawer.clear(ColorRGBa.BLACK)
drawer.image(cb) drawer.image(cb)
} }
} }
} }

View File

@@ -2,7 +2,6 @@ import org.openrndr.application
import org.openrndr.color.ColorRGBa import org.openrndr.color.ColorRGBa
import org.openrndr.draw.* import org.openrndr.draw.*
fun main() = application { fun main() = application {
program { program {
val cb = colorBuffer(128, 128, type = ColorType.UINT8) val cb = colorBuffer(128, 128, type = ColorType.UINT8)
@@ -15,7 +14,6 @@ fun main() = application {
image("image", cb.imageBinding(0, ImageAccess.WRITE)) image("image", cb.imageBinding(0, ImageAccess.WRITE))
} }
extend { extend {
drawer.shadeStyle = ss drawer.shadeStyle = ss
drawer.clear(ColorRGBa.PINK) drawer.clear(ColorRGBa.PINK)
drawer.rectangle(0.0, 0.0, 100.0, 100.0) drawer.rectangle(0.0, 0.0, 100.0, 100.0)

View File

@@ -1,13 +1,12 @@
import org.openrndr.application import org.openrndr.application
import org.openrndr.color.ColorRGBa import org.openrndr.color.rgb
import org.openrndr.draw.* import org.openrndr.draw.*
fun main() = application { fun main() = application {
program { program {
val cb = colorBuffer(128, 128) val cb = colorBuffer(128, 128, type = ColorType.UINT8)
val at = arrayTexture(128, 128, 32) val at = arrayTexture(128, 128, 32, type = ColorType.UINT8)
val vt = volumeTexture(32, 32, 32) val vt = volumeTexture(32, 32, 32, type = ColorType.UINT8)
extend { extend {
val ss = shadeStyle { val ss = shadeStyle {
fragmentTransform = """ fragmentTransform = """
@@ -16,12 +15,13 @@ fun main() = application {
imageStore(p_at, ivec3(2, 2, 2), vec4(1.0, 0.0, 0.0, 1.0)); imageStore(p_at, ivec3(2, 2, 2), vec4(1.0, 0.0, 0.0, 1.0));
""".trimIndent() """.trimIndent()
parameter("at", at.imageBinding(0, ImageAccess.READ_WRITE)) image("at", at.imageBinding(0, ImageAccess.READ_WRITE))
parameter("image", cb.imageBinding(0, ImageAccess.READ_WRITE)) image("image", cb.imageBinding(0, ImageAccess.READ_WRITE))
parameter("vt", vt.imageBinding(0, ImageAccess.READ_WRITE)) image("vt", vt.imageBinding(0, ImageAccess.READ_WRITE))
} }
drawer.shadeStyle = ss drawer.shadeStyle = ss
drawer.clear(ColorRGBa.PINK) drawer.clear(rgb(0.1))
drawer.fill = rgb(0.2)
drawer.rectangle(0.0, 0.0, 100.0, 100.0) drawer.rectangle(0.0, 0.0, 100.0, 100.0)
drawer.image(cb, 0.0, 200.0) drawer.image(cb, 0.0, 200.0)
} }

View File

@@ -33,9 +33,9 @@ fun main() {
stroke = ColorRGBa.PINK stroke = ColorRGBa.PINK
strokeWeight = 8.0 strokeWeight = 8.0
fontMap = font fontMap = font
LineCap.values().forEachIndexed { x, cap -> LineCap.entries.forEachIndexed { x, cap ->
lineCap = cap lineCap = cap
LineJoin.values().forEachIndexed { y, join -> LineJoin.entries.forEachIndexed { y, join ->
lineJoin = join lineJoin = join
val pos = IntVector2(x - 1, y - 1).vector2 * 180.0 val pos = IntVector2(x - 1, y - 1).vector2 * 180.0
isolated { isolated {

View File

@@ -8,7 +8,8 @@ fun main() = application {
program { program {
val style = shadeStyle { val style = shadeStyle {
//fragmentTransform = "x_stroke.a *= step(0.5, fract(c_contourPosition / p_dashLen));" //fragmentTransform = "x_stroke.a *= step(0.5, fract(c_contourPosition / p_dashLen));"
fragmentTransform = "x_stroke.a *= smoothstep(0.0, 1.0, mod(c_contourPosition, p_dashLen)) * smoothstep(p_dashLen, p_dashLen-1.0, mod(c_contourPosition, p_dashLen));" fragmentTransform =
"x_stroke.a *= smoothstep(0.0, 1.0, mod(c_contourPosition, p_dashLen)) * smoothstep(p_dashLen, p_dashLen-1.0, mod(c_contourPosition, p_dashLen));"
parameter("dashLen", 20.0) parameter("dashLen", 20.0)
} }
extend { extend {
@@ -25,8 +26,7 @@ fun main() = application {
shadeStyle = style shadeStyle = style
contour(c) contour(c)
drawer.lineSegment(0.0, 0.0, width*1.0, height*1.0) drawer.lineSegment(0.0, 0.0, width * 1.0, height * 1.0)
} }
} }
} }

View File

@@ -8,36 +8,34 @@ import org.openrndr.extra.meshgenerators.boxMesh
import org.openrndr.ffmpeg.VideoPlayerFFMPEG import org.openrndr.ffmpeg.VideoPlayerFFMPEG
import org.openrndr.math.Vector3 import org.openrndr.math.Vector3
fun main() { fun main() = application {
application { program {
program { val cube = boxMesh()
val cube = boxMesh() val screen = VideoPlayerFFMPEG.fromScreen(
val screen = VideoPlayerFFMPEG.fromScreen( frameRate = 15.0,
frameRate = 15.0, imageWidth = 300,
imageWidth = 300, imageHeight = 300
imageHeight = 300 )
)
screen.play() screen.play()
extend { extend {
screen.draw(drawer, true) // update the screen grabber screen.draw(drawer, true) // update the screen grabber
drawer.isolated { drawer.isolated {
clear(ColorRGBa.WHITE) clear(ColorRGBa.WHITE)
perspective(60.0, width * 1.0 / height, 0.01, 1000.0) perspective(60.0, width * 1.0 / height, 0.01, 1000.0)
depthWrite = true depthWrite = true
depthTestPass = DepthTestPass.LESS_OR_EQUAL depthTestPass = DepthTestPass.LESS_OR_EQUAL
shadeStyle = shadeStyle { shadeStyle = shadeStyle {
fragmentTransform = "x_fill = texture(p_tex, vec2(1.0-va_texCoord0.x, va_texCoord0.y));" fragmentTransform = "x_fill = texture(p_tex, vec2(1.0-va_texCoord0.x, va_texCoord0.y));"
screen.colorBuffer?.run { screen.colorBuffer?.run {
parameter("tex", this) parameter("tex", this)
}
} }
rotate(Vector3.UNIT_Z, 90.0)
translate(0.0, 0.0, -120.0)
rotate(Vector3.UNIT_X, seconds * 10)
scale(90.0)
vertexBuffer(cube, DrawPrimitive.TRIANGLES)
} }
rotate(Vector3.UNIT_Z, 90.0)
translate(0.0, 0.0, -120.0)
rotate(Vector3.UNIT_X, seconds * 10)
scale(90.0)
vertexBuffer(cube, DrawPrimitive.TRIANGLES)
} }
} }
} }

View File

@@ -1,5 +1,8 @@
import org.openrndr.application import org.openrndr.application
import org.openrndr.draw.* import org.openrndr.draw.BufferPrimitiveType
import org.openrndr.draw.shadeStyle
import org.openrndr.draw.shaderStorageBuffer
import org.openrndr.draw.shaderStorageFormat
import java.nio.ByteBuffer import java.nio.ByteBuffer
import java.nio.ByteOrder import java.nio.ByteOrder
@@ -46,6 +49,5 @@ fun main() = application {
// Therefore the value of `f1` can vary from frame to frame, // Therefore the value of `f1` can vary from frame to frame,
// because we don't know how many times `+= 2.0` was executed. // because we don't know how many times `+= 2.0` was executed.
} }
} }
} }

View File

@@ -7,46 +7,44 @@ import org.openrndr.draw.vertexFormat
import org.openrndr.math.Vector3 import org.openrndr.math.Vector3
import org.openrndr.resourceText import org.openrndr.resourceText
fun main() { fun main() = application {
application { program {
program { val vb = vertexBuffer(vertexFormat {
val vb = vertexBuffer(vertexFormat { position(3)
position(3) }, 12)
}, 12) val shader = Shader.Companion.createFromCode(
val shader = Shader.Companion.createFromCode( vsCode = resourceText("/shaders/ts-01.vert"),
vsCode = resourceText("/shaders/ts-01.vert"), tcsCode = resourceText("/shaders/ts-01.tesc"),
tcsCode = resourceText("/shaders/ts-01.tesc"), tesCode = resourceText("/shaders/ts-01.tese"),
tesCode = resourceText("/shaders/ts-01.tese"), fsCode = resourceText("/shaders/ts-01.frag"),
fsCode = resourceText("/shaders/ts-01.frag"), name = "x"
name = "x" )
)
vb.put { vb.put {
write(Vector3(0.0, 0.0, 0.0)) write(Vector3(0.0, 0.0, 0.0))
write(Vector3(100.0, 0.0, 0.0)) write(Vector3(100.0, 0.0, 0.0))
write(Vector3(140.0, 200.0, 0.0)) write(Vector3(140.0, 200.0, 0.0))
write(Vector3(200.0, 300.0, 0.0)) write(Vector3(200.0, 300.0, 0.0))
write(Vector3(0.0, 0.0, 0.0)) write(Vector3(0.0, 0.0, 0.0))
write(Vector3(100.0, 0.0, 0.0)) write(Vector3(100.0, 0.0, 0.0))
write(Vector3(140.0, 200.0, 0.0)) write(Vector3(140.0, 200.0, 0.0))
write(Vector3(200.0, 400.0, 0.0)) write(Vector3(200.0, 400.0, 0.0))
write(Vector3(0.0, 0.0, 0.0)) write(Vector3(0.0, 0.0, 0.0))
write(Vector3(100.0, 0.0, 0.0)) write(Vector3(100.0, 0.0, 0.0))
write(Vector3(140.0, 200.0, 0.0)) write(Vector3(140.0, 200.0, 0.0))
write(Vector3(200.0, 500.0, 0.0)) write(Vector3(200.0, 500.0, 0.0))
} }
extend { extend {
drawer.clear(ColorRGBa.PINK) drawer.clear(ColorRGBa.PINK)
shader.begin() shader.begin()
shader.uniform("offset", mouse.position.xy0) shader.uniform("offset", mouse.position.xy0)
shader.uniform("view", drawer.view) shader.uniform("view", drawer.view)
shader.uniform("proj", drawer.projection) shader.uniform("proj", drawer.projection)
shader.uniform("model", drawer.model) shader.uniform("model", drawer.model)
driver.drawVertexBuffer(shader, listOf(vb), DrawPrimitive.PATCHES, 0, vb.vertexCount) driver.drawVertexBuffer(shader, listOf(vb), DrawPrimitive.PATCHES, 0, vb.vertexCount)
shader.end() shader.end()
}
} }
} }
} }

View File

@@ -7,45 +7,43 @@ import org.openrndr.draw.vertexFormat
import org.openrndr.resourceText import org.openrndr.resourceText
import org.openrndr.shape.Ellipse import org.openrndr.shape.Ellipse
fun main() { fun main() = application {
application { program {
program { val ellipse = Ellipse(width / 2.0, height / 2.0, 100.0, 300.0).contour
val ellipse = Ellipse(width/2.0, height/2.0, 100.0, 300.0).contour
val vb = vertexBuffer(vertexFormat { val vb = vertexBuffer(vertexFormat {
position(3) position(3)
}, ellipse.segments.size * 4) }, ellipse.segments.size * 4)
val shader = Shader.createFromCode( val shader = Shader.createFromCode(
vsCode = resourceText("/shaders/ts-02.vert"), vsCode = resourceText("/shaders/ts-02.vert"),
tcsCode = resourceText("/shaders/ts-02.tesc"), tcsCode = resourceText("/shaders/ts-02.tesc"),
tesCode = resourceText("/shaders/ts-02.tese"), tesCode = resourceText("/shaders/ts-02.tese"),
gsCode = resourceText("/shaders/ts-02.geom"), gsCode = resourceText("/shaders/ts-02.geom"),
fsCode = resourceText("/shaders/ts-02.frag"), fsCode = resourceText("/shaders/ts-02.frag"),
name = "x" name = "x"
) )
vb.put { vb.put {
for (segment in ellipse.segments) { for (segment in ellipse.segments) {
val cubic = segment.cubic val cubic = segment.cubic
write(cubic.start.xy0) write(cubic.start.xy0)
write(cubic.control[0].xy0) write(cubic.control[0].xy0)
write(cubic.control[1].xy0) write(cubic.control[1].xy0)
write(cubic.end.xy0) write(cubic.end.xy0)
}
}
extend {
drawer.clear(ColorRGBa.PINK)
shader.begin()
shader.uniform("offset", mouse.position.xy0)
shader.uniform("view", drawer.view)
shader.uniform("proj", drawer.projection)
shader.uniform("model", drawer.model)
shader.uniform("resolution", ((mouse.position.x / width) * 63 + 1).toInt())
driver.drawVertexBuffer(shader, listOf(vb), DrawPrimitive.PATCHES, 0, vb.vertexCount)
shader.end()
} }
} }
extend {
drawer.clear(ColorRGBa.PINK)
shader.begin()
shader.uniform("offset", mouse.position.xy0)
shader.uniform("view", drawer.view)
shader.uniform("proj", drawer.projection)
shader.uniform("model", drawer.model)
shader.uniform("resolution", ((mouse.position.x / width) * 63 + 1).toInt())
driver.drawVertexBuffer(shader, listOf(vb), DrawPrimitive.PATCHES, 0, vb.vertexCount)
shader.end()
}
} }
} }

View File

@@ -7,51 +7,49 @@ import org.openrndr.draw.vertexFormat
import org.openrndr.resourceText import org.openrndr.resourceText
import org.openrndr.shape.Ellipse import org.openrndr.shape.Ellipse
fun main() { fun main() = application {
application { program {
program {
val ellipse = Ellipse(width/2.0, height/2.0, 100.0, 200.0).contour val ellipse = Ellipse(width / 2.0, height / 2.0, 100.0, 200.0).contour
val vb = vertexBuffer(vertexFormat { val vb = vertexBuffer(vertexFormat {
position(3) position(3)
}, ellipse.segments.size * 4) }, ellipse.segments.size * 4)
val shader = Shader.createFromCode( val shader = Shader.createFromCode(
vsCode = resourceText("/shaders/ts-03.vert"), vsCode = resourceText("/shaders/ts-03.vert"),
tcsCode = resourceText("/shaders/ts-03.tesc"), tcsCode = resourceText("/shaders/ts-03.tesc"),
tesCode = resourceText("/shaders/ts-03.tese"), tesCode = resourceText("/shaders/ts-03.tese"),
gsCode = resourceText("/shaders/ts-03.geom"), gsCode = resourceText("/shaders/ts-03.geom"),
fsCode = resourceText("/shaders/ts-03.frag"), fsCode = resourceText("/shaders/ts-03.frag"),
name = "x" name = "x"
) )
vb.put { vb.put {
for (segment in ellipse.segments) { for (segment in ellipse.segments) {
val cubic = segment.cubic val cubic = segment.cubic
write(cubic.start.xy0) write(cubic.start.xy0)
write(cubic.control[0].xy0) write(cubic.control[0].xy0)
write(cubic.control[1].xy0) write(cubic.control[1].xy0)
write(cubic.end.xy0) write(cubic.end.xy0)
}
}
extend {
drawer.clear(ColorRGBa.PINK)
drawer.translate(width/2.0, height/2.0, 0.0)
drawer.rotate(seconds*45.0)
drawer.translate(-width/2.0, -height/2.0, 0.0)
shader.begin()
shader.uniform("offset", mouse.position.xy0)
shader.uniform("view", drawer.view)
shader.uniform("proj", drawer.projection)
shader.uniform("model", drawer.model)
shader.uniform("resolution", ((mouse.position.x / width) * 63 + 1).toInt())
shader.uniform("weight",((mouse.position.y / height) * 128 + 1) )
driver.drawVertexBuffer(shader, listOf(vb), DrawPrimitive.PATCHES, 0, vb.vertexCount)
shader.end()
} }
} }
extend {
drawer.clear(ColorRGBa.PINK)
drawer.translate(width / 2.0, height / 2.0, 0.0)
drawer.rotate(seconds * 45.0)
drawer.translate(-width / 2.0, -height / 2.0, 0.0)
shader.begin()
shader.uniform("offset", mouse.position.xy0)
shader.uniform("view", drawer.view)
shader.uniform("proj", drawer.projection)
shader.uniform("model", drawer.model)
shader.uniform("resolution", ((mouse.position.x / width) * 63 + 1).toInt())
shader.uniform("weight", ((mouse.position.y / height) * 128 + 1))
driver.drawVertexBuffer(shader, listOf(vb), DrawPrimitive.PATCHES, 0, vb.vertexCount)
shader.end()
}
} }
} }

View File

@@ -1,73 +1,67 @@
import org.openrndr.application import org.openrndr.application
import org.openrndr.color.ColorRGBa import org.openrndr.color.ColorRGBa
import org.openrndr.draw.* import org.openrndr.draw.*
import org.openrndr.extra.noise.uniform
import org.openrndr.extra.noise.uniformRing
import org.openrndr.extra.camera.Orbital import org.openrndr.extra.camera.Orbital
import org.openrndr.extra.camera.OrbitalCamera
import org.openrndr.extra.meshgenerators.sphereMesh import org.openrndr.extra.meshgenerators.sphereMesh
import org.openrndr.extra.noise.uniformRing
import org.openrndr.extra.shaderphrases.preprocessedFromUrls
import org.openrndr.math.Vector3 import org.openrndr.math.Vector3
import org.openrndr.resourceUrl import org.openrndr.resourceUrl
import org.openrndr.shape.Ellipse
import org.openrndr.shape.path3D import org.openrndr.shape.path3D
import org.openrndr.extra.shaderphrases.preprocessedFromUrls
import kotlin.math.cos import kotlin.math.cos
fun main() { fun main() = application {
application { program {
program { extend(Orbital())
extend(Orbital())
val path = path3D { val path = path3D {
moveTo(Vector3.ZERO) moveTo(Vector3.ZERO)
for (i in 0 until 100) { for (i in 0 until 100) {
continueTo(anchor + Vector3.uniformRing(0.0, 10.0),anchor + Vector3.uniformRing(0.0, 10.0)) continueTo(anchor + Vector3.uniformRing(0.0, 10.0), anchor + Vector3.uniformRing(0.0, 10.0))
}
}
val vb = vertexBuffer(vertexFormat {
position(3)
}, path.segments.size * 4)
val shader = Shader.preprocessedFromUrls(
vsUrl = resourceUrl("/shaders/ts-04.vert"),
tcsUrl = resourceUrl("/shaders/ts-04.tesc"),
tesUrl = resourceUrl("/shaders/ts-04.tese"),
gsUrl = resourceUrl("/shaders/ts-04.geom"),
fsUrl = resourceUrl("/shaders/ts-04.frag")
)
val mesh = sphereMesh()
extend {
val vc = vb.put {
for (segment in path.sub(0.0, cos(seconds*0.1)*0.5+ 0.5).segments) {
val cubic = segment.cubic
write(cubic.start)
write(cubic.control[0])
write(cubic.control[1])
write(cubic.end)
}
}
drawer.clear(ColorRGBa.PINK)
drawer.depthTestPass = DepthTestPass.LESS_OR_EQUAL
drawer.depthWrite = true
drawer.vertexBuffer(mesh, DrawPrimitive.TRIANGLES)
shader.begin()
shader.uniform("offset", mouse.position.xy0)
shader.uniform("view", drawer.view)
shader.uniform("proj", drawer.projection)
shader.uniform("model", drawer.model)
shader.uniform("resolution", 32)
shader.uniform("weight", 3.0 + cos(seconds))
shader.uniform("time", seconds*0.0)
drawer.depthWrite = false
driver.setState(drawer.drawStyle)
driver.drawVertexBuffer(shader, listOf(vb), DrawPrimitive.PATCHES, 0, vc)
shader.end()
drawer.fill = ColorRGBa.WHITE
} }
} }
val vb = vertexBuffer(vertexFormat {
position(3)
}, path.segments.size * 4)
val shader = Shader.preprocessedFromUrls(
vsUrl = resourceUrl("/shaders/ts-04.vert"),
tcsUrl = resourceUrl("/shaders/ts-04.tesc"),
tesUrl = resourceUrl("/shaders/ts-04.tese"),
gsUrl = resourceUrl("/shaders/ts-04.geom"),
fsUrl = resourceUrl("/shaders/ts-04.frag")
)
val mesh = sphereMesh()
extend {
val vc = vb.put {
for (segment in path.sub(0.0, cos(seconds * 0.1) * 0.5 + 0.5).segments) {
val cubic = segment.cubic
write(cubic.start)
write(cubic.control[0])
write(cubic.control[1])
write(cubic.end)
}
}
drawer.clear(ColorRGBa.PINK)
drawer.depthTestPass = DepthTestPass.LESS_OR_EQUAL
drawer.depthWrite = true
drawer.vertexBuffer(mesh, DrawPrimitive.TRIANGLES)
shader.begin()
shader.uniform("offset", mouse.position.xy0)
shader.uniform("view", drawer.view)
shader.uniform("proj", drawer.projection)
shader.uniform("model", drawer.model)
shader.uniform("resolution", 32)
shader.uniform("weight", 3.0 + cos(seconds))
shader.uniform("time", seconds * 0.0)
drawer.depthWrite = false
driver.setState(drawer.drawStyle)
driver.drawVertexBuffer(shader, listOf(vb), DrawPrimitive.PATCHES, 0, vc)
shader.end()
drawer.fill = ColorRGBa.WHITE
}
} }
} }

View File

@@ -4,7 +4,7 @@ import org.openrndr.draw.*
fun main() = application { fun main() = application {
program { program {
val volumeTexture = VolumeTexture.create(128,128,32, type = ColorType.UINT8) val volumeTexture = VolumeTexture.create(128, 128, 32, type = ColorType.UINT8)
val rt = renderTarget(128, 128) { val rt = renderTarget(128, 128) {
volumeTexture(volumeTexture, 0) volumeTexture(volumeTexture, 0)
} }

View File

@@ -31,9 +31,11 @@ fun main() = application {
// Rectangles with the bottom right corner centered in the window // Rectangles with the bottom right corner centered in the window
drawer.rectangles(List(10) { drawer.rectangles(List(10) {
Rectangle(drawer.bounds.center, Rectangle(
-squareSize * 2 + it * 10, drawer.bounds.center,
-squareSize * 2 + it * 10) -squareSize * 2 + it * 10,
-squareSize * 2 + it * 10
)
}) })
} }
} }

View File

@@ -11,10 +11,9 @@ fun main() = application {
drawer.stroke = ColorRGBa.WHITE drawer.stroke = ColorRGBa.WHITE
drawer.strokeWeight = 2.0 drawer.strokeWeight = 2.0
drawer.rectangles { drawer.rectangles {
for (y in 0 until height/20) { for (y in 0 until height / 20) {
for (x in 0 until width/20) { for (x in 0 until width / 20) {
rectangle(x * 20.0, y * 20.0, 10.0, 15.0, (x + y) * 10.0 + seconds*90.0) rectangle(x * 20.0, y * 20.0, 10.0, 15.0, (x + y) * 10.0 + seconds * 90.0)
} }
} }
} }

View File

@@ -49,6 +49,56 @@ for (c in cs blend (width / 40)) {
Two color spaces are added: `ColorHSLUVa` and `ColorHPLUVa`, they are an implementation of the colorspaces presented at [hsluv.org](http://www.hsluv.org) Two color spaces are added: `ColorHSLUVa` and `ColorHPLUVa`, they are an implementation of the colorspaces presented at [hsluv.org](http://www.hsluv.org)
<!-- __demos__ --> <!-- __demos__ -->
## Demos ## Demos
### colormap/DemoSpectralZucconiColormap
[source code](src/jvmDemo/kotlin/colormap/DemoSpectralZucconiColormap.kt)
![colormap-DemoSpectralZucconiColormapKt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/colormap-DemoSpectralZucconiColormapKt.png)
### colormap/DemoSpectralZucconiColormapPhrase
[source code](src/jvmDemo/kotlin/colormap/DemoSpectralZucconiColormapPhrase.kt)
![colormap-DemoSpectralZucconiColormapPhraseKt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/colormap-DemoSpectralZucconiColormapPhraseKt.png)
### colormap/DemoSpectralZucconiColormapPlot
[source code](src/jvmDemo/kotlin/colormap/DemoSpectralZucconiColormapPlot.kt)
![colormap-DemoSpectralZucconiColormapPlotKt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/colormap-DemoSpectralZucconiColormapPlotKt.png)
### colormap/DemoTurboColormap
[source code](src/jvmDemo/kotlin/colormap/DemoTurboColormap.kt)
![colormap-DemoTurboColormapKt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/colormap-DemoTurboColormapKt.png)
### colormap/DemoTurboColormapPhrase
[source code](src/jvmDemo/kotlin/colormap/DemoTurboColormapPhrase.kt)
![colormap-DemoTurboColormapPhraseKt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/colormap-DemoTurboColormapPhraseKt.png)
### colormap/DemoTurboColormapPlot
[source code](src/jvmDemo/kotlin/colormap/DemoTurboColormapPlot.kt)
![colormap-DemoTurboColormapPlotKt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/colormap-DemoTurboColormapPlotKt.png)
### colorRange/DemoColorRange01
[source code](src/jvmDemo/kotlin/colorRange/DemoColorRange01.kt)
![colorRange-DemoColorRange01Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/colorRange-DemoColorRange01Kt.png)
### colorRange/DemoColorRange02
[source code](src/jvmDemo/kotlin/colorRange/DemoColorRange02.kt)
![colorRange-DemoColorRange02Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/colorRange-DemoColorRange02Kt.png)
### colorRange/DemoColorRange03
[source code](src/jvmDemo/kotlin/colorRange/DemoColorRange03.kt)
![colorRange-DemoColorRange03Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/colorRange-DemoColorRange03Kt.png)
### colorRange/DemoColorRange04
[source code](src/jvmDemo/kotlin/colorRange/DemoColorRange04.kt)
![colorRange-DemoColorRange04Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/colorRange-DemoColorRange04Kt.png)
### DemoColorPalette01 ### DemoColorPalette01
[source code](src/jvmDemo/kotlin/DemoColorPalette01.kt) [source code](src/jvmDemo/kotlin/DemoColorPalette01.kt)
@@ -69,26 +119,6 @@ Two color spaces are added: `ColorHSLUVa` and `ColorHPLUVa`, they are an impleme
![DemoColorPlane02Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/DemoColorPlane02Kt.png) ![DemoColorPlane02Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/DemoColorPlane02Kt.png)
### DemoColorRange01
[source code](src/jvmDemo/kotlin/DemoColorRange01.kt)
![DemoColorRange01Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/DemoColorRange01Kt.png)
### DemoColorRange02
[source code](src/jvmDemo/kotlin/DemoColorRange02.kt)
![DemoColorRange02Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/DemoColorRange02Kt.png)
### DemoColorRange03
[source code](src/jvmDemo/kotlin/DemoColorRange03.kt)
![DemoColorRange03Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/DemoColorRange03Kt.png)
### DemoColorRange04
[source code](src/jvmDemo/kotlin/DemoColorRange04.kt)
![DemoColorRange04Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/DemoColorRange04Kt.png)
### DemoColorSequence01 ### DemoColorSequence01
[source code](src/jvmDemo/kotlin/DemoColorSequence01.kt) [source code](src/jvmDemo/kotlin/DemoColorSequence01.kt)
@@ -109,21 +139,6 @@ Two color spaces are added: `ColorHSLUVa` and `ColorHPLUVa`, they are an impleme
![DemoFettePalette02Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/DemoFettePalette02Kt.png) ![DemoFettePalette02Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/DemoFettePalette02Kt.png)
### DemoHistogram01
[source code](src/jvmDemo/kotlin/DemoHistogram01.kt)
![DemoHistogram01Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/DemoHistogram01Kt.png)
### DemoHistogram02
[source code](src/jvmDemo/kotlin/DemoHistogram02.kt)
![DemoHistogram02Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/DemoHistogram02Kt.png)
### DemoHistogram03
[source code](src/jvmDemo/kotlin/DemoHistogram03.kt)
![DemoHistogram03Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/DemoHistogram03Kt.png)
### DemoHSLUV01 ### DemoHSLUV01
[source code](src/jvmDemo/kotlin/DemoHSLUV01.kt) [source code](src/jvmDemo/kotlin/DemoHSLUV01.kt)
@@ -149,37 +164,22 @@ Two color spaces are added: `ColorHSLUVa` and `ColorHPLUVa`, they are an impleme
![DemoOKHSV01Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/DemoOKHSV01Kt.png) ![DemoOKHSV01Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/DemoOKHSV01Kt.png)
### DemoSpectralZucconiColormap
[source code](src/jvmDemo/kotlin/DemoSpectralZucconiColormap.kt)
![DemoSpectralZucconiColormapKt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/DemoSpectralZucconiColormapKt.png)
### DemoSpectralZucconiColormapPhrase
[source code](src/jvmDemo/kotlin/DemoSpectralZucconiColormapPhrase.kt)
![DemoSpectralZucconiColormapPhraseKt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/DemoSpectralZucconiColormapPhraseKt.png)
### DemoSpectralZucconiColormapPlot
[source code](src/jvmDemo/kotlin/DemoSpectralZucconiColormapPlot.kt)
![DemoSpectralZucconiColormapPlotKt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/DemoSpectralZucconiColormapPlotKt.png)
### DemoTurboColormap
[source code](src/jvmDemo/kotlin/DemoTurboColormap.kt)
![DemoTurboColormapKt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/DemoTurboColormapKt.png)
### DemoTurboColormapPhrase
[source code](src/jvmDemo/kotlin/DemoTurboColormapPhrase.kt)
![DemoTurboColormapPhraseKt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/DemoTurboColormapPhraseKt.png)
### DemoTurboColormapPlot
[source code](src/jvmDemo/kotlin/DemoTurboColormapPlot.kt)
![DemoTurboColormapPlotKt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/DemoTurboColormapPlotKt.png)
### DemoXSLUV01 ### DemoXSLUV01
[source code](src/jvmDemo/kotlin/DemoXSLUV01.kt) [source code](src/jvmDemo/kotlin/DemoXSLUV01.kt)
![DemoXSLUV01Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/DemoXSLUV01Kt.png) ![DemoXSLUV01Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/DemoXSLUV01Kt.png)
### histogram/DemoHistogram01
[source code](src/jvmDemo/kotlin/histogram/DemoHistogram01.kt)
![histogram-DemoHistogram01Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/histogram-DemoHistogram01Kt.png)
### histogram/DemoHistogram02
[source code](src/jvmDemo/kotlin/histogram/DemoHistogram02.kt)
![histogram-DemoHistogram02Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/histogram-DemoHistogram02Kt.png)
### histogram/DemoHistogram03
[source code](src/jvmDemo/kotlin/histogram/DemoHistogram03.kt)
![histogram-DemoHistogram03Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/histogram-DemoHistogram03Kt.png)

View File

@@ -11,7 +11,10 @@ import org.openrndr.extra.color.spaces.*
* Demonstrates the creation of color palettes using various available methods * Demonstrates the creation of color palettes using various available methods
*/ */
fun main() = application { fun main() = application {
configure { } configure {
width = 720
height = 540
}
program { program {
// HueShiftableColor: // HueShiftableColor:
// HPLuv HSL HSV LCHab LCHuv XSL XSV XSLuv HSLuv OKHSL OKHSV OKLCH // HPLuv HSL HSV LCHab LCHuv XSL XSV XSLuv HSLuv OKHSL OKHSV OKLCH
@@ -27,34 +30,33 @@ fun main() = application {
palette0.forEachIndexed { i, c -> palette0.forEachIndexed { i, c ->
drawer.fill = c drawer.fill = c
drawer.circle(100.0 + i * 40.0, 80.0, 40.0) drawer.circle(100.0 + i * 50.0, 80.0, 50.0)
} }
palette1.forEachIndexed { i, c -> palette1.forEachIndexed { i, c ->
drawer.fill = c drawer.fill = c
drawer.circle(100.0 + i * 40.0, 180.0, 40.0) drawer.circle(100.0 + i * 50.0, 200.0, 50.0)
} }
palette2.forEachIndexed { i, c -> palette2.forEachIndexed { i, c ->
drawer.fill = c drawer.fill = c
drawer.circle(380.0 + i * 40.0, 180.0, 40.0) drawer.circle(440.0 + i * 50.0, 200.0, 50.0)
} }
palette3.forEachIndexed { i, c -> palette3.forEachIndexed { i, c ->
drawer.fill = c drawer.fill = c
drawer.circle(100.0 + i * 40.0, 280.0, 40.0) drawer.circle(100.0 + i * 50.0, 320.0, 50.0)
} }
palette4.forEachIndexed { i, c -> palette4.forEachIndexed { i, c ->
drawer.fill = c drawer.fill = c
drawer.circle(350.0 + i * 40.0, 280.0, 40.0) drawer.circle(400.0 + i * 50.0, 320.0, 50.0)
} }
palette5.forEachIndexed { i, c -> palette5.forEachIndexed { i, c ->
drawer.fill = c drawer.fill = c
drawer.circle(100.0 + i * 40.0, 380.0, 40.0) drawer.circle(100.0 + i * 50.0, 440.0, 50.0)
} }
} }
} }
} }

View File

@@ -11,6 +11,10 @@ import org.openrndr.extra.color.tools.shadeLuminosity
* an increased dynamic range. * an increased dynamic range.
*/ */
fun main() = application { fun main() = application {
configure {
width = 720
height = 360
}
program { program {
val count = 8 val count = 8
val palette = RGB.PINK.analogous<HSLuv>(360.0, count).mapIndexed { i, c -> val palette = RGB.PINK.analogous<HSLuv>(360.0, count).mapIndexed { i, c ->

View File

@@ -7,80 +7,75 @@ import org.openrndr.extra.meshgenerators.sphereMesh
import org.openrndr.math.Vector3 import org.openrndr.math.Vector3
import kotlin.math.cos import kotlin.math.cos
fun main() { fun main() = application {
application { configure {
configure { width = 720
width = 800 height = 720
height = 800 }
program {
val mesh = sphereMesh(8, 8, radius = 0.1)
} val instanceData = vertexBuffer(
program { vertexFormat {
val mesh = sphereMesh(8, 8, radius = 0.1) attribute("instanceColor", VertexElementType.VECTOR4_FLOAT32)
attribute("instancePosition", VertexElementType.VECTOR3_FLOAT32)
},
90 * 100
)
println(extensions.size)
extend(Orbital())
val instanceData = vertexBuffer( extend {
vertexFormat { drawer.clear(ColorRGBa.WHITE)
attribute("instanceColor", VertexElementType.VECTOR4_FLOAT32) drawer.stroke = null
attribute("instancePosition", VertexElementType.VECTOR3_FLOAT32) drawer.fontMap = loadFont("demo-data/fonts/IBMPlexMono-Regular.ttf", 16.0)
},
90 * 100
)
println(extensions.size)
extend(Orbital())
extend { instanceData.put {
drawer.clear(ColorRGBa.WHITE) for (hue in 0 until 360 step 4) {
for (chroma in 0 until 100 step 1) {
drawer.stroke = null val lch = ColorOKLCHa(cos(seconds * 0.1) * 0.5 + 0.5, chroma / 100.0, hue.toDouble())
val srgb = lch.toRGBa().toSRGB().clip()
drawer.fontMap = loadFont("demo-data/fonts/IBMPlexMono-Regular.ttf", 16.0) write(srgb)
write(Vector3((srgb.r - 0.5) * 10.0, (srgb.g - 0.5) * 10.0, (srgb.b - 0.5) * 10.0))
instanceData.put {
for (hue in 0 until 360 step 4) {
for (chroma in 0 until 100 step 1) {
val lch = ColorOKLCHa(cos(seconds * 0.1) * 0.5 + 0.5, chroma / 100.0, hue.toDouble())
val srgb = lch.toRGBa().toSRGB().clip()
write(srgb)
write(Vector3((srgb.r - 0.5) * 10.0, (srgb.g - 0.5) * 10.0, (srgb.b - 0.5) * 10.0))
}
} }
} }
drawer.isolated { }
drawer.shadeStyle = shadeStyle { drawer.isolated {
drawer.shadeStyle = shadeStyle {
vertexTransform = """ vertexTransform = """
x_position += i_instancePosition; x_position += i_instancePosition;
""".trimIndent() """.trimIndent()
fragmentTransform = """ fragmentTransform = """
x_fill = vi_instanceColor; x_fill = vi_instanceColor;
""".trimIndent() """.trimIndent()
}
drawer.vertexBufferInstances(listOf(mesh), listOf(instanceData), DrawPrimitive.TRIANGLES, 90 * 100)
} }
drawer.vertexBufferInstances(listOf(mesh), listOf(instanceData), DrawPrimitive.TRIANGLES, 90 * 100)
drawer.stroke = ColorRGBa.BLACK.opacify(0.25)
drawer.strokeWeight = 10.0
drawer.lineSegments(
listOf(
Vector3(-5.0, -5.0, -5.0), Vector3(5.0, -5.0, -5.0),
Vector3(-5.0, -5.0, 5.0), Vector3(5.0, -5.0, 5.0),
Vector3(-5.0, 5.0, -5.0), Vector3(5.0, 5.0, -5.0),
Vector3(-5.0, 5.0, 5.0), Vector3(5.0, 5.0, 5.0),
Vector3(-5.0, -5.0, -5.0), Vector3(-5.0, 5.0, -5.0),
Vector3(5.0, -5.0, -5.0), Vector3(5.0, 5.0, -5.0),
Vector3(-5.0, -5.0, 5.0), Vector3(-5.0, 5.0, 5.0),
Vector3(5.0, -5.0, 5.0), Vector3(5.0, 5.0, 5.0),
Vector3(-5.0, -5.0, -5.0), Vector3(-5.0, -5.0, 5.0),
Vector3(5.0, -5.0, -5.0), Vector3(5.0, -5.0, 5.0),
Vector3(-5.0, 5.0, -5.0), Vector3(-5.0, 5.0, 5.0),
Vector3(5.0, 5.0, -5.0), Vector3(5.0, 5.0, 5.0),
)
)
} }
drawer.stroke = ColorRGBa.BLACK.opacify(0.25)
drawer.strokeWeight = 10.0
drawer.lineSegments(
listOf(
Vector3(-5.0, -5.0, -5.0), Vector3(5.0, -5.0, -5.0),
Vector3(-5.0, -5.0, 5.0), Vector3(5.0, -5.0, 5.0),
Vector3(-5.0, 5.0, -5.0), Vector3(5.0, 5.0, -5.0),
Vector3(-5.0, 5.0, 5.0), Vector3(5.0, 5.0, 5.0),
Vector3(-5.0, -5.0, -5.0), Vector3(-5.0, 5.0, -5.0),
Vector3(5.0, -5.0, -5.0), Vector3(5.0, 5.0, -5.0),
Vector3(-5.0, -5.0, 5.0), Vector3(-5.0, 5.0, 5.0),
Vector3(5.0, -5.0, 5.0), Vector3(5.0, 5.0, 5.0),
Vector3(-5.0, -5.0, -5.0), Vector3(-5.0, -5.0, 5.0),
Vector3(5.0, -5.0, -5.0), Vector3(5.0, -5.0, 5.0),
Vector3(-5.0, 5.0, -5.0), Vector3(-5.0, 5.0, 5.0),
Vector3(5.0, 5.0, -5.0), Vector3(5.0, 5.0, 5.0),
)
)
} }
} }
} }

View File

@@ -7,73 +7,71 @@ import org.openrndr.extra.meshgenerators.sphereMesh
import org.openrndr.math.Vector3 import org.openrndr.math.Vector3
import kotlin.math.cos import kotlin.math.cos
fun main() { fun main() = application {
application { configure {
configure { width = 720
width = 800 height = 720
height = 800 }
} program {
program { val mesh = sphereMesh(8, 8, radius = 0.1)
val mesh = sphereMesh(8, 8, radius = 0.1)
val instanceData = vertexBuffer( val instanceData = vertexBuffer(
vertexFormat { vertexFormat {
attribute("instanceColor", VertexElementType.VECTOR4_FLOAT32) attribute("instanceColor", VertexElementType.VECTOR4_FLOAT32)
attribute("instancePosition", VertexElementType.VECTOR3_FLOAT32) attribute("instancePosition", VertexElementType.VECTOR3_FLOAT32)
}, },
100 * 100 100 * 100
) )
extend(Orbital()) extend(Orbital())
extend { extend {
drawer.clear(ColorRGBa.WHITE) drawer.clear(ColorRGBa.WHITE)
drawer.stroke = null drawer.stroke = null
drawer.fontMap = loadFont("demo-data/fonts/IBMPlexMono-Regular.ttf", 16.0) drawer.fontMap = loadFont("demo-data/fonts/IBMPlexMono-Regular.ttf", 16.0)
instanceData.put { instanceData.put {
for (lumo in 0 until 100 step 1) { for (lumo in 0 until 100 step 1) {
for (chroma in 0 until 100 step 1) { for (chroma in 0 until 100 step 1) {
val lch = ColorOKLCHa(lumo / 100.0, chroma / 100.0, cos(seconds * 0.1) * 360.0) val lch = ColorOKLCHa(lumo / 100.0, chroma / 100.0, cos(seconds * 0.1) * 360.0)
val srgb = lch.toRGBa().toSRGB().clip() val srgb = lch.toRGBa().toSRGB().clip()
write(srgb) write(srgb)
write(Vector3((srgb.r - 0.5) * 10.0, (srgb.g - 0.5) * 10.0, (srgb.b - 0.5) * 10.0)) write(Vector3((srgb.r - 0.5) * 10.0, (srgb.g - 0.5) * 10.0, (srgb.b - 0.5) * 10.0))
}
} }
} }
drawer.isolated { }
drawer.shadeStyle = shadeStyle { drawer.isolated {
vertexTransform = """ drawer.shadeStyle = shadeStyle {
vertexTransform = """
x_position += i_instancePosition; x_position += i_instancePosition;
""".trimIndent() """.trimIndent()
fragmentTransform = """ fragmentTransform = """
x_fill = vi_instanceColor; x_fill = vi_instanceColor;
""".trimIndent() """.trimIndent()
}
drawer.vertexBufferInstances(listOf(mesh), listOf(instanceData), DrawPrimitive.TRIANGLES, 90 * 100)
} }
drawer.vertexBufferInstances(listOf(mesh), listOf(instanceData), DrawPrimitive.TRIANGLES, 90 * 100)
drawer.stroke = ColorRGBa.BLACK.opacify(0.25)
drawer.strokeWeight = 10.0
drawer.lineSegments(
listOf(
Vector3(-5.0, -5.0, -5.0), Vector3(5.0, -5.0, -5.0),
Vector3(-5.0, -5.0, 5.0), Vector3(5.0, -5.0, 5.0),
Vector3(-5.0, 5.0, -5.0), Vector3(5.0, 5.0, -5.0),
Vector3(-5.0, 5.0, 5.0), Vector3(5.0, 5.0, 5.0),
Vector3(-5.0, -5.0, -5.0), Vector3(-5.0, 5.0, -5.0),
Vector3(5.0, -5.0, -5.0), Vector3(5.0, 5.0, -5.0),
Vector3(-5.0, -5.0, 5.0), Vector3(-5.0, 5.0, 5.0),
Vector3(5.0, -5.0, 5.0), Vector3(5.0, 5.0, 5.0),
Vector3(-5.0, -5.0, -5.0), Vector3(-5.0, -5.0, 5.0),
Vector3(5.0, -5.0, -5.0), Vector3(5.0, -5.0, 5.0),
Vector3(-5.0, 5.0, -5.0), Vector3(-5.0, 5.0, 5.0),
Vector3(5.0, 5.0, -5.0), Vector3(5.0, 5.0, 5.0),
)
)
} }
drawer.stroke = ColorRGBa.BLACK.opacify(0.25)
drawer.strokeWeight = 10.0
drawer.lineSegments(
listOf(
Vector3(-5.0, -5.0, -5.0), Vector3(5.0, -5.0, -5.0),
Vector3(-5.0, -5.0, 5.0), Vector3(5.0, -5.0, 5.0),
Vector3(-5.0, 5.0, -5.0), Vector3(5.0, 5.0, -5.0),
Vector3(-5.0, 5.0, 5.0), Vector3(5.0, 5.0, 5.0),
Vector3(-5.0, -5.0, -5.0), Vector3(-5.0, 5.0, -5.0),
Vector3(5.0, -5.0, -5.0), Vector3(5.0, 5.0, -5.0),
Vector3(-5.0, -5.0, 5.0), Vector3(-5.0, 5.0, 5.0),
Vector3(5.0, -5.0, 5.0), Vector3(5.0, 5.0, 5.0),
Vector3(-5.0, -5.0, -5.0), Vector3(-5.0, -5.0, 5.0),
Vector3(5.0, -5.0, -5.0), Vector3(5.0, -5.0, 5.0),
Vector3(-5.0, 5.0, -5.0), Vector3(-5.0, 5.0, 5.0),
Vector3(5.0, 5.0, -5.0), Vector3(5.0, 5.0, 5.0),
)
)
} }
} }
} }

View File

@@ -1,52 +0,0 @@
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.loadFont
import org.openrndr.extra.color.spaces.*
import org.openrndr.extra.color.palettes.rangeTo
fun main() {
application {
configure {
height = 30 + 50 * 11 // row count
}
program {
extend {
drawer.clear(ColorRGBa.WHITE)
val colorA = ColorRGBa.BLUE
val colorB = ColorRGBa.PINK
val stepCount = 25
val allSteps = listOf(
"RGB" to (colorA..colorB blend stepCount),
"RGB linear" to (colorA.toLinear()..colorB.toLinear() blend stepCount),
"HSV" to (colorA..colorB.toHSVa() blend stepCount),
"Lab" to (colorA.toLABa()..colorB.toLABa() blend stepCount),
"LCh(ab)" to (colorA.toLCHABa()..colorB.toLCHABa() blend stepCount),
"OKLab" to (colorA.toOKLABa()..colorB.toOKLABa() blend stepCount),
"OKLCh" to (colorA.toOKLCHa()..colorB.toOKLCHa() blend stepCount),
"OKHSV" to (colorA.toOKHSVa()..colorB.toOKHSVa() blend stepCount),
"OKHSL" to (colorA.toOKHSLa()..colorB.toOKHSLa() blend stepCount),
"HSLUV" to (colorA.toHSLUVa()..colorB.toHSLUVa() blend stepCount),
"XSLUV" to (colorA.toXSLUVa()..colorB.toXSLUVa() blend stepCount),
)
drawer.stroke = null
drawer.fontMap = loadFont("demo-data/fonts/IBMPlexMono-Regular.ttf", 16.0)
drawer.translate(20.0, 20.0)
for ((label, steps) in allSteps) {
drawer.fill = ColorRGBa.GRAY.shade(0.25)
drawer.text(label, 0.0, 24.0)
for (i in steps.indices) {
drawer.fill = steps[i].toSRGB()
drawer.rectangle(100.0 + i * 20.0, 0.0, 20.0, 40.0)
}
drawer.translate(0.0, 50.0)
}
}
}
}
}

View File

@@ -1,87 +0,0 @@
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.DrawPrimitive
import org.openrndr.draw.isolated
import org.openrndr.draw.loadFont
import org.openrndr.extra.camera.Orbital
import org.openrndr.extra.color.palettes.rangeTo
import org.openrndr.extra.color.spaces.toHSLUVa
import org.openrndr.extra.color.spaces.toOKLABa
import org.openrndr.extra.color.spaces.toOKLCHa
import org.openrndr.extra.color.spaces.toXSLUVa
import org.openrndr.extra.meshgenerators.sphereMesh
import org.openrndr.math.Vector3
fun main() {
application {
configure {
width = 800
height = 800
}
program {
val mesh = sphereMesh(8, 8, radius = 0.1)
extend(Orbital())
extend {
drawer.clear(ColorRGBa.WHITE)
val colorA = ColorRGBa.BLUE.toHSVa().shiftHue(seconds * 40.0).toRGBa()
val colorB = ColorRGBa.PINK.toHSVa().shiftHue(-seconds * 34.0).toRGBa()
val stepCount = 25
val allSteps = listOf(
"RGB" to (colorA..colorB blend stepCount),
"RGB linear" to (colorA.toLinear()..colorB.toLinear() blend stepCount),
"HSV" to (colorA..colorB.toHSVa() blend stepCount),
"Lab" to (colorA.toLABa()..colorB.toLABa() blend stepCount),
"LCh(ab)" to (colorA.toLCHABa()..colorB.toLCHABa() blend stepCount),
"OKLab" to (colorA.toOKLABa()..colorB.toOKLABa() blend stepCount),
"OKLCh" to (colorA.toOKLCHa()..colorB.toOKLCHa() blend stepCount),
"HSLUV" to (colorA.toHSLUVa()..colorB.toHSLUVa() blend stepCount),
"XSLUV" to (colorA.toXSLUVa()..colorB.toXSLUVa() blend stepCount),
)
drawer.stroke = null
drawer.fontMap = loadFont("demo-data/fonts/IBMPlexMono-Regular.ttf", 16.0)
for ((_, steps) in allSteps) {
for (i in steps.indices) {
val srgb = steps[i].toSRGB().clip()
drawer.fill = srgb
drawer.isolated {
drawer.translate((srgb.r - 0.5) * 10.0, (srgb.g - 0.5) * 10.0, (srgb.b - 0.5) * 10.0)
drawer.vertexBuffer(mesh, DrawPrimitive.TRIANGLES)
}
}
val positions = steps.map {
val l = it.toSRGB().clip()
Vector3((l.r - 0.5) * 10.0, (l.g - 0.5) * 10.0, (l.b - 0.5) * 10.0)
}
drawer.stroke = ColorRGBa.BLACK.opacify(0.25)
drawer.strokeWeight = 10.0
drawer.lineStrip(positions)
}
drawer.lineSegments(
listOf(
Vector3(-5.0, -5.0, -5.0), Vector3(5.0, -5.0, -5.0),
Vector3(-5.0, -5.0, 5.0), Vector3(5.0, -5.0, 5.0),
Vector3(-5.0, 5.0, -5.0), Vector3(5.0, 5.0, -5.0),
Vector3(-5.0, 5.0, 5.0), Vector3(5.0, 5.0, 5.0),
Vector3(-5.0, -5.0, -5.0), Vector3(-5.0, 5.0, -5.0),
Vector3(5.0, -5.0, -5.0), Vector3(5.0, 5.0, -5.0),
Vector3(-5.0, -5.0, 5.0), Vector3(-5.0, 5.0, 5.0),
Vector3(5.0, -5.0, 5.0), Vector3(5.0, 5.0, 5.0),
Vector3(-5.0, -5.0, -5.0), Vector3(-5.0, -5.0, 5.0),
Vector3(5.0, -5.0, -5.0), Vector3(5.0, -5.0, 5.0),
Vector3(-5.0, 5.0, -5.0), Vector3(-5.0, 5.0, 5.0),
Vector3(5.0, 5.0, -5.0), Vector3(5.0, 5.0, 5.0),
)
)
}
}
}
}

View File

@@ -24,48 +24,46 @@ import org.openrndr.math.Vector3
* - Applying a custom fragment shader with a palette-based shading style. * - Applying a custom fragment shader with a palette-based shading style.
* - Rendering a grid of 3D spheres, each transformed and rotated to create a dynamic pattern. * - Rendering a grid of 3D spheres, each transformed and rotated to create a dynamic pattern.
*/ */
fun main() { fun main() = application {
application { configure {
configure { width = 720
width = 720 height = 720
height = 720 }
} program {
program { val cs = ColorSequence(
val cs = ColorSequence( listOf(
listOf( 0.0 to ColorRGBa.PINK,
0.0 to ColorRGBa.PINK, 0.25 to ColorRGBa.ORANGE.toOKLABa(),
0.25 to ColorRGBa.ORANGE.toOKLABa(), 0.27 to ColorRGBa.WHITE.toOKLABa(),
0.27 to ColorRGBa.WHITE.toOKLABa(), 0.32 to ColorRGBa.BLUE,
0.32 to ColorRGBa.BLUE, 1.0 to ColorRGBa.MEDIUM_AQUAMARINE
1.0 to ColorRGBa.MEDIUM_AQUAMARINE
)
) )
val palette = cs.toColorBuffer(drawer, 256, 16) )
val sphere = sphereMesh(sides = 48, segments = 48) val palette = cs.toColorBuffer(drawer, 256, 16)
val sphere = sphereMesh(sides = 48, segments = 48)
extend(Orbital()) { extend(Orbital()) {
fov = 50.0 fov = 50.0
eye = Vector3(0.0, 0.0, 13.0) eye = Vector3(0.0, 0.0, 13.0)
} }
extend { extend {
drawer.shadeStyle = shadeStyle { drawer.shadeStyle = shadeStyle {
fragmentTransform = """ fragmentTransform = """
float d = normalize(va_normal).z; float d = normalize(va_normal).z;
x_fill = texture(p_palette, vec2(1.0-d, 0.0)); x_fill = texture(p_palette, vec2(1.0-d, 0.0));
""".trimIndent() """.trimIndent()
parameter("palette", palette) parameter("palette", palette)
} }
for (j in -2..2) { for (j in -2..2) {
for (i in -2..2) { for (i in -2..2) {
drawer.isolated { drawer.isolated {
drawer.translate(i * 2.0, j * 2.0, 0.0) drawer.translate(i * 2.0, j * 2.0, 0.0)
drawer.rotate(Vector3.UNIT_Y, j * 30.0) drawer.rotate(Vector3.UNIT_Y, j * 30.0)
drawer.rotate(Vector3.UNIT_X, i * 30.0) drawer.rotate(Vector3.UNIT_X, i * 30.0)
drawer.vertexBuffer(sphere, DrawPrimitive.TRIANGLES) drawer.vertexBuffer(sphere, DrawPrimitive.TRIANGLES)
}
} }
} }
} }
} }
} }
} }

View File

@@ -4,36 +4,34 @@ import org.openrndr.extra.color.spaces.toOKHSVa
import org.openrndr.extra.color.statistics.deltaE76 import org.openrndr.extra.color.statistics.deltaE76
import org.openrndr.math.Polar import org.openrndr.math.Polar
fun main() { fun main() = application {
application { configure {
configure { width = 720
width = 720 height = 720
height = 720 }
} program {
program { extend {
extend { drawer.clear(ColorRGBa.BLACK)
drawer.clear(ColorRGBa.BLACK) drawer.fill = null
drawer.fill = null drawer.stroke = ColorRGBa.WHITE.opacify(0.2)
drawer.stroke = ColorRGBa.WHITE.opacify(0.2) for (i in 10 until 270 step 10) {
for (i in 10 until 270 step 10) { drawer.circle(drawer.bounds.center, i.toDouble())
drawer.circle(drawer.bounds.center, i.toDouble()) }
}
drawer.stroke = null drawer.stroke = null
val startColor = ColorRGBa.RED.toOKHSVa().shiftHue(seconds*36.0).toRGBa() val startColor = ColorRGBa.RED.toOKHSVa().shiftHue(seconds * 36.0).toRGBa()
drawer.circles { drawer.circles {
for (j in 99 downTo 0) { for (j in 99 downTo 0) {
for (i in 0 until 360 step 10) { for (i in 0 until 360 step 10) {
val color = startColor.toOKHSVa().shiftHue(i.toDouble()).saturate(j / 99.0).toRGBa() val color = startColor.toOKHSVa().shiftHue(i.toDouble()).saturate(j / 99.0).toRGBa()
val distance = color.deltaE76(startColor) val distance = color.deltaE76(startColor)
val p = Polar(seconds * 36.0 + i.toDouble(), distance).cartesian + drawer.bounds.center val p = Polar(seconds * 36.0 + i.toDouble(), distance).cartesian + drawer.bounds.center
fill = color fill = color
circle(p, 2.0) circle(p, 2.0)
}
} }
} }
} }
} }
} }
} }

View File

@@ -6,81 +6,79 @@ import org.openrndr.extra.color.fettepalette.generateColorRamp
import org.openrndr.math.Vector2 import org.openrndr.math.Vector2
import kotlin.random.Random import kotlin.random.Random
fun main() { fun main() = application {
application { configure {
configure { width = 720
width = 720 height = 720
height = 720 }
}
program { program {
val total = 9 val total = 9
extend {
val ramp = generateColorRamp(
total = total,
centerHue = (mouse.position.x / width) * 360.0,
curveMethod = Lamé,
hueCycle = mouse.position.y / height,
curveAccent = 0.0,
offsetTint = 0.01,
offsetShade = 0.01,
tintShadeHueShift = 0.01,
offsetCurveModTint = 0.03,
offsetCurveModShade = 0.03,
minSaturationLight = Vector2.ZERO,
maxSaturationLight = Vector2.ONE,
useOK = true
)
fun rampSquare(ramp: ColorRamp, random: Random, position: Vector2, width: Double) {
drawer.isolated {
drawer.fill = ramp.baseColors.random(random).toRGBa()
drawer.stroke = null
drawer.rectangle(position, width, width)
drawer.fill = ramp.lightColors.random(random).toRGBa()
drawer.rectangle(position + Vector2(width / 4.0, width / 4.0), width / 4.0, width / 2.0)
val dc = ramp.darkColors.shuffled(random).take(2)
drawer.fill = dc[0].toRGBa()
drawer.rectangle(position + Vector2(width / 2.0, width / 4.0), width / 4.0, width / 4.0)
drawer.fill = dc[1].toRGBa()
drawer.rectangle(position + Vector2(width / 2.0, width / 2.0), width / 4.0, width / 4.0)
}
}
extend {
val ramp = generateColorRamp(
total = total,
centerHue = (mouse.position.x / width) * 360.0,
curveMethod = Lamé,
hueCycle = mouse.position.y / height,
curveAccent = 0.0,
offsetTint = 0.01,
offsetShade = 0.01,
tintShadeHueShift = 0.01,
offsetCurveModTint = 0.03,
offsetCurveModShade = 0.03,
minSaturationLight = Vector2.ZERO,
maxSaturationLight = Vector2.ONE,
useOK = true
)
fun rampSquare(ramp: ColorRamp, random: Random, position: Vector2, width: Double) {
drawer.isolated { drawer.isolated {
for ((index, i) in ramp.lightColors.withIndex()) { drawer.fill = ramp.baseColors.random(random).toRGBa()
drawer.stroke = null drawer.stroke = null
drawer.fill = i.toRGBa() drawer.rectangle(position, width, width)
drawer.rectangle(20.0, 20.0, 50.0, 50.0)
drawer.translate(50.0, 0.0)
}
}
drawer.isolated {
for ((index, i) in ramp.baseColors.withIndex()) {
drawer.stroke = null
drawer.fill = i.toRGBa()
drawer.rectangle(20.0, 70.0, 50.0, 50.0)
drawer.translate(50.0, 0.0)
}
}
drawer.isolated {
for ((index, i) in ramp.darkColors.withIndex()) {
drawer.stroke = null
drawer.fill = i.toRGBa()
drawer.rectangle(20.0, 120.0, 50.0, 50.0)
drawer.translate(50.0, 0.0)
}
}
val random = Random(seconds.toInt()) drawer.fill = ramp.lightColors.random(random).toRGBa()
rampSquare(ramp, random, Vector2(180.0, 180.0), 360.0) drawer.rectangle(position + Vector2(width / 4.0, width / 4.0), width / 4.0, width / 2.0)
val dc = ramp.darkColors.shuffled(random).take(2)
drawer.fill = dc[0].toRGBa()
drawer.rectangle(position + Vector2(width / 2.0, width / 4.0), width / 4.0, width / 4.0)
drawer.fill = dc[1].toRGBa()
drawer.rectangle(position + Vector2(width / 2.0, width / 2.0), width / 4.0, width / 4.0)
}
} }
drawer.isolated {
for ((index, i) in ramp.lightColors.withIndex()) {
drawer.stroke = null
drawer.fill = i.toRGBa()
drawer.rectangle(20.0, 20.0, 50.0, 50.0)
drawer.translate(50.0, 0.0)
}
}
drawer.isolated {
for ((index, i) in ramp.baseColors.withIndex()) {
drawer.stroke = null
drawer.fill = i.toRGBa()
drawer.rectangle(20.0, 70.0, 50.0, 50.0)
drawer.translate(50.0, 0.0)
}
}
drawer.isolated {
for ((index, i) in ramp.darkColors.withIndex()) {
drawer.stroke = null
drawer.fill = i.toRGBa()
drawer.rectangle(20.0, 120.0, 50.0, 50.0)
drawer.translate(50.0, 0.0)
}
}
val random = Random(seconds.toInt())
rampSquare(ramp, random, Vector2(180.0, 180.0), 360.0)
} }
} }
} }

View File

@@ -8,70 +8,68 @@ import org.openrndr.extra.gui.addTo
import org.openrndr.math.Vector2 import org.openrndr.math.Vector2
import kotlin.random.Random import kotlin.random.Random
fun main() { fun main() = application {
application { configure {
configure { width = 720
width = 720 height = 720
height = 720 }
}
program { program {
val gui = GUI() val gui = GUI()
val parameters = ColorRampParameters() val parameters = ColorRampParameters()
parameters.addTo(gui) parameters.addTo(gui)
extend(gui)
extend {
val ramp = generateColorRamp(parameters)
fun rampSquare(ramp: ColorRamp, random: Random, position: Vector2, width: Double) {
drawer.isolated {
drawer.fill = ramp.baseColors.random(random).toRGBa()
drawer.stroke = null
drawer.rectangle(position, width, width)
drawer.fill = ramp.lightColors.random(random).toRGBa()
drawer.rectangle(position + Vector2(width / 4.0, width / 4.0), width / 4.0, width / 2.0)
val dc = ramp.darkColors.shuffled(random).take(2)
drawer.fill = dc[0].toRGBa()
drawer.rectangle(position + Vector2(width / 2.0, width / 4.0), width / 4.0, width / 4.0)
drawer.fill = dc[1].toRGBa()
drawer.rectangle(position + Vector2(width / 2.0, width / 2.0), width / 4.0, width / 4.0)
}
}
drawer.translate(200.0, 0.0)
extend(gui)
extend {
val ramp = generateColorRamp(parameters)
fun rampSquare(ramp: ColorRamp, random: Random, position: Vector2, width: Double) {
drawer.isolated { drawer.isolated {
for ((index, i) in ramp.lightColors.withIndex()) { drawer.fill = ramp.baseColors.random(random).toRGBa()
drawer.stroke = null drawer.stroke = null
drawer.fill = i.toRGBa() drawer.rectangle(position, width, width)
drawer.rectangle(20.0, 20.0, 50.0, 50.0)
drawer.translate(50.0, 0.0)
}
}
drawer.isolated {
for ((index, i) in ramp.baseColors.withIndex()) {
drawer.stroke = null
drawer.fill = i.toRGBa()
drawer.rectangle(20.0, 70.0, 50.0, 50.0)
drawer.translate(50.0, 0.0)
}
}
drawer.isolated {
for ((index, i) in ramp.darkColors.withIndex()) {
drawer.stroke = null
drawer.fill = i.toRGBa()
drawer.rectangle(20.0, 120.0, 50.0, 50.0)
drawer.translate(50.0, 0.0)
}
}
val random = Random(seconds.toInt()) drawer.fill = ramp.lightColors.random(random).toRGBa()
rampSquare(ramp, random, Vector2(20.0, 180.0), 360.0) drawer.rectangle(position + Vector2(width / 4.0, width / 4.0), width / 4.0, width / 2.0)
val dc = ramp.darkColors.shuffled(random).take(2)
drawer.fill = dc[0].toRGBa()
drawer.rectangle(position + Vector2(width / 2.0, width / 4.0), width / 4.0, width / 4.0)
drawer.fill = dc[1].toRGBa()
drawer.rectangle(position + Vector2(width / 2.0, width / 2.0), width / 4.0, width / 4.0)
}
} }
drawer.translate(200.0, 0.0)
drawer.isolated {
for ((index, i) in ramp.lightColors.withIndex()) {
drawer.stroke = null
drawer.fill = i.toRGBa()
drawer.rectangle(20.0, 20.0, 50.0, 50.0)
drawer.translate(50.0, 0.0)
}
}
drawer.isolated {
for ((index, i) in ramp.baseColors.withIndex()) {
drawer.stroke = null
drawer.fill = i.toRGBa()
drawer.rectangle(20.0, 70.0, 50.0, 50.0)
drawer.translate(50.0, 0.0)
}
}
drawer.isolated {
for ((index, i) in ramp.darkColors.withIndex()) {
drawer.stroke = null
drawer.fill = i.toRGBa()
drawer.rectangle(20.0, 120.0, 50.0, 50.0)
drawer.translate(50.0, 0.0)
}
}
val random = Random(seconds.toInt())
rampSquare(ramp, random, Vector2(20.0, 180.0), 360.0)
} }
} }
} }

View File

@@ -10,37 +10,41 @@ import org.openrndr.extra.color.spaces.ColorHSLUVa
import org.openrndr.math.Vector2 import org.openrndr.math.Vector2
import org.openrndr.shape.Rectangle import org.openrndr.shape.Rectangle
fun main() { fun main() = application {
application { configure {
program { width = 720
val font = loadFont("demo-data/fonts/IBMPlexMono-Regular.ttf", 26.0) height = 540
extend { }
drawer.stroke = null program {
drawer.clear(rgb(0.3)) val font = loadFont("demo-data/fonts/IBMPlexMono-Regular.ttf", 26.0)
val s = mouse.position.x / width extend {
val l = mouse.position.y / height drawer.stroke = null
for (a in 0 until 360 step 12) { drawer.clear(rgb(0.3))
val pos = Vector2(0.0, 110.0) val s = mouse.position.x / width
drawer.isolated { val l = mouse.position.y / height
translate(bounds.center) for (a in 0 until 360 step 12) {
rotate(a * 1.0) val pos = Vector2(0.0, 110.0)
drawer.isolated {
translate(bounds.center)
rotate(a * 1.0)
fill = ColorHSLUVa(a * 1.0, s, l).toRGBa().toSRGB() fill = ColorHSLUVa(a * 1.0, s, l).toRGBa().toSRGB()
rectangle(Rectangle(pos * 1.2, 40.0, 300.0)) rectangle(Rectangle(pos * 1.2, 40.0, 300.0))
fill = ColorHSLa(a * 1.0, s, l).toRGBa() fill = ColorHSLa(a * 1.0, s, l).toRGBa()
rectangle(Rectangle.fromCenter(pos, 30.0, 60.0)) rectangle(Rectangle.fromCenter(pos, 30.0, 60.0))
}
} }
drawer.fontMap = font }
drawer.fill = if(l > 0.8) ColorRGBa.BLACK else ColorRGBa.WHITE drawer.fontMap = font
drawer.text("HSLa", width * 0.48, height * 0.73) drawer.fill = if (l > 0.8) ColorRGBa.BLACK else ColorRGBa.WHITE
drawer.text("HSLUVa", width * 0.8, height * 0.52) drawer.text("HSLa", width * 0.48, height * 0.73)
drawer.text("hue: 0 to 360, " + drawer.text("HSLUVa", width * 0.8, height * 0.52)
drawer.text(
"hue: 0 to 360, " +
"saturation: ${String.format("%.02f", s)}, " + "saturation: ${String.format("%.02f", s)}, " +
"lightness: ${String.format("%.02f", l)}", "lightness: ${String.format("%.02f", l)}",
30.0, 460.0) 30.0, height - 30.0
} )
} }
} }
} }

View File

@@ -7,41 +7,40 @@ import org.openrndr.math.Polar
import org.openrndr.math.Vector2 import org.openrndr.math.Vector2
import kotlin.math.sqrt import kotlin.math.sqrt
fun main() { fun main() = application {
application { configure {
configure { width = 720
width = 720 height = 720
height = 720 }
val g = Math.PI * 2.0 * (1.0 - 1.0 / 1.61803398875)
fun phyllotaxis(count: Int) = sequence {
for (i in 0 until count) {
yield(Polar(Math.toDegrees(i * 1.0), g * i))
} }
}
val g = Math.PI * 2.0 * (1.0 - 1.0 / 1.61803398875) program {
fun phyllotaxis(count: Int) = sequence { extend {
for (i in 0 until count) { drawer.clear(ColorRGBa.GRAY)
yield(Polar(Math.toDegrees(i * 1.0), g * i)) val color = ColorRGBa.RED
} val hc = color.toHSLUVa()
} drawer.stroke = null
drawer.strokeWeight = 0.0
program { val count = 400
extend { val bobRadius = 20.0
drawer.clear(ColorRGBa.GRAY)
val color = ColorRGBa.RED
val hc = color.toHSLUVa()
drawer.stroke = null
drawer.strokeWeight = 0.0
val count = 400 for (i in phyllotaxis(count)) {
val bobRadius = 20.0 val h = i.theta
val s = i.radius / (count * g)
for (i in phyllotaxis(count)) { for (l in 9 downTo 0) {
val h = i.theta val position =
val s = i.radius / (count * g) i.cartesian / (count * g) * (width / 2.0 - bobRadius) + Vector2(width / 2.0, height / 2.0)
for (l in 9 downTo 0) { drawer.fill = hc.shiftHue(h).saturate(s).shade((9 - l) / 4.5).toRGBa().toSRGB()
val position = i.cartesian / (count * g) * (width / 2.0 - bobRadius) + Vector2(width / 2.0, height / 2.0) drawer.circle(position, sqrt(s) * 20.0 * l / 9.0)
drawer.fill = hc.shiftHue(h).saturate(s).shade((9 - l) / 4.5).toRGBa().toSRGB()
drawer.circle(position, sqrt(s) * 20.0 * l / 9.0)
}
} }
} }
} }
} }
} }

View File

@@ -5,37 +5,35 @@ import org.openrndr.extra.color.spaces.OKHSV
import org.openrndr.extra.color.tools.mixHue import org.openrndr.extra.color.tools.mixHue
import org.openrndr.extra.color.tools.withHue import org.openrndr.extra.color.tools.withHue
fun main() { fun main() = application {
application { configure {
configure { width = 720
width = 800 height = 720
height = 800 }
} program {
program { extend {
extend { val seedColor = ColorRGBa.PINK
val seedColor = ColorRGBa.PINK val targetHue = seconds * 100.0
val targetHue = seconds*100.0
val rows = 10 val rows = 10
val columns = 12 val columns = 12
val cellWidth = width / columns.toDouble() val cellWidth = width / columns.toDouble()
val cellHeight = height / rows.toDouble() val cellHeight = height / rows.toDouble()
drawer.stroke = null drawer.stroke = null
for (j in 0 until 10) { for (j in 0 until 10) {
drawer.isolated { drawer.isolated {
for (i in 0 until columns) { for (i in 0 until columns) {
drawer.fill = seedColor drawer.fill = seedColor
.withHue<OKHSV>(i * 360.0 / columns) .withHue<OKHSV>(i * 360.0 / columns)
.mixHue<OKHSV>(targetHue, j / (rows.toDouble()-1.0)) .mixHue<OKHSV>(targetHue, j / (rows.toDouble() - 1.0))
drawer.rectangle(0.0, 0.0, cellWidth, cellHeight) drawer.rectangle(0.0, 0.0, cellWidth, cellHeight)
drawer.translate(cellWidth, 0.0) drawer.translate(cellWidth, 0.0)
}
} }
drawer.translate(0.0, cellHeight)
} }
drawer.translate(0.0, cellHeight)
} }
} }
} }
} }

View File

@@ -3,41 +3,33 @@ import org.openrndr.color.ColorRGBa
import org.openrndr.draw.isolated import org.openrndr.draw.isolated
import org.openrndr.extra.color.mixing.mixSpectral import org.openrndr.extra.color.mixing.mixSpectral
import org.openrndr.extra.color.spaces.OKHSV import org.openrndr.extra.color.spaces.OKHSV
import org.openrndr.extra.color.spaces.OKLab
import org.openrndr.extra.color.tools.saturate
import org.openrndr.extra.color.tools.shadeLuminosity
import org.openrndr.extra.color.tools.shiftHue import org.openrndr.extra.color.tools.shiftHue
fun main() { fun main() = application {
application { configure {
configure { width = 720
width = 800 height = 720
height = 800 }
} program {
program { extend {
val a = ColorRGBa.BLUE.shiftHue<OKHSV>(0.0).saturate<OKHSV>(0.3).shadeLuminosity<OKLab>(0.3)
val b = ColorRGBa.BLUE.shiftHue<OKHSV>(60.0).saturate<OKHSV>(0.8)
extend { drawer.isolated {
for (i in 0 until 60) {
val c = mixSpectral(a, b, i / 59.0, 0.0, 0.0).toSRGB()
drawer.fill = c
drawer.stroke = null
drawer.rectangle(0.0, 0.0, width / 60.0, 1.0 * height)
for (j in 0 until 60) { drawer.translate(width / 60.0, 0.0)
val p = 3.0
val a = ColorRGBa.BLUE.shiftHue<OKHSV>(j * p)
val b = ColorRGBa.BLUE.shiftHue<OKHSV>(j * p + 180.0)
drawer.isolated {
for (i in 0 until 60) {
val c = mixSpectral(a, b, i / 59.0, 0.0, 0.0).toSRGB()
drawer.fill = c
drawer.stroke = null
drawer.rectangle(0.0, 0.0, width/60.0, 0.5 * height/60.0)
drawer.fill = a.mix(b, i / 59.0)
drawer.rectangle(0.0, 0.5 * height, width/60.0, 0.5 * height/60.0)
drawer.translate(width/60.0, 0.0)
}
}
drawer.translate(0.0, 0.5 * height/60.0)
} }
} }
drawer.translate(0.0, 0.5 * height / 60.0)
} }
} }
} }

View File

@@ -1,11 +1,18 @@
import org.openrndr.application import org.openrndr.application
import org.openrndr.color.ColorRGBa import org.openrndr.color.ColorRGBa
import org.openrndr.color.rgb
import org.openrndr.extra.color.spaces.ColorOKHSLa import org.openrndr.extra.color.spaces.ColorOKHSLa
import org.openrndr.extra.color.spaces.ColorOKHSVa import org.openrndr.extra.color.spaces.ColorOKHSVa
fun main() = application { fun main() = application {
configure {
width = 720
height = 160
}
program { program {
extend { extend {
drawer.clear(rgb(0.2))
val c = ColorRGBa.GREEN val c = ColorRGBa.GREEN
val okhsv = ColorOKHSVa.fromColorRGBa(c) val okhsv = ColorOKHSVa.fromColorRGBa(c)
val hsv = c.toHSVa() val hsv = c.toHSVa()

View File

@@ -3,15 +3,22 @@
import org.openrndr.application import org.openrndr.application
import org.openrndr.color.ColorRGBa import org.openrndr.color.ColorRGBa
import org.openrndr.extra.color.spaces.ColorXSLUVa import org.openrndr.extra.color.spaces.ColorXSLUVa
import org.openrndr.extra.color.spaces.toHSLUVa
import org.openrndr.math.Polar import org.openrndr.math.Polar
import org.openrndr.shape.contour import org.openrndr.shape.contour
fun main() { fun main() = application {
configure {
width = 720
height = 720
}
class Arc(val start: Double, val radius: Double, val length: Double, val height: Double) { class Arc(val start: Double, val radius: Double, val length: Double, val height: Double) {
fun split(offset: Double = 0.0): List<Arc> { fun split(offset: Double = 0.0): List<Arc> {
val hl = length / 2.0 val hl = length / 2.0
return listOf(Arc(start, radius + offset, hl, height), Arc(start + hl, radius + offset, hl, height)) return listOf(
Arc(start, radius + offset, hl, height),
Arc(start + hl, radius + offset, hl, height)
)
} }
val contour val contour
@@ -31,30 +38,22 @@ fun main() {
this + flatMap { it.split(it.height) }.split(depth - 1) this + flatMap { it.split(it.height) }.split(depth - 1)
} }
application { program {
configure { val arcs = (0..4).map { Arc(it * 90.0 - 45.0, 50.0, 90.0, 50.0) }.split(5)
width = 720
height = 720
}
program { extend {
val arcs = (0..4).map { Arc(it * 90.0 - 45.0, 50.0, 90.0, 50.0) }.split(5) drawer.clear(ColorRGBa.GRAY)
val color = ColorRGBa.RED
extend { drawer.stroke = ColorRGBa.BLACK
drawer.clear(ColorRGBa.GRAY) drawer.strokeWeight = 1.0
val color = ColorRGBa.RED drawer.translate(drawer.bounds.center)
val hc = color.toHSLUVa() val l = if (System.getProperty("takeScreenshot") == "true") 0.7 else mouse.position.y / height
drawer.stroke = ColorRGBa.BLACK val s = if (System.getProperty("takeScreenshot") == "true") 1.0 else mouse.position.x / width
drawer.strokeWeight = 1.0 for (arc in arcs) {
drawer.translate(drawer.bounds.center) val xsluv = ColorXSLUVa(arc.start + arc.length / 2.0, s, l, 1.0)
val l = if (System.getProperty("takeScreenshot") == "true") 0.7 else mouse.position.y / height drawer.fill = xsluv.toRGBa()
val s = if (System.getProperty("takeScreenshot") == "true") 1.0 else mouse.position.x / width drawer.contour(arc.contour)
for (arc in arcs) {
val xsluv = ColorXSLUVa(arc.start + arc.length / 2.0, s, l, 1.0)
drawer.fill = xsluv.toRGBa()
drawer.contour(arc.contour)
}
} }
} }
} }
} }

View File

@@ -1,3 +1,5 @@
package colorRange
// Comparison of color lists generated by interpolating from // Comparison of color lists generated by interpolating from
// PINK to BLUE in different color models // PINK to BLUE in different color models
@@ -10,6 +12,10 @@ import org.openrndr.math.map
import org.openrndr.shape.Rectangle import org.openrndr.shape.Rectangle
fun main() = application { fun main() = application {
configure {
width = 720
height = 540
}
program { program {
val numColors = 10 val numColors = 10
val colorLists = listOf( val colorLists = listOf(

View File

@@ -1,3 +1,5 @@
package colorRange
// Create a colorSequence with multiple color models // Create a colorSequence with multiple color models
import org.openrndr.application import org.openrndr.application
@@ -6,6 +8,10 @@ import org.openrndr.extra.color.palettes.colorSequence
import org.openrndr.extra.color.spaces.toHSLUVa import org.openrndr.extra.color.spaces.toHSLUVa
fun main() = application { fun main() = application {
configure {
width = 720
height = 360
}
program { program {
extend { extend {
val cs = colorSequence(0.0 to ColorRGBa.PINK, val cs = colorSequence(0.0 to ColorRGBa.PINK,

View File

@@ -0,0 +1,53 @@
package colorRange
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.loadFont
import org.openrndr.extra.color.palettes.rangeTo
import org.openrndr.extra.color.spaces.*
fun main() = application {
configure {
width = 720
height = 30 + 50 * 11 // row count
}
program {
extend {
drawer.clear(ColorRGBa.WHITE)
val colorA = ColorRGBa.BLUE
val colorB = ColorRGBa.PINK
val stepCount = 25
val allSteps = listOf(
"RGB" to (colorA..colorB blend stepCount),
"RGB linear" to (colorA.toLinear()..colorB.toLinear() blend stepCount),
"HSV" to (colorA..colorB.toHSVa() blend stepCount),
"Lab" to (colorA.toLABa()..colorB.toLABa() blend stepCount),
"LCh(ab)" to (colorA.toLCHABa()..colorB.toLCHABa() blend stepCount),
"OKLab" to (colorA.toOKLABa()..colorB.toOKLABa() blend stepCount),
"OKLCh" to (colorA.toOKLCHa()..colorB.toOKLCHa() blend stepCount),
"OKHSV" to (colorA.toOKHSVa()..colorB.toOKHSVa() blend stepCount),
"OKHSL" to (colorA.toOKHSLa()..colorB.toOKHSLa() blend stepCount),
"HSLUV" to (colorA.toHSLUVa()..colorB.toHSLUVa() blend stepCount),
"XSLUV" to (colorA.toXSLUVa()..colorB.toXSLUVa() blend stepCount),
)
drawer.stroke = null
drawer.fontMap = loadFont("demo-data/fonts/IBMPlexMono-Regular.ttf", 16.0)
drawer.translate(20.0, 20.0)
for ((label, steps) in allSteps) {
drawer.fill = ColorRGBa.GRAY.shade(0.25)
drawer.text(label, 0.0, 24.0)
for (i in steps.indices) {
drawer.fill = steps[i].toSRGB()
drawer.rectangle(100.0 + i * 20.0, 0.0, 20.0, 40.0)
}
drawer.translate(0.0, 50.0)
}
}
}
}

View File

@@ -0,0 +1,87 @@
package colorRange
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.DrawPrimitive
import org.openrndr.draw.isolated
import org.openrndr.draw.loadFont
import org.openrndr.extra.camera.Orbital
import org.openrndr.extra.color.palettes.rangeTo
import org.openrndr.extra.color.spaces.toHSLUVa
import org.openrndr.extra.color.spaces.toOKLABa
import org.openrndr.extra.color.spaces.toOKLCHa
import org.openrndr.extra.color.spaces.toXSLUVa
import org.openrndr.extra.meshgenerators.sphereMesh
import org.openrndr.math.Vector3
fun main() = application {
configure {
width = 720
height = 720
}
program {
val mesh = sphereMesh(8, 8, radius = 0.1)
extend(Orbital())
extend {
drawer.clear(ColorRGBa.WHITE)
val colorA = ColorRGBa.BLUE.toHSVa().shiftHue(seconds * 40.0).toRGBa()
val colorB = ColorRGBa.PINK.toHSVa().shiftHue(-seconds * 34.0).toRGBa()
val stepCount = 25
val allSteps = listOf(
"RGB" to (colorA..colorB blend stepCount),
"RGB linear" to (colorA.toLinear()..colorB.toLinear() blend stepCount),
"HSV" to (colorA..colorB.toHSVa() blend stepCount),
"Lab" to (colorA.toLABa()..colorB.toLABa() blend stepCount),
"LCh(ab)" to (colorA.toLCHABa()..colorB.toLCHABa() blend stepCount),
"OKLab" to (colorA.toOKLABa()..colorB.toOKLABa() blend stepCount),
"OKLCh" to (colorA.toOKLCHa()..colorB.toOKLCHa() blend stepCount),
"HSLUV" to (colorA.toHSLUVa()..colorB.toHSLUVa() blend stepCount),
"XSLUV" to (colorA.toXSLUVa()..colorB.toXSLUVa() blend stepCount),
)
drawer.stroke = null
drawer.fontMap = loadFont("demo-data/fonts/IBMPlexMono-Regular.ttf", 16.0)
for ((_, steps) in allSteps) {
for (i in steps.indices) {
val srgb = steps[i].toSRGB().clip()
drawer.fill = srgb
drawer.isolated {
drawer.translate((srgb.r - 0.5) * 10.0, (srgb.g - 0.5) * 10.0, (srgb.b - 0.5) * 10.0)
drawer.vertexBuffer(mesh, DrawPrimitive.TRIANGLES)
}
}
val positions = steps.map {
val l = it.toSRGB().clip()
Vector3((l.r - 0.5) * 10.0, (l.g - 0.5) * 10.0, (l.b - 0.5) * 10.0)
}
drawer.stroke = ColorRGBa.BLACK.opacify(0.25)
drawer.strokeWeight = 10.0
drawer.lineStrip(positions)
}
drawer.lineSegments(
listOf(
Vector3(-5.0, -5.0, -5.0), Vector3(5.0, -5.0, -5.0),
Vector3(-5.0, -5.0, 5.0), Vector3(5.0, -5.0, 5.0),
Vector3(-5.0, 5.0, -5.0), Vector3(5.0, 5.0, -5.0),
Vector3(-5.0, 5.0, 5.0), Vector3(5.0, 5.0, 5.0),
Vector3(-5.0, -5.0, -5.0), Vector3(-5.0, 5.0, -5.0),
Vector3(5.0, -5.0, -5.0), Vector3(5.0, 5.0, -5.0),
Vector3(-5.0, -5.0, 5.0), Vector3(-5.0, 5.0, 5.0),
Vector3(5.0, -5.0, 5.0), Vector3(5.0, 5.0, 5.0),
Vector3(-5.0, -5.0, -5.0), Vector3(-5.0, -5.0, 5.0),
Vector3(5.0, -5.0, -5.0), Vector3(5.0, -5.0, 5.0),
Vector3(-5.0, 5.0, -5.0), Vector3(-5.0, 5.0, 5.0),
Vector3(5.0, 5.0, -5.0), Vector3(5.0, 5.0, 5.0),
)
)
}
}
}

View File

@@ -1,9 +1,15 @@
package colormap
import org.openrndr.application import org.openrndr.application
import org.openrndr.extra.color.colormaps.spectralZucconi6 import org.openrndr.extra.color.colormaps.spectralZucconi6
import org.openrndr.extra.noise.fastFloor import org.openrndr.extra.noise.fastFloor
import kotlin.math.sin import kotlin.math.sin
fun main() = application { fun main() = application {
configure {
width = 720
height = 360
}
program { program {
extend { extend {
drawer.stroke = null drawer.stroke = null

View File

@@ -1,9 +1,15 @@
package colormap
import org.openrndr.application import org.openrndr.application
import org.openrndr.draw.shadeStyle import org.openrndr.draw.shadeStyle
import org.openrndr.extra.color.colormaps.ColormapPhraseBook import org.openrndr.extra.color.colormaps.ColormapPhraseBook
import org.openrndr.extra.shaderphrases.preprocess import org.openrndr.extra.shaderphrases.preprocess
fun main() = application { fun main() = application {
configure {
width = 720
height = 360
}
program { program {
ColormapPhraseBook.register() ColormapPhraseBook.register()
val style = shadeStyle { val style = shadeStyle {
@@ -11,10 +17,8 @@ fun main() = application {
fragmentTransform = "x_fill.rgb = spectral_zucconi6(c_boundsPosition.x);" fragmentTransform = "x_fill.rgb = spectral_zucconi6(c_boundsPosition.x);"
} }
extend { extend {
drawer.run { drawer.shadeStyle = style
shadeStyle = style drawer.rectangle(drawer.bounds)
rectangle(bounds)
}
} }
} }
} }

View File

@@ -1,3 +1,5 @@
package colormap
import org.openrndr.application import org.openrndr.application
import org.openrndr.color.ColorRGBa import org.openrndr.color.ColorRGBa
import org.openrndr.draw.shadeStyle import org.openrndr.draw.shadeStyle
@@ -7,22 +9,28 @@ import org.openrndr.extra.shaderphrases.preprocess
import org.openrndr.math.Vector2 import org.openrndr.math.Vector2
fun main() = application { fun main() = application {
configure {
width = 720
height = 360
}
program { program {
ColormapPhraseBook.register() ColormapPhraseBook.register()
val backgroundStyle = shadeStyle { val backgroundStyle = shadeStyle {
fragmentPreamble = "#pragma import colormap.spectral_zucconi6".preprocess() fragmentPreamble = "#pragma import colormap.spectral_zucconi6".preprocess()
fragmentTransform = "x_fill.rgb = spectral_zucconi6(c_boundsPosition.x);" fragmentTransform = "x_fill.rgb = spectral_zucconi6(c_boundsPosition.x);"
} }
fun getColormapPoints( fun getColormapPoints(
block: ColorRGBa.() -> Double block: ColorRGBa.() -> Double
) = List(width) { x -> ) = List(width) { x ->
Vector2( Vector2(
x = x.toDouble(), x.toDouble(),
y = height.toDouble() height.toDouble()
- block(spectralZucconi6(x / width.toDouble())) - block(spectralZucconi6(x / width.toDouble()))
* height.toDouble() * height.toDouble()
) )
} }
val redPoints = getColormapPoints { r } val redPoints = getColormapPoints { r }
val greenPoints = getColormapPoints { g } val greenPoints = getColormapPoints { g }
val bluePoints = getColormapPoints { b } val bluePoints = getColormapPoints { b }

View File

@@ -1,9 +1,15 @@
package colormap
import org.openrndr.application import org.openrndr.application
import org.openrndr.extra.color.colormaps.turboColormap import org.openrndr.extra.color.colormaps.turboColormap
import org.openrndr.extra.noise.fastFloor import org.openrndr.extra.noise.fastFloor
import kotlin.math.sin import kotlin.math.sin
fun main() = application { fun main() = application {
configure {
width = 720
height = 360
}
program { program {
extend { extend {
drawer.stroke = null drawer.stroke = null

View File

@@ -1,9 +1,15 @@
package colormap
import org.openrndr.application import org.openrndr.application
import org.openrndr.draw.shadeStyle import org.openrndr.draw.shadeStyle
import org.openrndr.extra.color.colormaps.ColormapPhraseBook import org.openrndr.extra.color.colormaps.ColormapPhraseBook
import org.openrndr.extra.shaderphrases.preprocess import org.openrndr.extra.shaderphrases.preprocess
fun main() = application { fun main() = application {
configure {
width = 720
height = 360
}
program { program {
ColormapPhraseBook.register() ColormapPhraseBook.register()
val style = shadeStyle { val style = shadeStyle {
@@ -11,10 +17,8 @@ fun main() = application {
fragmentTransform = "x_fill.rgb = turbo_colormap(c_boundsPosition.x);" fragmentTransform = "x_fill.rgb = turbo_colormap(c_boundsPosition.x);"
} }
extend { extend {
drawer.run { drawer.shadeStyle = style
shadeStyle = style drawer.rectangle(drawer.bounds)
rectangle(bounds)
}
} }
} }
} }

View File

@@ -1,3 +1,5 @@
package colormap
import org.openrndr.application import org.openrndr.application
import org.openrndr.color.ColorRGBa import org.openrndr.color.ColorRGBa
import org.openrndr.draw.shadeStyle import org.openrndr.draw.shadeStyle
@@ -7,6 +9,10 @@ import org.openrndr.extra.shaderphrases.preprocess
import org.openrndr.math.Vector2 import org.openrndr.math.Vector2
fun main() = application { fun main() = application {
configure {
width = 720
height = 360
}
program { program {
ColormapPhraseBook.register() ColormapPhraseBook.register()
val backgroundStyle = shadeStyle { val backgroundStyle = shadeStyle {

View File

@@ -1,10 +1,14 @@
// Show color histogram of an image package histogram// Show color histogram of an image
import org.openrndr.application import org.openrndr.application
import org.openrndr.draw.loadImage import org.openrndr.draw.loadImage
import org.openrndr.extra.color.statistics.calculateHistogramRGB import org.openrndr.extra.color.statistics.calculateHistogramRGB
fun main() = application { fun main() = application {
configure {
width = 720
height = 540
}
program { program {
val useColors = 32 val useColors = 32
val image = loadImage("demo-data/images/image-001.png") val image = loadImage("demo-data/images/image-001.png")
@@ -29,7 +33,7 @@ fun main() = application {
"% of the image colors.") "% of the image colors.")
extend { extend {
drawer.image(image) drawer.image(image, 0.0, 0.0, width * 1.0, height * 1.0)
drawer.stroke = null drawer.stroke = null
var x = 0.0 var x = 0.0
topColorsSortedByLuminosity.forEachIndexed { i, (color, freq) -> topColorsSortedByLuminosity.forEachIndexed { i, (color, freq) ->

View File

@@ -1,4 +1,4 @@
// Show color histogram using non-uniform weighting package histogram// Show color histogram using non-uniform weighting
import org.openrndr.application import org.openrndr.application
import org.openrndr.draw.loadImage import org.openrndr.draw.loadImage
@@ -6,6 +6,10 @@ import org.openrndr.extra.color.statistics.calculateHistogramRGB
import kotlin.math.pow import kotlin.math.pow
fun main() = application { fun main() = application {
configure {
width = 720
height = 540
}
program { program {
val image = loadImage("demo-data/images/image-001.png") val image = loadImage("demo-data/images/image-001.png")
// -- here we use non-uniform weighting, such that bright colors are prioritized // -- here we use non-uniform weighting, such that bright colors are prioritized
@@ -16,7 +20,7 @@ fun main() = application {
// .subList(0, 32).sortedBy { it.first.toHSLa().h } // sort by hue // .subList(0, 32).sortedBy { it.first.toHSLa().h } // sort by hue
extend { extend {
drawer.image(image) drawer.image(image, 0.0, 0.0, width * 1.0, height * 1.0)
for (i in 0 until 32) { for (i in 0 until 32) {
drawer.fill = colors[i].first drawer.fill = colors[i].first
drawer.stroke = null drawer.stroke = null

View File

@@ -1,15 +1,18 @@
// Create a simple rectangle composition based on colors sampled from image package histogram// Create a simple rectangle composition based on colors sampled from image
import org.openrndr.application import org.openrndr.application
import org.openrndr.draw.loadImage import org.openrndr.draw.loadImage
import org.openrndr.extra.color.statistics.calculateHistogramRGB import org.openrndr.extra.color.statistics.calculateHistogramRGB
fun main() = application { fun main() = application {
configure {
width = 720
height = 540
}
program { program {
val image = loadImage("demo-data/images/image-001.png") val image = loadImage("demo-data/images/image-001.png")
val histogram = calculateHistogramRGB(image) val histogram = calculateHistogramRGB(image)
extend { extend {
drawer.image(image)
for (j in 0 until height step 32) { for (j in 0 until height step 32) {
for (i in 0 until width step 32) { for (i in 0 until width step 32) {
drawer.stroke = null drawer.stroke = null

View File

@@ -18,8 +18,8 @@ import org.openrndr.shape.Rectangle
*/ */
fun main() = application { fun main() = application {
configure { configure {
width = 1024 width = 720
height = 1024 height = 720
} }
program { program {

View File

@@ -1,25 +1,23 @@
import org.openrndr.MouseTracker
import org.openrndr.application import org.openrndr.application
import org.openrndr.color.ColorRGBa import org.openrndr.color.ColorRGBa
import org.openrndr.draw.* import org.openrndr.draw.ColorType
import org.openrndr.draw.constant
import org.openrndr.draw.createEquivalent
import org.openrndr.draw.tint
import org.openrndr.drawImage import org.openrndr.drawImage
import org.openrndr.extra.jumpfill.DirectionalField import org.openrndr.extra.jumpfill.DirectionalField
import org.openrndr.extra.noise.scatter import org.openrndr.extra.noise.scatter
import org.openrndr.extra.noise.simplex
import org.openrndr.math.IntVector2 import org.openrndr.math.IntVector2
import org.openrndr.math.Vector2
import org.openrndr.math.Vector3 import org.openrndr.math.Vector3
import org.openrndr.math.clamp import org.openrndr.math.clamp
import org.openrndr.shape.Rectangle
import kotlin.math.abs
/** /**
* Create directional distance field and demonstrate signed distance * Create directional distance field and demonstrate signed distance
*/ */
fun main() = application { fun main() = application {
configure { configure {
width = 1024 width = 720
height = 1024 height = 720
} }
program { program {
@@ -37,7 +35,10 @@ fun main() = application {
ddf.shadow.download() ddf.shadow.download()
extend { extend {
val p = (mouse.position * ddf.contentScale).toInt().clamp(IntVector2.ZERO, IntVector2(width-1, height-1)) val p = (mouse.position * ddf.contentScale).toInt().clamp(
IntVector2.ZERO,
IntVector2(width - 1, height - 1)
)
val c = ddf.shadow[p.x, p.y] val c = ddf.shadow[p.x, p.y]
val sdf3 = Vector3(c.r, c.g, c.b) val sdf3 = Vector3(c.r, c.g, c.b)

View File

@@ -25,8 +25,8 @@ import org.openrndr.shape.Rectangle
*/ */
fun main() = application { fun main() = application {
configure { configure {
width = 1024 width = 720
height = 1024 height = 720
} }
program { program {

View File

@@ -8,6 +8,10 @@ import org.openrndr.extra.fx.patterns.Checkers
import org.openrndr.extra.jumpfill.fx.InnerGlow import org.openrndr.extra.jumpfill.fx.InnerGlow
fun main() = application { fun main() = application {
configure {
width = 720
height = 720
}
program { program {
val c = compose { val c = compose {
layer { layer {

View File

@@ -8,6 +8,10 @@ import org.openrndr.extra.fx.patterns.Checkers
import org.openrndr.extra.jumpfill.fx.InnerGlow import org.openrndr.extra.jumpfill.fx.InnerGlow
fun main() = application { fun main() = application {
configure {
width = 720
height = 720
}
program { program {
val c = compose { val c = compose {
layer { layer {

View File

@@ -6,28 +6,26 @@ import org.openrndr.draw.colorBuffer
import org.openrndr.extra.jumpfill.ShapeSDF import org.openrndr.extra.jumpfill.ShapeSDF
import org.openrndr.extra.svg.loadSVG import org.openrndr.extra.svg.loadSVG
fun main() { fun main() = application {
application { configure {
configure { width = 720
width = 1280 height = 405
height = 720 }
} program {
program { val sdf = ShapeSDF()
val sdf = ShapeSDF() val df = colorBuffer(width, height, format = ColorFormat.RGBa, type = ColorType.FLOAT32)
val df = colorBuffer(width, height, format = ColorFormat.RGBa, type = ColorType.FLOAT32)
val shapes = loadSVG("orx-jumpflood/src/jvmDemo/resources/name.svg").findShapes().map { it.shape } val shapes = loadSVG("orx-jumpflood/src/jvmDemo/resources/name.svg").findShapes().map { it.shape }
sdf.setShapes(shapes) sdf.setShapes(shapes)
sdf.apply(emptyArray(), df) sdf.apply(emptyArray(), df)
val mouseTracker = MouseTracker(mouse) val mouseTracker = MouseTracker(mouse)
extend { extend {
if(mouseTracker.pressedButtons.isEmpty()) if(mouseTracker.pressedButtons.isEmpty())
drawer.image(df) drawer.image(df)
else else
drawer.shapes(shapes) drawer.shapes(shapes)
}
} }
} }
} }

View File

@@ -13,50 +13,48 @@ import org.openrndr.math.transforms.transform
import kotlin.math.min import kotlin.math.min
fun main() { fun main() = application {
application { configure {
configure { width = 720
width = 1280 height = 405
height = 720 }
} program {
program { val sdf0 = ShapeSDF()
val sdf0 = ShapeSDF() val df0 = colorBuffer(width, height, format = ColorFormat.RGBa, type = ColorType.FLOAT32)
val df0 = colorBuffer(width, height, format = ColorFormat.RGBa, type = ColorType.FLOAT32)
val sdf1 = ShapeSDF() val sdf1 = ShapeSDF()
val df1 = colorBuffer(width, height, format = ColorFormat.RGBa, type = ColorType.FLOAT32) val df1 = colorBuffer(width, height, format = ColorFormat.RGBa, type = ColorType.FLOAT32)
val shapes = loadSVG("orx-jumpflood/src/jvmDemo/resources/name.svg").findShapes().map { it.shape } val shapes = loadSVG("orx-jumpflood/src/jvmDemo/resources/name.svg").findShapes().map { it.shape }
val union = SDFSmoothIntersection() val union = SDFSmoothIntersection()
val onion = SDFOnion() val onion = SDFOnion()
val strokeFill = SDFStrokeFill() val strokeFill = SDFStrokeFill()
extend { extend {
drawer.clear(ColorRGBa.PINK) drawer.clear(ColorRGBa.PINK)
sdf0.setShapes(shapes) sdf0.setShapes(shapes)
sdf1.setShapes(shapes.map { sdf1.setShapes(shapes.map {
it.transform(transform { it.transform(transform {
translate(1280 / 2.0, 720.0 / 2) translate(drawer.bounds.center)
rotate(Vector3.Companion.UNIT_Z, seconds * 45.0 - 30.0) rotate(Vector3.Companion.UNIT_Z, seconds * 45.0 - 30.0)
translate(-1280 / 2.0, -720.0 / 2.0) translate(-drawer.bounds.center)
})
}) })
})
sdf0.apply(emptyArray(), df0) sdf0.apply(emptyArray(), df0)
sdf1.apply(emptyArray(), df1) sdf1.apply(emptyArray(), df1)
union.radius = 10.0 + min(mouse.position.y, 100.0) union.radius = 10.0 + min(mouse.position.y, 100.0)
union.apply(arrayOf(df0, df1), df0) union.apply(arrayOf(df0, df1), df0)
onion.radius = 20.0 onion.radius = 20.0
onion.apply(df0, df0) onion.apply(df0, df0)
strokeFill.strokeWeight = 2.0 strokeFill.strokeWeight = 2.0
strokeFill.apply(df0, df0) strokeFill.apply(df0, df0)
drawer.image(df0) drawer.image(df0)
}
} }
} }
} }

View File

@@ -9,47 +9,44 @@ import org.openrndr.extra.jumpfill.draw.SDFStrokeFill
import org.openrndr.extra.jumpfill.ops.SDFSmoothDifference import org.openrndr.extra.jumpfill.ops.SDFSmoothDifference
import org.openrndr.extra.svg.loadSVG import org.openrndr.extra.svg.loadSVG
fun main() = application {
configure {
width = 720
height = 405
}
program {
val sdf0 = ShapeSDF()
val sdf1 = ShapeSDF()
val df0 = colorBuffer(width, height, format = ColorFormat.RGBa, type = ColorType.FLOAT32)
val df1 = colorBuffer(width, height, format = ColorFormat.RGBa, type = ColorType.FLOAT32)
fun main() { val fd = FluidDistort()
application { fd.outputUV = true
configure {
width = 1280
height = 720
}
program {
val sdf0 = ShapeSDF()
val sdf1 = ShapeSDF()
val df0 = colorBuffer(width, height, format = ColorFormat.RGBa, type = ColorType.FLOAT32)
val df1 = colorBuffer(width, height, format = ColorFormat.RGBa, type = ColorType.FLOAT32)
val fd = FluidDistort() val uvmap = colorBuffer(width, height, type = ColorType.FLOAT16)
fd.outputUV = true
val uvmap = colorBuffer(width, height, type = ColorType.FLOAT16) val shapes = loadSVG("orx-jumpflood/src/jvmDemo/resources/name.svg").findShapes().map { it.shape }
val union = SDFSmoothDifference()
val shapes = loadSVG("orx-jumpflood/src/jvmDemo/resources/name.svg").findShapes().map { it.shape } sdf0.setShapes(shapes)
val union = SDFSmoothDifference() sdf1.setShapes(shapes)
sdf0.setShapes(shapes) val strokeFill = SDFStrokeFill()
sdf1.setShapes(shapes)
val strokeFill = SDFStrokeFill() extend {
drawer.clear(ColorRGBa.PINK)
extend { fd.apply(emptyArray(), uvmap)
drawer.clear(ColorRGBa.PINK)
fd.apply(emptyArray(), uvmap) sdf0.useUV = true
sdf0.apply(uvmap, df0)
sdf1.apply(uvmap, df1)
union.radius = 10.0
union.apply(arrayOf(df0, df1), df0)
sdf0.useUV = true strokeFill.strokeWeight = 10.0
sdf0.apply(uvmap, df0) strokeFill.apply(df0, df0)
sdf1.apply(uvmap, df1) drawer.image(df0)
union.radius = 10.0
union.apply(arrayOf(df0, df1), df0)
strokeFill.strokeWeight = 10.0
strokeFill.apply(df0, df0)
drawer.image(df0)
}
} }
} }
} }

View File

@@ -11,52 +11,49 @@ import org.openrndr.extra.jumpfill.ops.SDFSmoothDifference
import org.openrndr.extra.svg.loadSVG import org.openrndr.extra.svg.loadSVG
import org.openrndr.shape.Circle import org.openrndr.shape.Circle
fun main() = application {
configure {
width = 720
height = 405
}
program {
val gui = GUI()
val sdf0 = ShapeSDF()
val sdf1 = ShapeSDF()
val df0 = colorBuffer(width, height, format = ColorFormat.RGBa, type = ColorType.FLOAT32)
val df1 = colorBuffer(width, height, format = ColorFormat.RGBa, type = ColorType.FLOAT32)
fun main() { val perturb = Perturb()
application { perturb.outputUV = true
configure {
width = 1280
height = 720
}
program {
val gui = GUI()
val sdf0 = ShapeSDF()
val sdf1 = ShapeSDF()
val df0 = colorBuffer(width, height, format = ColorFormat.RGBa, type = ColorType.FLOAT32)
val df1 = colorBuffer(width, height, format = ColorFormat.RGBa, type = ColorType.FLOAT32)
val perturb = Perturb() val uvmap = colorBuffer(width, height, type = ColorType.FLOAT16)
perturb.outputUV = true
val uvmap = colorBuffer(width, height, type = ColorType.FLOAT16) val circleShapes = List(1) { Circle(drawer.bounds.center, 200.0).shape }
val shapes = loadSVG("orx-jumpflood/src/jvmDemo/resources/name.svg").findShapes().map { it.shape }
val circleShapes = List(1) { Circle(width/2.0, height/2.0, 200.0).shape} sdf0.setShapes(circleShapes)
val shapes = loadSVG("orx-jumpflood/src/jvmDemo/resources/name.svg").findShapes().map { it.shape } sdf1.setShapes(shapes)
sdf0.setShapes(circleShapes) val difference = SDFSmoothDifference()
sdf1.setShapes(shapes) val strokeFill = SDFStrokeFill()
val difference = SDFSmoothDifference() gui.add(perturb)
val strokeFill = SDFStrokeFill() extend(gui)
extend {
drawer.clear(ColorRGBa.PINK)
gui.add(perturb) perturb.phase = seconds * 0.1
extend(gui) perturb.apply(uvmap, uvmap)
extend {
drawer.clear(ColorRGBa.PINK)
perturb.phase = seconds * 0.1 sdf0.useUV = true
perturb.apply(uvmap, uvmap) sdf0.apply(uvmap, df0)
sdf1.apply(uvmap, df1)
difference.radius = 10.0
difference.apply(arrayOf(df0, df1), df0)
sdf0.useUV = true strokeFill.strokeWeight = 10.0
sdf0.apply(uvmap, df0) strokeFill.apply(df0, df0)
sdf1.apply(uvmap, df1) drawer.image(df0)
difference.radius = 10.0
difference.apply(arrayOf(df0, df1), df0)
strokeFill.strokeWeight = 10.0
strokeFill.apply(df0, df0)
drawer.image(df0)
}
} }
} }
} }

View File

@@ -11,66 +11,63 @@ import org.openrndr.extra.jumpfill.ops.SDFSmoothDifference
import org.openrndr.extra.svg.loadSVG import org.openrndr.extra.svg.loadSVG
import org.openrndr.math.Vector2 import org.openrndr.math.Vector2
import org.openrndr.shape.Circle import org.openrndr.shape.Circle
import kotlin.math.cos import kotlin.math.cos
import kotlin.math.sin import kotlin.math.sin
fun main() { fun main() = application {
application { configure {
configure { width = 720
width = 1280 height = 405
height = 720 }
} program {
program { val gui = GUI()
val gui = GUI() val sdf0 = ShapeSDF()
val sdf0 = ShapeSDF() val sdf1 = ShapeSDF()
val sdf1 = ShapeSDF() val df0 = colorBuffer(width, height, format = ColorFormat.RGBa, type = ColorType.FLOAT32)
val df0 = colorBuffer(width, height, format = ColorFormat.RGBa, type = ColorType.FLOAT32) val df1 = colorBuffer(width, height, format = ColorFormat.RGBa, type = ColorType.FLOAT32)
val df1 = colorBuffer(width, height, format = ColorFormat.RGBa, type = ColorType.FLOAT32)
val perturb = Perturb() val perturb = Perturb()
perturb.outputUV = true
val uvmap = colorBuffer(width, height, type = ColorType.FLOAT16)
val uvmap2 = colorBuffer(width, height, type = ColorType.FLOAT16)
val circleShapes = List(1) { Circle(drawer.bounds.center, 200.0).shape }
val shapes = loadSVG("orx-jumpflood/src/jvmDemo/resources/name.svg").findShapes().map { it.shape }
sdf0.setShapes(circleShapes)
sdf1.setShapes(shapes)
val difference = SDFSmoothDifference()
val strokeFill = SDFStrokeFill()
sdf0.useUV = true
gui.add(sdf0)
gui.add(perturb)
gui.add(strokeFill)
gui.add(difference)
extend(gui)
extend {
drawer.clear(ColorRGBa.PINK)
perturb.offset = Vector2(cos(seconds * 0.2), sin(seconds * 0.2))
perturb.outputUV = true perturb.outputUV = true
perturb.phase = seconds * 0.1
perturb.apply(uvmap, uvmap)
val uvmap = colorBuffer(width, height, type = ColorType.FLOAT16) perturb.offset = Vector2.ZERO
val uvmap2 = colorBuffer(width, height, type = ColorType.FLOAT16) perturb.outputUV = false
perturb.phase = seconds * 0.05
perturb.apply(uvmap, uvmap2)
val circleShapes = List(1) { Circle(width/2.0, height/2.0, 200.0).shape} sdf0.apply(uvmap2, df0)
val shapes = loadSVG("orx-jumpflood/src/jvmDemo/resources/name.svg").findShapes().map { it.shape } sdf1.apply(uvmap2, df1)
sdf0.setShapes(circleShapes) difference.apply(arrayOf(df0, df1), df0)
sdf1.setShapes(shapes)
val difference = SDFSmoothDifference() strokeFill.apply(df0, df0)
val strokeFill = SDFStrokeFill() drawer.image(df0)
sdf0.useUV = true
gui.add(sdf0)
gui.add(perturb)
gui.add(strokeFill)
gui.add(difference)
extend(gui)
extend {
drawer.clear(ColorRGBa.PINK)
perturb.offset = Vector2(cos(seconds*0.2), sin(seconds*0.2))
perturb.outputUV = true
perturb.phase = seconds * 0.1
perturb.apply(uvmap, uvmap)
perturb.offset = Vector2.ZERO
perturb.outputUV = false
perturb.phase = seconds * 0.05
perturb.apply(uvmap, uvmap2)
sdf0.apply(uvmap2, df0)
sdf1.apply(uvmap2, df1)
difference.apply(arrayOf(df0, df1), df0)
strokeFill.apply(df0, df0)
drawer.image(df0)
}
} }
} }
} }

View File

@@ -7,40 +7,38 @@ import org.openrndr.draw.renderTarget
import org.openrndr.extra.jumpfill.fx.Skeleton import org.openrndr.extra.jumpfill.fx.Skeleton
import org.openrndr.extra.noise.simplex import org.openrndr.extra.noise.simplex
fun main() { fun main() = application {
application { configure {
configure { width = 720
width = 1280 height = 540
height = 720 }
} program {
program { val skeleton = Skeleton()
val skeleton = Skeleton()
val input = renderTarget(width, height) { val input = renderTarget(width, height) {
colorBuffer() colorBuffer()
} }
val field = input.colorBuffer(0).createEquivalent(type = ColorType.FLOAT32) val field = input.colorBuffer(0).createEquivalent(type = ColorType.FLOAT32)
extend { extend {
drawer.isolatedWithTarget(input) { drawer.isolatedWithTarget(input) {
// -- draw something interesting // -- draw something interesting
drawer.stroke = null drawer.stroke = null
drawer.clear(ColorRGBa.BLACK) drawer.clear(ColorRGBa.BLACK)
drawer.fill = ColorRGBa.WHITE drawer.fill = ColorRGBa.WHITE
drawer.circle(mouse.position, 300.0) drawer.circle(mouse.position, 300.0)
drawer.fill = ColorRGBa.BLACK drawer.fill = ColorRGBa.BLACK
drawer.circle(mouse.position, 150.0) drawer.circle(mouse.position, 150.0)
drawer.fill = ColorRGBa.WHITE drawer.fill = ColorRGBa.WHITE
for (i in 0 until 30) { for (i in 0 until 30) {
val time = seconds * 0.25 val time = seconds * 0.25
val x = simplex(i * 20, time) * width / 2 + width / 2 val x = simplex(i * 20, time) * width / 2 + width / 2
val y = simplex(i * 20 + 5, time) * height / 2 + height / 2 val y = simplex(i * 20 + 5, time) * height / 2 + height / 2
val r = simplex(i*30, time) * 50.0 + 50.0 val r = simplex(i * 30, time) * 50.0 + 50.0
drawer.circle(x, y, r) drawer.circle(x, y, r)
}
} }
skeleton.apply(input.colorBuffer(0), field)
drawer.image(field)
} }
skeleton.apply(input.colorBuffer(0), field)
drawer.image(field)
} }
} }
} }

View File

@@ -2,46 +2,43 @@ import org.openrndr.application
import org.openrndr.color.ColorRGBa import org.openrndr.color.ColorRGBa
import org.openrndr.draw.ColorType import org.openrndr.draw.ColorType
import org.openrndr.draw.createEquivalent import org.openrndr.draw.createEquivalent
import org.openrndr.draw.isolatedWithTarget import org.openrndr.draw.isolatedWithTarget
import org.openrndr.draw.renderTarget import org.openrndr.draw.renderTarget
import org.openrndr.extra.jumpfill.fx.StraightSkeleton import org.openrndr.extra.jumpfill.fx.StraightSkeleton
import org.openrndr.extra.noise.simplex import org.openrndr.extra.noise.simplex
fun main() { fun main() = application {
application { configure {
configure { width = 720
width = 1280 height = 720
height = 720 }
program {
val straightSkeleton = StraightSkeleton()
val input = renderTarget(width, height) {
colorBuffer()
} }
program { val field = input.colorBuffer(0).createEquivalent(type = ColorType.FLOAT32)
val straightSkeleton = StraightSkeleton()
val input = renderTarget(width, height) {
colorBuffer()
}
val field = input.colorBuffer(0).createEquivalent(type = ColorType.FLOAT32)
extend { extend {
drawer.isolatedWithTarget(input) { drawer.isolatedWithTarget(input) {
// -- draw something interesting // -- draw something interesting
drawer.stroke = null drawer.stroke = null
drawer.clear(ColorRGBa.BLACK) drawer.clear(ColorRGBa.BLACK)
drawer.fill = ColorRGBa.WHITE drawer.fill = ColorRGBa.WHITE
drawer.circle(mouse.position, 300.0) drawer.circle(mouse.position, 300.0)
drawer.fill = ColorRGBa.BLACK drawer.fill = ColorRGBa.BLACK
drawer.circle(mouse.position, 150.0) drawer.circle(mouse.position, 150.0)
drawer.fill = ColorRGBa.WHITE drawer.fill = ColorRGBa.WHITE
for (i in 0 until 30) { for (i in 0 until 30) {
val time = seconds * 0.25 val time = seconds * 0.25
val x = simplex(i * 20, time) * width / 2 + width / 2 val x = simplex(i * 20, time) * width / 2 + width / 2
val y = simplex(i * 20 + 5, time) * height / 2 + height / 2 val y = simplex(i * 20 + 5, time) * height / 2 + height / 2
val r = simplex(i*30, time) * 50.0 + 50.0 val r = simplex(i * 30, time) * 50.0 + 50.0
drawer.circle(x, y, r) drawer.circle(x, y, r)
}
} }
straightSkeleton.apply(input.colorBuffer(0), field)
drawer.image(field)
} }
straightSkeleton.apply(input.colorBuffer(0), field)
drawer.image(field)
} }
} }
} }

View File

@@ -13,14 +13,14 @@ fun main() = application {
height = 512 height = 512
} }
program { program {
val rt = renderTarget(512, 512, 1.0) { val rt = renderTarget(width, height, 1.0) {
colorBuffer(type = ColorType.FLOAT32) colorBuffer(type = ColorType.FLOAT32)
} }
val encoder = EncodePoints() val encoder = EncodePoints()
val jf = JumpFlooder(512, 512, encodePoints = Passthrough()) val jf = JumpFlooder(width, height, encodePoints = Passthrough())
val jf2 = JumpFlooder(512, 512, encodePoints = Passthrough()) val jf2 = JumpFlooder(width, height, encodePoints = Passthrough())
val idcontours = IdContourPoints() val idcontours = IdContourPoints()
val contoured = colorBuffer(512, 512, type = ColorType.FLOAT32) val contoured = colorBuffer(width, height, type = ColorType.FLOAT32)
extend { extend {
fun plot(x: Double, y: Double, id: Double) { fun plot(x: Double, y: Double, id: Double) {
drawer.fill = ColorRGBa(id, 0.0, 0.0, 1.0) drawer.fill = ColorRGBa(id, 0.0, 0.0, 1.0)
@@ -53,7 +53,7 @@ fun main() = application {
drawer.image(contoured) drawer.image(contoured)
val flooded2 = jf2.jumpFlood(contoured) val flooded2 = jf2.jumpFlood(contoured)
drawer.image(flooded2, 512.0, 0.0) drawer.image(flooded2, width * 1.0, 0.0)
drawer.shadeStyle = shadeStyle { drawer.shadeStyle = shadeStyle {
fragmentTransform = """ fragmentTransform = """

View File

@@ -10,11 +10,11 @@ fun main() = application {
height = 512 height = 512
} }
program { program {
val rt = renderTarget(512, 512, 1.0) { val rt = renderTarget(width, height, 1.0) {
colorBuffer(type = ColorType.FLOAT32) colorBuffer(type = ColorType.FLOAT32)
} }
val flowfield = colorBuffer(512, 512, type = ColorType.FLOAT32) val flowfield = colorBuffer(width, height, type = ColorType.FLOAT32)
val cluster = ClusteredField(decodeMode = DecodeMode.DISTANCE, outputDistanceToContours = true) val cluster = ClusteredField(decodeMode = DecodeMode.DISTANCE, outputDistanceToContours = true)

View File

@@ -9,11 +9,11 @@ import org.openrndr.math.Vector2
fun main() = application { fun main() = application {
configure { configure {
width = 720 width = 512
height = 720 height = 512
} }
program { program {
val rt = renderTarget(720, 720, 1.0) { val rt = renderTarget(width, height, 1.0) {
colorBuffer(type = ColorType.FLOAT32) colorBuffer(type = ColorType.FLOAT32)
} }
val flowfield = colorBuffer(width, height, type = ColorType.FLOAT32) val flowfield = colorBuffer(width, height, type = ColorType.FLOAT32)
@@ -28,9 +28,9 @@ fun main() = application {
val points = drawer.bounds.scatter(20.0) val points = drawer.bounds.scatter(20.0)
drawer.points { drawer.points {
for ((index, point) in points.withIndex()) { for ((index, point) in points.withIndex()) {
fill = ColorRGBa((index+1.0)/points.size, 0.0, 0.0, 1.0) fill = ColorRGBa((index + 1.0) / points.size, 0.0, 0.0, 1.0)
for (i in 0 until 30) { for (i in 0 until 30) {
point(point + Vector2.uniformRing(15.0, 25.0)* Vector2(1.0, 1.0)) point(point + Vector2.uniformRing(15.0, 25.0) * Vector2(1.0, 1.0))
} }
} }
} }

View File

@@ -1,12 +1,8 @@
<svg version="1.1" baseProfile="tiny" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 1280 720" xml:space="preserve"> <?xml version="1.0" encoding="UTF-8"?>
<polygon fill="#FF00FF" stroke="#000000" stroke-miterlimit="2.6131" points="1013.8,424.3 1013.8,238 957.1,238 957.1,238 <svg width="720" height="405" version="1.1" viewBox="0 0 720 405" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><g fill="#f0f">
794.7,238 794.7,294.7 957.1,294.7 957.1,318.9 794.7,318.9 794.7,375.6 957.1,375.6 957.1,424.3 794.7,424.3 794.7,481 957.1,481 <path d="m538 166v13.6h-91.3v31.8h91.3v27.3h-91.3v31.8h137v-31.8h-13.5v-104h-123v31.8z" stroke="#000" stroke-miterlimit="2.61"/>
1013.8,481 1037.8,481 1037.8,424.3 "/> <path d="m397 148h-72.9v-13.6h-31.9v90.8h52.4v13.6h-52.4v31.8h137v-31.8h-52.4v-13.6h52.4v-90.8h-31.9zm0 45.4h-72.9v-13.6h72.9z" stroke="#000" stroke-miterlimit="2.61"/>
<path fill="#FF00FF" stroke="#000000" stroke-miterlimit="2.6131" d="M705.7,263.3H576V239h-56.7v119.2l0,0V401h93.2v24.3h-93.2V482 <path d="m201 157"/>
h243.1v-56.7h-93.2V401h93.2V239h-56.7V263.3L705.7,263.3z M705.7,344.3H576V320h129.7V344.3z"/> <path d="m201 157c-5.17-1.85-10.7-2.8-16.2-2.8-26.5 0-48 21.5-48 47.9 0 26.5 21.5 47.9 48 47.9 26.5 0 48-21.5 48-47.9v-0.224c0-20.2-12.8-38.2-31.9-44.9zm-16.2 60.8c-8.82 0-16-7.12-16-15.9s7.14-15.9 16-15.9c8.77 0 16 7.12 16 15.9-0.0562 8.8-7.19 15.9-16 15.9z" stroke="#000" stroke-miterlimit="2.61"/>
<path fill="#FF00FF" d="M356.6,279L356.6,279L356.6,279z"/> <rect x="242" y="134" width="31.9" height="136" stroke="#000" stroke-miterlimit="2.61"/>
<path fill="#FF00FF" stroke="#000000" stroke-miterlimit="2.6131" d="M356.6,279c-9.2-3.3-19-5-28.8-5c-47.2,0-85.5,38.3-85.5,85.5 </g></svg>
s38.3,85.5,85.5,85.5s85.5-38.3,85.5-85.5c0-0.1,0-0.3,0-0.4C413.3,323.1,390.5,291,356.6,279z M327.8,387.4
c-15.7,0-28.4-12.7-28.4-28.4c0-15.7,12.7-28.4,28.4-28.4c15.6,0,28.4,12.7,28.4,28.4C356.1,374.7,343.4,387.4,327.8,387.4z"/>
<rect x="430.1" y="238" fill="#FF00FF" stroke="#000000" stroke-miterlimit="2.6131" width="56.7" height="243"/>
</svg>

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 897 B

View File

@@ -16,6 +16,12 @@ fun main() = application {
program { program {
var time = 0.0 var time = 0.0
if (System.getProperty("takeScreenshot") == "true") {
extensions.filterIsInstance<SingleScreenshot>().forEach {
it.delayFrames = 200
}
}
// ------------------------------------------------------------ // ------------------------------------------------------------
// By default OPENRNDR clears the canvas on each animation // By default OPENRNDR clears the canvas on each animation
// frame. NoClear disables that behavior, letting you // frame. NoClear disables that behavior, letting you
@@ -29,11 +35,6 @@ fun main() = application {
backdrop = { drawer.clear(rgb(0.15)) } backdrop = { drawer.clear(rgb(0.15)) }
} }
if (System.getProperty("takeScreenshot") == "true") {
extensions.filterIsInstance<SingleScreenshot>().forEach {
it.delayFrames = 60
}
}
extend { extend {
// Draw something. For this demo *what* you draw is not so // Draw something. For this demo *what* you draw is not so
// important, only the fact that it stays on the canvas // important, only the fact that it stays on the canvas