From fc4f7275fbb378df469c28d49420b1a3260a4d96 Mon Sep 17 00:00:00 2001 From: Abe Pazos Date: Sat, 25 Jan 2025 13:30:18 +0100 Subject: [PATCH] Demos: ensure 720px wide, reduce indentation openrndr-demos, orx-color, orx-jumpflood, orx-no-clear --- .../src/demo/kotlin/Demo16BitPng.kt | 19 +-- .../src/demo/kotlin/DemoAsyncImages01.kt | 16 +- .../src/demo/kotlin/DemoBillboardCircles01.kt | 3 - .../src/demo/kotlin/DemoCatmullRom01.kt | 4 +- .../src/demo/kotlin/DemoCircleBatch03.kt | 1 - .../src/demo/kotlin/DemoContour03.kt | 1 - .../demo/kotlin/DemoContourIntersections02.kt | 52 +++---- .../demo/kotlin/DemoContourIntersections03.kt | 12 +- .../src/demo/kotlin/DemoCubemap01.kt | 9 +- .../src/demo/kotlin/DemoCubemap02.kt | 12 +- .../src/demo/kotlin/DemoCubemap03.kt | 12 +- .../src/demo/kotlin/DemoDDSImage01.kt | 18 +-- .../src/demo/kotlin/DemoGeometryShader01.kt | 42 +++--- .../src/demo/kotlin/DemoImageLoadStore01.kt | 15 +- .../src/demo/kotlin/DemoImageLoadStore02.kt | 2 - .../src/demo/kotlin/DemoImageLoadStore03.kt | 18 +-- .../src/demo/kotlin/DemoLineCapJoin.kt | 4 +- .../src/demo/kotlin/DemoLineDash01.kt | 6 +- .../src/demo/kotlin/DemoScreenCapture01.kt | 52 ++++--- .../demo/kotlin/DemoShaderStorageBuffer01.kt | 6 +- .../src/demo/kotlin/DemoTessShader01.kt | 74 +++++----- .../src/demo/kotlin/DemoTessShader02.kt | 70 +++++---- .../src/demo/kotlin/DemoTessShader03.kt | 80 +++++----- .../src/demo/kotlin/DemoTessShader04.kt | 112 +++++++------- .../src/demo/kotlin/DemoVolumeTexture01.kt | 2 +- .../demo/kotlin/DrawerNegativeDimensions.kt | 8 +- .../src/demo/kotlin/DrawerRectangleBatch03.kt | 7 +- orx-color/README.md | 130 ++++++++--------- .../src/jvmDemo/kotlin/DemoColorPalette01.kt | 18 ++- .../src/jvmDemo/kotlin/DemoColorPalette02.kt | 4 + .../src/jvmDemo/kotlin/DemoColorPlane01.kt | 119 ++++++++------- .../src/jvmDemo/kotlin/DemoColorPlane02.kt | 110 +++++++------- .../src/jvmDemo/kotlin/DemoColorRange03.kt | 52 ------- .../src/jvmDemo/kotlin/DemoColorRange04.kt | 87 ----------- .../src/jvmDemo/kotlin/DemoColorSequence01.kt | 68 +++++---- orx-color/src/jvmDemo/kotlin/DemoDeltaE.kt | 50 +++---- .../src/jvmDemo/kotlin/DemoFettePalette01.kt | 138 +++++++++--------- .../src/jvmDemo/kotlin/DemoFettePalette02.kt | 118 ++++++++------- orx-color/src/jvmDemo/kotlin/DemoHSLUV01.kt | 58 ++++---- orx-color/src/jvmDemo/kotlin/DemoHSLUV02.kt | 59 ++++---- .../src/jvmDemo/kotlin/DemoHueTools01.kt | 50 +++---- .../src/jvmDemo/kotlin/DemoMixSpectral01.kt | 50 +++---- orx-color/src/jvmDemo/kotlin/DemoOKHSV01.kt | 7 + orx-color/src/jvmDemo/kotlin/DemoXSLUV01.kt | 51 ++++--- .../{ => colorRange}/DemoColorRange01.kt | 6 + .../{ => colorRange}/DemoColorRange02.kt | 6 + .../kotlin/colorRange/DemoColorRange03.kt | 53 +++++++ .../kotlin/colorRange/DemoColorRange04.kt | 87 +++++++++++ .../DemoSpectralZucconiColormap.kt | 6 + .../DemoSpectralZucconiColormapPhrase.kt | 12 +- .../DemoSpectralZucconiColormapPlot.kt | 16 +- .../{ => colormap}/DemoTurboColormap.kt | 6 + .../{ => colormap}/DemoTurboColormapPhrase.kt | 12 +- .../{ => colormap}/DemoTurboColormapPlot.kt | 6 + .../kotlin/{ => histogram}/DemoHistogram01.kt | 8 +- .../kotlin/{ => histogram}/DemoHistogram02.kt | 8 +- .../kotlin/{ => histogram}/DemoHistogram03.kt | 7 +- .../jvmDemo/kotlin/DemoDirectionField01.kt | 4 +- .../jvmDemo/kotlin/DemoDirectionField02.kt | 19 +-- .../src/jvmDemo/kotlin/DemoDistanceField01.kt | 4 +- .../src/jvmDemo/kotlin/DemoInnerGlow01.kt | 4 + .../src/jvmDemo/kotlin/DemoInnerGlow02.kt | 4 + .../src/jvmDemo/kotlin/DemoShapeSDF01.kt | 32 ++-- .../src/jvmDemo/kotlin/DemoShapeSDF02.kt | 68 +++++---- .../src/jvmDemo/kotlin/DemoShapeSDF03.kt | 63 ++++---- .../src/jvmDemo/kotlin/DemoShapeSDF04.kt | 73 +++++---- .../src/jvmDemo/kotlin/DemoShapeSDF05.kt | 99 ++++++------- .../src/jvmDemo/kotlin/DemoSkeleton01.kt | 62 ++++---- .../jvmDemo/kotlin/DemoStraightSkeleton01.kt | 61 ++++---- .../src/jvmDemo/kotlin/DemoVoronoi01.kt | 10 +- .../src/jvmDemo/kotlin/DemoVoronoi02.kt | 4 +- .../src/jvmDemo/kotlin/DemoVoronoi03.kt | 10 +- orx-jumpflood/src/jvmDemo/resources/name.svg | 20 +-- .../src/jvmDemo/kotlin/DemoNoClear.kt | 11 +- 74 files changed, 1314 insertions(+), 1293 deletions(-) delete mode 100644 orx-color/src/jvmDemo/kotlin/DemoColorRange03.kt delete mode 100644 orx-color/src/jvmDemo/kotlin/DemoColorRange04.kt rename orx-color/src/jvmDemo/kotlin/{ => colorRange}/DemoColorRange01.kt (95%) rename orx-color/src/jvmDemo/kotlin/{ => colorRange}/DemoColorRange02.kt (89%) create mode 100644 orx-color/src/jvmDemo/kotlin/colorRange/DemoColorRange03.kt create mode 100644 orx-color/src/jvmDemo/kotlin/colorRange/DemoColorRange04.kt rename orx-color/src/jvmDemo/kotlin/{ => colormap}/DemoSpectralZucconiColormap.kt (89%) rename orx-color/src/jvmDemo/kotlin/{ => colormap}/DemoSpectralZucconiColormapPhrase.kt (75%) rename orx-color/src/jvmDemo/kotlin/{ => colormap}/DemoSpectralZucconiColormapPlot.kt (83%) rename orx-color/src/jvmDemo/kotlin/{ => colormap}/DemoTurboColormap.kt (89%) rename orx-color/src/jvmDemo/kotlin/{ => colormap}/DemoTurboColormapPhrase.kt (75%) rename orx-color/src/jvmDemo/kotlin/{ => colormap}/DemoTurboColormapPlot.kt (94%) rename orx-color/src/jvmDemo/kotlin/{ => histogram}/DemoHistogram01.kt (90%) rename orx-color/src/jvmDemo/kotlin/{ => histogram}/DemoHistogram02.kt (82%) rename orx-color/src/jvmDemo/kotlin/{ => histogram}/DemoHistogram03.kt (79%) diff --git a/openrndr-demos/src/demo/kotlin/Demo16BitPng.kt b/openrndr-demos/src/demo/kotlin/Demo16BitPng.kt index 640080f6..77f99c5c 100644 --- a/openrndr-demos/src/demo/kotlin/Demo16BitPng.kt +++ b/openrndr-demos/src/demo/kotlin/Demo16BitPng.kt @@ -1,16 +1,13 @@ - import org.openrndr.application import org.openrndr.draw.loadImage -fun main() { - application { - program { - val image16 = loadImage("demo-data/images/16-bit.png") - val image8 = loadImage("demo-data/images/image-001.png") - extend { - drawer.image(image16) - drawer.image(image8, 320.0, 0.0) - } +fun main() = application { + program { + val image16 = loadImage("demo-data/images/16-bit.png") + val image8 = loadImage("demo-data/images/image-001.png") + extend { + drawer.image(image16) + drawer.image(image8, 320.0, 0.0) } } -} \ No newline at end of file +} diff --git a/openrndr-demos/src/demo/kotlin/DemoAsyncImages01.kt b/openrndr-demos/src/demo/kotlin/DemoAsyncImages01.kt index 74b9e8e6..052ba1b3 100644 --- a/openrndr-demos/src/demo/kotlin/DemoAsyncImages01.kt +++ b/openrndr-demos/src/demo/kotlin/DemoAsyncImages01.kt @@ -1,15 +1,13 @@ import org.openrndr.application import org.openrndr.internal.colorBufferLoader -fun main() { - application { - program { - extend { - val proxy = colorBufferLoader.loadFromUrl("https://avatars3.githubusercontent.com/u/31103334?s=200&v=4") - proxy.colorBuffer?.let { - drawer.image(it) - } +fun main() = application { + program { + extend { + val proxy = colorBufferLoader.loadFromUrl("https://avatars3.githubusercontent.com/u/31103334?s=200&v=4") + proxy.colorBuffer?.let { + drawer.image(it) } } } -} \ No newline at end of file +} diff --git a/openrndr-demos/src/demo/kotlin/DemoBillboardCircles01.kt b/openrndr-demos/src/demo/kotlin/DemoBillboardCircles01.kt index ce19e55c..636eebb4 100644 --- a/openrndr-demos/src/demo/kotlin/DemoBillboardCircles01.kt +++ b/openrndr-demos/src/demo/kotlin/DemoBillboardCircles01.kt @@ -11,14 +11,12 @@ import org.openrndr.math.Vector3 fun main() = application { - configure { multisample = WindowMultisample.SampleCount(8) } program { extend(Orbital()) - val circlePositions = vertexBuffer(vertexFormat { attribute("position", VertexElementType.VECTOR3_FLOAT32) attribute("scale", VertexElementType.FLOAT32) @@ -31,7 +29,6 @@ fun main() = application { } } - extend { drawer.perspective(90.0, width*1.0/height*1.0, 0.1, 100.0) diff --git a/openrndr-demos/src/demo/kotlin/DemoCatmullRom01.kt b/openrndr-demos/src/demo/kotlin/DemoCatmullRom01.kt index fdaed550..46b06be0 100644 --- a/openrndr-demos/src/demo/kotlin/DemoCatmullRom01.kt +++ b/openrndr-demos/src/demo/kotlin/DemoCatmullRom01.kt @@ -9,7 +9,9 @@ import org.openrndr.shape.ShapeContour fun main() = application { 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 contour = ShapeContour.fromPoints(cmr.positions(200), true) diff --git a/openrndr-demos/src/demo/kotlin/DemoCircleBatch03.kt b/openrndr-demos/src/demo/kotlin/DemoCircleBatch03.kt index c23e08ca..93c4b775 100644 --- a/openrndr-demos/src/demo/kotlin/DemoCircleBatch03.kt +++ b/openrndr-demos/src/demo/kotlin/DemoCircleBatch03.kt @@ -10,7 +10,6 @@ This program demonstrates dynamic circle batches fun main() = application { program { - extend { drawer.clear(ColorRGBa.GRAY) drawer.circles { diff --git a/openrndr-demos/src/demo/kotlin/DemoContour03.kt b/openrndr-demos/src/demo/kotlin/DemoContour03.kt index cd9fb510..211cd938 100644 --- a/openrndr-demos/src/demo/kotlin/DemoContour03.kt +++ b/openrndr-demos/src/demo/kotlin/DemoContour03.kt @@ -12,7 +12,6 @@ fun main() { } program { - val cs = Rectangle(0.0, 0.0, 200.0, 200.0).contour val cc = Circle(100.0, 0.0, 100.0).contour diff --git a/openrndr-demos/src/demo/kotlin/DemoContourIntersections02.kt b/openrndr-demos/src/demo/kotlin/DemoContourIntersections02.kt index 88a06acb..ce9bcacc 100644 --- a/openrndr-demos/src/demo/kotlin/DemoContourIntersections02.kt +++ b/openrndr-demos/src/demo/kotlin/DemoContourIntersections02.kt @@ -5,33 +5,35 @@ import org.openrndr.shape.Circle import org.openrndr.shape.Rectangle import org.openrndr.shape.intersections -fun main() { - application { - program { - extend { - val circle = Circle(mouse.position, 200.0).contour +fun main() = application { + program { + extend { + val circle = Circle(mouse.position, 200.0).contour - drawer.fill = null - for (y in 50 until height step 100) { - for (x in 50 until width step 100) { + drawer.fill = null + for (y in 50 until height step 100) { + for (x in 50 until width step 100) { - 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 + 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 ints = intersections(circle, r) - if (ints.isEmpty()) { - drawer.stroke = ColorRGBa.GREEN - drawer.contour(r) - } else { - drawer.stroke = ColorRGBa.WHITE - 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 sub = r.sub(it.first, end) - val length = sub.length - val ta = sub.tForLength(2.0) - val tb = sub.tForLength(length - 2.0) - drawer.contour(sub.sub(ta, tb)) - } + val ints = intersections(circle, r) + if (ints.isEmpty()) { + drawer.stroke = ColorRGBa.GREEN + drawer.contour(r) + } else { + drawer.stroke = ColorRGBa.WHITE + 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 sub = r.sub(it.first, end) + val length = sub.length + val ta = sub.tForLength(2.0) + val tb = sub.tForLength(length - 2.0) + drawer.contour(sub.sub(ta, tb)) } } } @@ -39,4 +41,4 @@ fun main() { } } } -} \ No newline at end of file +} diff --git a/openrndr-demos/src/demo/kotlin/DemoContourIntersections03.kt b/openrndr-demos/src/demo/kotlin/DemoContourIntersections03.kt index ff1260e0..3ed66230 100644 --- a/openrndr-demos/src/demo/kotlin/DemoContourIntersections03.kt +++ b/openrndr-demos/src/demo/kotlin/DemoContourIntersections03.kt @@ -12,12 +12,12 @@ fun main() = application { val points = 200 extend { val contour = ShapeContour.fromPoints( - List(points) { - val a = PI * 2 * it / points - val x = (200 + 50 * cos(a * 2)) * sin(a * 3 + sin(a)) - val y = 150 * cos(a * 2 + seconds * 0.2) - Vector2(x, y) - }, closed = true + List(points) { + val a = PI * 2 * it / points + val x = (200 + 50 * cos(a * 2)) * sin(a * 3 + sin(a)) + val y = 150 * cos(a * 2 + seconds * 0.2) + Vector2(x, y) + }, closed = true ) val ints = intersections(contour, contour) drawer.run { diff --git a/openrndr-demos/src/demo/kotlin/DemoCubemap01.kt b/openrndr-demos/src/demo/kotlin/DemoCubemap01.kt index fd052c05..dddef7b7 100644 --- a/openrndr-demos/src/demo/kotlin/DemoCubemap01.kt +++ b/openrndr-demos/src/demo/kotlin/DemoCubemap01.kt @@ -1,16 +1,17 @@ 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.meshgenerators.boxMesh fun main() = application { program { - val cubemap = loadCubemap("demo-data/cubemaps/garage_iem.dds", null, session = Session.active) val cube = boxMesh() - extend(Orbital()) { - } + extend(Orbital()) extend { drawer.shadeStyle = shadeStyle { fragmentTransform = """ diff --git a/openrndr-demos/src/demo/kotlin/DemoCubemap02.kt b/openrndr-demos/src/demo/kotlin/DemoCubemap02.kt index f3cb0972..6850ceb4 100644 --- a/openrndr-demos/src/demo/kotlin/DemoCubemap02.kt +++ b/openrndr-demos/src/demo/kotlin/DemoCubemap02.kt @@ -7,13 +7,17 @@ fun main() = application { program { val cubemap1 = loadCubemap("demo-data/cubemaps/garage_iem.dds", null, session = Session.active) 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) cubemap2.generateMipmaps() - extend(Orbital()) { - - } + extend(Orbital()) extend { drawer.shadeStyle = shadeStyle { fragmentTransform = """ diff --git a/openrndr-demos/src/demo/kotlin/DemoCubemap03.kt b/openrndr-demos/src/demo/kotlin/DemoCubemap03.kt index 8b0027c5..040dd755 100644 --- a/openrndr-demos/src/demo/kotlin/DemoCubemap03.kt +++ b/openrndr-demos/src/demo/kotlin/DemoCubemap03.kt @@ -7,7 +7,13 @@ fun main() = application { program { val cubemap1 = loadCubemap("demo-data/cubemaps/garage_iem.dds", null, session = Session.active) 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) cubemap2.generateMipmaps() @@ -18,9 +24,7 @@ fun main() = application { cma.generateMipmaps() - extend(Orbital()) { - - } + extend(Orbital()) extend { drawer.shadeStyle = shadeStyle { fragmentTransform = """ diff --git a/openrndr-demos/src/demo/kotlin/DemoDDSImage01.kt b/openrndr-demos/src/demo/kotlin/DemoDDSImage01.kt index d94608d8..aa1e0bc4 100644 --- a/openrndr-demos/src/demo/kotlin/DemoDDSImage01.kt +++ b/openrndr-demos/src/demo/kotlin/DemoDDSImage01.kt @@ -1,15 +1,13 @@ import org.openrndr.application import org.openrndr.draw.loadImage -fun main() { - application { - program { - val image = loadImage("demo-data/images/image-001.dds") - println(image.format) - println(image.type) - extend { - drawer.image(image) - } +fun main() = application { + program { + val image = loadImage("demo-data/images/image-001.dds") + println(image.format) + println(image.type) + extend { + drawer.image(image) } } -} \ No newline at end of file +} diff --git a/openrndr-demos/src/demo/kotlin/DemoGeometryShader01.kt b/openrndr-demos/src/demo/kotlin/DemoGeometryShader01.kt index a11273f3..085bbf1a 100644 --- a/openrndr-demos/src/demo/kotlin/DemoGeometryShader01.kt +++ b/openrndr-demos/src/demo/kotlin/DemoGeometryShader01.kt @@ -6,27 +6,25 @@ import org.openrndr.extra.camera.Orbital import org.openrndr.extra.meshgenerators.boxMesh import org.openrndr.resourceText -fun main() { - application { - program { - val vb = boxMesh() - val shader = Shader.createFromCode( - vsCode = resourceText("/shaders/gs-01.vert"), - gsCode = resourceText("/shaders/gs-01.geom"), - fsCode = resourceText("/shaders/gs-01.frag"), - name = "x" - ) - extend(Orbital()) - 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) - driver.drawVertexBuffer(shader, listOf(vb), DrawPrimitive.TRIANGLES, 0, vb.vertexCount) - shader.end() - } +fun main() = application { + program { + val vb = boxMesh() + val shader = Shader.createFromCode( + vsCode = resourceText("/shaders/gs-01.vert"), + gsCode = resourceText("/shaders/gs-01.geom"), + fsCode = resourceText("/shaders/gs-01.frag"), + name = "x" + ) + extend(Orbital()) + 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) + driver.drawVertexBuffer(shader, listOf(vb), DrawPrimitive.TRIANGLES, 0, vb.vertexCount) + shader.end() } } -} \ No newline at end of file +} diff --git a/openrndr-demos/src/demo/kotlin/DemoImageLoadStore01.kt b/openrndr-demos/src/demo/kotlin/DemoImageLoadStore01.kt index 8831a91a..71b2ea50 100644 --- a/openrndr-demos/src/demo/kotlin/DemoImageLoadStore01.kt +++ b/openrndr-demos/src/demo/kotlin/DemoImageLoadStore01.kt @@ -5,12 +5,11 @@ import org.openrndr.extra.meshgenerators.planeMesh import org.openrndr.internal.Driver import org.openrndr.math.Vector3 - fun main() = application { program { - - val shader = Shader.createFromCode(vsCode = - """${Driver.instance.shaderConfiguration()} + val shader = Shader.createFromCode( + vsCode = + """${Driver.instance.shaderConfiguration(ShaderType.VERTEX)} in vec3 a_position; in vec2 a_texCoord0; in vec3 a_normal; @@ -21,14 +20,15 @@ void main() { gl_Position = projMatrix * vec4(a_position, 1.0); } """, - fsCode = """${Driver.instance.shaderConfiguration()} + fsCode = """${Driver.instance.shaderConfiguration(ShaderType.FRAGMENT)} out vec4 o_color; layout(rgba8) uniform writeonly image2D bla; void main() { 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 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.image(cb) } - } } \ No newline at end of file diff --git a/openrndr-demos/src/demo/kotlin/DemoImageLoadStore02.kt b/openrndr-demos/src/demo/kotlin/DemoImageLoadStore02.kt index ddbb86a3..f7c798cf 100644 --- a/openrndr-demos/src/demo/kotlin/DemoImageLoadStore02.kt +++ b/openrndr-demos/src/demo/kotlin/DemoImageLoadStore02.kt @@ -2,7 +2,6 @@ import org.openrndr.application import org.openrndr.color.ColorRGBa import org.openrndr.draw.* - fun main() = application { program { val cb = colorBuffer(128, 128, type = ColorType.UINT8) @@ -15,7 +14,6 @@ fun main() = application { image("image", cb.imageBinding(0, ImageAccess.WRITE)) } extend { - drawer.shadeStyle = ss drawer.clear(ColorRGBa.PINK) drawer.rectangle(0.0, 0.0, 100.0, 100.0) diff --git a/openrndr-demos/src/demo/kotlin/DemoImageLoadStore03.kt b/openrndr-demos/src/demo/kotlin/DemoImageLoadStore03.kt index 106918e2..d87f95ed 100644 --- a/openrndr-demos/src/demo/kotlin/DemoImageLoadStore03.kt +++ b/openrndr-demos/src/demo/kotlin/DemoImageLoadStore03.kt @@ -1,13 +1,12 @@ import org.openrndr.application -import org.openrndr.color.ColorRGBa +import org.openrndr.color.rgb import org.openrndr.draw.* - fun main() = application { program { - val cb = colorBuffer(128, 128) - val at = arrayTexture(128, 128, 32) - val vt = volumeTexture(32, 32, 32) + val cb = colorBuffer(128, 128, type = ColorType.UINT8) + val at = arrayTexture(128, 128, 32, type = ColorType.UINT8) + val vt = volumeTexture(32, 32, 32, type = ColorType.UINT8) extend { val ss = shadeStyle { fragmentTransform = """ @@ -16,12 +15,13 @@ fun main() = application { imageStore(p_at, ivec3(2, 2, 2), vec4(1.0, 0.0, 0.0, 1.0)); """.trimIndent() - parameter("at", at.imageBinding(0, ImageAccess.READ_WRITE)) - parameter("image", cb.imageBinding(0, ImageAccess.READ_WRITE)) - parameter("vt", vt.imageBinding(0, ImageAccess.READ_WRITE)) + image("at", at.imageBinding(0, ImageAccess.READ_WRITE)) + image("image", cb.imageBinding(0, ImageAccess.READ_WRITE)) + image("vt", vt.imageBinding(0, ImageAccess.READ_WRITE)) } 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.image(cb, 0.0, 200.0) } diff --git a/openrndr-demos/src/demo/kotlin/DemoLineCapJoin.kt b/openrndr-demos/src/demo/kotlin/DemoLineCapJoin.kt index 8141a882..844b202b 100644 --- a/openrndr-demos/src/demo/kotlin/DemoLineCapJoin.kt +++ b/openrndr-demos/src/demo/kotlin/DemoLineCapJoin.kt @@ -33,9 +33,9 @@ fun main() { stroke = ColorRGBa.PINK strokeWeight = 8.0 fontMap = font - LineCap.values().forEachIndexed { x, cap -> + LineCap.entries.forEachIndexed { x, cap -> lineCap = cap - LineJoin.values().forEachIndexed { y, join -> + LineJoin.entries.forEachIndexed { y, join -> lineJoin = join val pos = IntVector2(x - 1, y - 1).vector2 * 180.0 isolated { diff --git a/openrndr-demos/src/demo/kotlin/DemoLineDash01.kt b/openrndr-demos/src/demo/kotlin/DemoLineDash01.kt index b7d56e2b..6bfd56c0 100644 --- a/openrndr-demos/src/demo/kotlin/DemoLineDash01.kt +++ b/openrndr-demos/src/demo/kotlin/DemoLineDash01.kt @@ -8,7 +8,8 @@ fun main() = application { program { val style = shadeStyle { //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) } extend { @@ -25,8 +26,7 @@ fun main() = application { shadeStyle = style 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) } } } diff --git a/openrndr-demos/src/demo/kotlin/DemoScreenCapture01.kt b/openrndr-demos/src/demo/kotlin/DemoScreenCapture01.kt index 3cae667b..7cc6ba8e 100644 --- a/openrndr-demos/src/demo/kotlin/DemoScreenCapture01.kt +++ b/openrndr-demos/src/demo/kotlin/DemoScreenCapture01.kt @@ -8,36 +8,34 @@ import org.openrndr.extra.meshgenerators.boxMesh import org.openrndr.ffmpeg.VideoPlayerFFMPEG import org.openrndr.math.Vector3 -fun main() { - application { - program { - val cube = boxMesh() - val screen = VideoPlayerFFMPEG.fromScreen( - frameRate = 15.0, - imageWidth = 300, - imageHeight = 300 - ) +fun main() = application { + program { + val cube = boxMesh() + val screen = VideoPlayerFFMPEG.fromScreen( + frameRate = 15.0, + imageWidth = 300, + imageHeight = 300 + ) - screen.play() - extend { - screen.draw(drawer, true) // update the screen grabber - drawer.isolated { - clear(ColorRGBa.WHITE) - perspective(60.0, width * 1.0 / height, 0.01, 1000.0) - depthWrite = true - depthTestPass = DepthTestPass.LESS_OR_EQUAL - shadeStyle = shadeStyle { - fragmentTransform = "x_fill = texture(p_tex, vec2(1.0-va_texCoord0.x, va_texCoord0.y));" - screen.colorBuffer?.run { - parameter("tex", this) - } + screen.play() + extend { + screen.draw(drawer, true) // update the screen grabber + drawer.isolated { + clear(ColorRGBa.WHITE) + perspective(60.0, width * 1.0 / height, 0.01, 1000.0) + depthWrite = true + depthTestPass = DepthTestPass.LESS_OR_EQUAL + shadeStyle = shadeStyle { + fragmentTransform = "x_fill = texture(p_tex, vec2(1.0-va_texCoord0.x, va_texCoord0.y));" + screen.colorBuffer?.run { + 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) } } } diff --git a/openrndr-demos/src/demo/kotlin/DemoShaderStorageBuffer01.kt b/openrndr-demos/src/demo/kotlin/DemoShaderStorageBuffer01.kt index f880592f..085037d9 100644 --- a/openrndr-demos/src/demo/kotlin/DemoShaderStorageBuffer01.kt +++ b/openrndr-demos/src/demo/kotlin/DemoShaderStorageBuffer01.kt @@ -1,5 +1,8 @@ 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.ByteOrder @@ -46,6 +49,5 @@ fun main() = application { // Therefore the value of `f1` can vary from frame to frame, // because we don't know how many times `+= 2.0` was executed. } - } } \ No newline at end of file diff --git a/openrndr-demos/src/demo/kotlin/DemoTessShader01.kt b/openrndr-demos/src/demo/kotlin/DemoTessShader01.kt index e059d30e..8d07b9cc 100644 --- a/openrndr-demos/src/demo/kotlin/DemoTessShader01.kt +++ b/openrndr-demos/src/demo/kotlin/DemoTessShader01.kt @@ -7,46 +7,44 @@ import org.openrndr.draw.vertexFormat import org.openrndr.math.Vector3 import org.openrndr.resourceText -fun main() { - application { - program { - val vb = vertexBuffer(vertexFormat { - position(3) - }, 12) - val shader = Shader.Companion.createFromCode( - vsCode = resourceText("/shaders/ts-01.vert"), - tcsCode = resourceText("/shaders/ts-01.tesc"), - tesCode = resourceText("/shaders/ts-01.tese"), - fsCode = resourceText("/shaders/ts-01.frag"), - name = "x" - ) +fun main() = application { + program { + val vb = vertexBuffer(vertexFormat { + position(3) + }, 12) + val shader = Shader.Companion.createFromCode( + vsCode = resourceText("/shaders/ts-01.vert"), + tcsCode = resourceText("/shaders/ts-01.tesc"), + tesCode = resourceText("/shaders/ts-01.tese"), + fsCode = resourceText("/shaders/ts-01.frag"), + name = "x" + ) - vb.put { - write(Vector3(0.0, 0.0, 0.0)) - write(Vector3(100.0, 0.0, 0.0)) - write(Vector3(140.0, 200.0, 0.0)) - write(Vector3(200.0, 300.0, 0.0)) - write(Vector3(0.0, 0.0, 0.0)) - write(Vector3(100.0, 0.0, 0.0)) - write(Vector3(140.0, 200.0, 0.0)) - write(Vector3(200.0, 400.0, 0.0)) - write(Vector3(0.0, 0.0, 0.0)) - write(Vector3(100.0, 0.0, 0.0)) - write(Vector3(140.0, 200.0, 0.0)) - write(Vector3(200.0, 500.0, 0.0)) - } + vb.put { + write(Vector3(0.0, 0.0, 0.0)) + write(Vector3(100.0, 0.0, 0.0)) + write(Vector3(140.0, 200.0, 0.0)) + write(Vector3(200.0, 300.0, 0.0)) + write(Vector3(0.0, 0.0, 0.0)) + write(Vector3(100.0, 0.0, 0.0)) + write(Vector3(140.0, 200.0, 0.0)) + write(Vector3(200.0, 400.0, 0.0)) + write(Vector3(0.0, 0.0, 0.0)) + write(Vector3(100.0, 0.0, 0.0)) + write(Vector3(140.0, 200.0, 0.0)) + write(Vector3(200.0, 500.0, 0.0)) + } - 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) - driver.drawVertexBuffer(shader, listOf(vb), DrawPrimitive.PATCHES, 0, vb.vertexCount) + 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) + driver.drawVertexBuffer(shader, listOf(vb), DrawPrimitive.PATCHES, 0, vb.vertexCount) - shader.end() - } + shader.end() } } -} \ No newline at end of file +} diff --git a/openrndr-demos/src/demo/kotlin/DemoTessShader02.kt b/openrndr-demos/src/demo/kotlin/DemoTessShader02.kt index 6417b568..b7af7a45 100644 --- a/openrndr-demos/src/demo/kotlin/DemoTessShader02.kt +++ b/openrndr-demos/src/demo/kotlin/DemoTessShader02.kt @@ -7,45 +7,43 @@ import org.openrndr.draw.vertexFormat import org.openrndr.resourceText import org.openrndr.shape.Ellipse -fun main() { - application { - program { - val ellipse = Ellipse(width/2.0, height/2.0, 100.0, 300.0).contour +fun main() = application { + program { + val ellipse = Ellipse(width / 2.0, height / 2.0, 100.0, 300.0).contour - val vb = vertexBuffer(vertexFormat { - position(3) - }, ellipse.segments.size * 4) + val vb = vertexBuffer(vertexFormat { + position(3) + }, ellipse.segments.size * 4) - val shader = Shader.createFromCode( - vsCode = resourceText("/shaders/ts-02.vert"), - tcsCode = resourceText("/shaders/ts-02.tesc"), - tesCode = resourceText("/shaders/ts-02.tese"), - gsCode = resourceText("/shaders/ts-02.geom"), - fsCode = resourceText("/shaders/ts-02.frag"), - name = "x" - ) + val shader = Shader.createFromCode( + vsCode = resourceText("/shaders/ts-02.vert"), + tcsCode = resourceText("/shaders/ts-02.tesc"), + tesCode = resourceText("/shaders/ts-02.tese"), + gsCode = resourceText("/shaders/ts-02.geom"), + fsCode = resourceText("/shaders/ts-02.frag"), + name = "x" + ) - vb.put { - for (segment in ellipse.segments) { - val cubic = segment.cubic - write(cubic.start.xy0) - write(cubic.control[0].xy0) - write(cubic.control[1].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() + vb.put { + for (segment in ellipse.segments) { + val cubic = segment.cubic + write(cubic.start.xy0) + write(cubic.control[0].xy0) + write(cubic.control[1].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() + } } -} \ No newline at end of file +} diff --git a/openrndr-demos/src/demo/kotlin/DemoTessShader03.kt b/openrndr-demos/src/demo/kotlin/DemoTessShader03.kt index 2de5a999..035efa7e 100644 --- a/openrndr-demos/src/demo/kotlin/DemoTessShader03.kt +++ b/openrndr-demos/src/demo/kotlin/DemoTessShader03.kt @@ -7,51 +7,49 @@ import org.openrndr.draw.vertexFormat import org.openrndr.resourceText import org.openrndr.shape.Ellipse -fun main() { - application { - program { +fun main() = application { + 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 { - position(3) - }, ellipse.segments.size * 4) + val vb = vertexBuffer(vertexFormat { + position(3) + }, ellipse.segments.size * 4) - val shader = Shader.createFromCode( - vsCode = resourceText("/shaders/ts-03.vert"), - tcsCode = resourceText("/shaders/ts-03.tesc"), - tesCode = resourceText("/shaders/ts-03.tese"), - gsCode = resourceText("/shaders/ts-03.geom"), - fsCode = resourceText("/shaders/ts-03.frag"), - name = "x" - ) + val shader = Shader.createFromCode( + vsCode = resourceText("/shaders/ts-03.vert"), + tcsCode = resourceText("/shaders/ts-03.tesc"), + tesCode = resourceText("/shaders/ts-03.tese"), + gsCode = resourceText("/shaders/ts-03.geom"), + fsCode = resourceText("/shaders/ts-03.frag"), + name = "x" + ) - vb.put { - for (segment in ellipse.segments) { - val cubic = segment.cubic - write(cubic.start.xy0) - write(cubic.control[0].xy0) - write(cubic.control[1].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() + vb.put { + for (segment in ellipse.segments) { + val cubic = segment.cubic + write(cubic.start.xy0) + write(cubic.control[0].xy0) + write(cubic.control[1].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() + } } -} \ No newline at end of file +} diff --git a/openrndr-demos/src/demo/kotlin/DemoTessShader04.kt b/openrndr-demos/src/demo/kotlin/DemoTessShader04.kt index b3e54530..aefd0ce3 100644 --- a/openrndr-demos/src/demo/kotlin/DemoTessShader04.kt +++ b/openrndr-demos/src/demo/kotlin/DemoTessShader04.kt @@ -1,73 +1,67 @@ import org.openrndr.application import org.openrndr.color.ColorRGBa 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.OrbitalCamera 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.resourceUrl -import org.openrndr.shape.Ellipse import org.openrndr.shape.path3D - -import org.openrndr.extra.shaderphrases.preprocessedFromUrls import kotlin.math.cos -fun main() { - application { - program { - extend(Orbital()) +fun main() = application { + program { + extend(Orbital()) - val path = path3D { - moveTo(Vector3.ZERO) - for (i in 0 until 100) { - 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 path = path3D { + moveTo(Vector3.ZERO) + for (i in 0 until 100) { + 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 + } } -} \ No newline at end of file +} diff --git a/openrndr-demos/src/demo/kotlin/DemoVolumeTexture01.kt b/openrndr-demos/src/demo/kotlin/DemoVolumeTexture01.kt index fb28ef52..80acb087 100644 --- a/openrndr-demos/src/demo/kotlin/DemoVolumeTexture01.kt +++ b/openrndr-demos/src/demo/kotlin/DemoVolumeTexture01.kt @@ -4,7 +4,7 @@ import org.openrndr.draw.* fun main() = application { 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) { volumeTexture(volumeTexture, 0) } diff --git a/openrndr-demos/src/demo/kotlin/DrawerNegativeDimensions.kt b/openrndr-demos/src/demo/kotlin/DrawerNegativeDimensions.kt index 74cbc816..97cec56c 100644 --- a/openrndr-demos/src/demo/kotlin/DrawerNegativeDimensions.kt +++ b/openrndr-demos/src/demo/kotlin/DrawerNegativeDimensions.kt @@ -31,9 +31,11 @@ fun main() = application { // Rectangles with the bottom right corner centered in the window drawer.rectangles(List(10) { - Rectangle(drawer.bounds.center, - -squareSize * 2 + it * 10, - -squareSize * 2 + it * 10) + Rectangle( + drawer.bounds.center, + -squareSize * 2 + it * 10, + -squareSize * 2 + it * 10 + ) }) } } diff --git a/openrndr-demos/src/demo/kotlin/DrawerRectangleBatch03.kt b/openrndr-demos/src/demo/kotlin/DrawerRectangleBatch03.kt index e88db2c3..11819dc6 100644 --- a/openrndr-demos/src/demo/kotlin/DrawerRectangleBatch03.kt +++ b/openrndr-demos/src/demo/kotlin/DrawerRectangleBatch03.kt @@ -11,10 +11,9 @@ fun main() = application { drawer.stroke = ColorRGBa.WHITE drawer.strokeWeight = 2.0 drawer.rectangles { - for (y in 0 until height/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) - + for (y in 0 until height / 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) } } } diff --git a/orx-color/README.md b/orx-color/README.md index 7996ff71..8fcf758d 100644 --- a/orx-color/README.md +++ b/orx-color/README.md @@ -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) ## 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 [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) -### 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 [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) -### 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 [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) -### 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 [source code](src/jvmDemo/kotlin/DemoXSLUV01.kt) ![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) diff --git a/orx-color/src/jvmDemo/kotlin/DemoColorPalette01.kt b/orx-color/src/jvmDemo/kotlin/DemoColorPalette01.kt index 1d2ed406..15e31526 100644 --- a/orx-color/src/jvmDemo/kotlin/DemoColorPalette01.kt +++ b/orx-color/src/jvmDemo/kotlin/DemoColorPalette01.kt @@ -11,7 +11,10 @@ import org.openrndr.extra.color.spaces.* * Demonstrates the creation of color palettes using various available methods */ fun main() = application { - configure { } + configure { + width = 720 + height = 540 + } program { // HueShiftableColor: // HPLuv HSL HSV LCHab LCHuv XSL XSV XSLuv HSLuv OKHSL OKHSV OKLCH @@ -27,34 +30,33 @@ fun main() = application { palette0.forEachIndexed { i, 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 -> 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 -> 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 -> 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 -> 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 -> 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) } - } } } \ No newline at end of file diff --git a/orx-color/src/jvmDemo/kotlin/DemoColorPalette02.kt b/orx-color/src/jvmDemo/kotlin/DemoColorPalette02.kt index 6660ada5..5924948e 100644 --- a/orx-color/src/jvmDemo/kotlin/DemoColorPalette02.kt +++ b/orx-color/src/jvmDemo/kotlin/DemoColorPalette02.kt @@ -11,6 +11,10 @@ import org.openrndr.extra.color.tools.shadeLuminosity * an increased dynamic range. */ fun main() = application { + configure { + width = 720 + height = 360 + } program { val count = 8 val palette = RGB.PINK.analogous(360.0, count).mapIndexed { i, c -> diff --git a/orx-color/src/jvmDemo/kotlin/DemoColorPlane01.kt b/orx-color/src/jvmDemo/kotlin/DemoColorPlane01.kt index e7930a34..0659d31e 100644 --- a/orx-color/src/jvmDemo/kotlin/DemoColorPlane01.kt +++ b/orx-color/src/jvmDemo/kotlin/DemoColorPlane01.kt @@ -7,80 +7,75 @@ import org.openrndr.extra.meshgenerators.sphereMesh import org.openrndr.math.Vector3 import kotlin.math.cos -fun main() { - application { - configure { - width = 800 - height = 800 +fun main() = application { + configure { + width = 720 + height = 720 + } + program { + val mesh = sphereMesh(8, 8, radius = 0.1) - } - program { - val mesh = sphereMesh(8, 8, radius = 0.1) + val instanceData = vertexBuffer( + vertexFormat { + attribute("instanceColor", VertexElementType.VECTOR4_FLOAT32) + attribute("instancePosition", VertexElementType.VECTOR3_FLOAT32) + }, + 90 * 100 + ) + println(extensions.size) + extend(Orbital()) - val instanceData = vertexBuffer( - vertexFormat { - attribute("instanceColor", VertexElementType.VECTOR4_FLOAT32) - attribute("instancePosition", VertexElementType.VECTOR3_FLOAT32) - }, - 90 * 100 - ) - println(extensions.size) - extend(Orbital()) + extend { + drawer.clear(ColorRGBa.WHITE) + drawer.stroke = null + drawer.fontMap = loadFont("demo-data/fonts/IBMPlexMono-Regular.ttf", 16.0) - extend { - drawer.clear(ColorRGBa.WHITE) - - drawer.stroke = null - - drawer.fontMap = loadFont("demo-data/fonts/IBMPlexMono-Regular.ttf", 16.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)) - } + 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; """.trimIndent() - fragmentTransform = """ + fragmentTransform = """ x_fill = vi_instanceColor; """.trimIndent() - } - - 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.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), + + ) + ) } } -} \ No newline at end of file +} diff --git a/orx-color/src/jvmDemo/kotlin/DemoColorPlane02.kt b/orx-color/src/jvmDemo/kotlin/DemoColorPlane02.kt index d3a8c941..27212b0a 100644 --- a/orx-color/src/jvmDemo/kotlin/DemoColorPlane02.kt +++ b/orx-color/src/jvmDemo/kotlin/DemoColorPlane02.kt @@ -7,73 +7,71 @@ import org.openrndr.extra.meshgenerators.sphereMesh import org.openrndr.math.Vector3 import kotlin.math.cos -fun main() { - application { - configure { - width = 800 - height = 800 - } - program { - val mesh = sphereMesh(8, 8, radius = 0.1) +fun main() = application { + configure { + width = 720 + height = 720 + } + program { + val mesh = sphereMesh(8, 8, radius = 0.1) - val instanceData = vertexBuffer( - vertexFormat { - attribute("instanceColor", VertexElementType.VECTOR4_FLOAT32) - attribute("instancePosition", VertexElementType.VECTOR3_FLOAT32) - }, - 100 * 100 - ) - extend(Orbital()) - extend { - drawer.clear(ColorRGBa.WHITE) + val instanceData = vertexBuffer( + vertexFormat { + attribute("instanceColor", VertexElementType.VECTOR4_FLOAT32) + attribute("instancePosition", VertexElementType.VECTOR3_FLOAT32) + }, + 100 * 100 + ) + extend(Orbital()) + extend { + 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 { - for (lumo 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 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)) - } + instanceData.put { + for (lumo 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 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 { - vertexTransform = """ + } + drawer.isolated { + drawer.shadeStyle = shadeStyle { + vertexTransform = """ x_position += i_instancePosition; """.trimIndent() - fragmentTransform = """ + fragmentTransform = """ x_fill = vi_instanceColor; """.trimIndent() - } - 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.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), + ) + ) } } -} \ No newline at end of file +} diff --git a/orx-color/src/jvmDemo/kotlin/DemoColorRange03.kt b/orx-color/src/jvmDemo/kotlin/DemoColorRange03.kt deleted file mode 100644 index f6c9e715..00000000 --- a/orx-color/src/jvmDemo/kotlin/DemoColorRange03.kt +++ /dev/null @@ -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) - } - } - } - } -} \ No newline at end of file diff --git a/orx-color/src/jvmDemo/kotlin/DemoColorRange04.kt b/orx-color/src/jvmDemo/kotlin/DemoColorRange04.kt deleted file mode 100644 index b3ad3e1e..00000000 --- a/orx-color/src/jvmDemo/kotlin/DemoColorRange04.kt +++ /dev/null @@ -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), - ) - ) - } - } - } -} \ No newline at end of file diff --git a/orx-color/src/jvmDemo/kotlin/DemoColorSequence01.kt b/orx-color/src/jvmDemo/kotlin/DemoColorSequence01.kt index 26c268a0..d564e09b 100644 --- a/orx-color/src/jvmDemo/kotlin/DemoColorSequence01.kt +++ b/orx-color/src/jvmDemo/kotlin/DemoColorSequence01.kt @@ -24,48 +24,46 @@ import org.openrndr.math.Vector3 * - 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. */ -fun main() { - application { - configure { - width = 720 - height = 720 - } - program { - val cs = ColorSequence( - listOf( - 0.0 to ColorRGBa.PINK, - 0.25 to ColorRGBa.ORANGE.toOKLABa(), - 0.27 to ColorRGBa.WHITE.toOKLABa(), - 0.32 to ColorRGBa.BLUE, - 1.0 to ColorRGBa.MEDIUM_AQUAMARINE - ) +fun main() = application { + configure { + width = 720 + height = 720 + } + program { + val cs = ColorSequence( + listOf( + 0.0 to ColorRGBa.PINK, + 0.25 to ColorRGBa.ORANGE.toOKLABa(), + 0.27 to ColorRGBa.WHITE.toOKLABa(), + 0.32 to ColorRGBa.BLUE, + 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()) { - fov = 50.0 - eye = Vector3(0.0, 0.0, 13.0) - } - extend { - drawer.shadeStyle = shadeStyle { - fragmentTransform = """ + extend(Orbital()) { + fov = 50.0 + eye = Vector3(0.0, 0.0, 13.0) + } + extend { + drawer.shadeStyle = shadeStyle { + fragmentTransform = """ float d = normalize(va_normal).z; x_fill = texture(p_palette, vec2(1.0-d, 0.0)); """.trimIndent() - parameter("palette", palette) - } - for (j in -2..2) { - for (i in -2..2) { - drawer.isolated { - drawer.translate(i * 2.0, j * 2.0, 0.0) - drawer.rotate(Vector3.UNIT_Y, j * 30.0) - drawer.rotate(Vector3.UNIT_X, i * 30.0) - drawer.vertexBuffer(sphere, DrawPrimitive.TRIANGLES) - } + parameter("palette", palette) + } + for (j in -2..2) { + for (i in -2..2) { + drawer.isolated { + drawer.translate(i * 2.0, j * 2.0, 0.0) + drawer.rotate(Vector3.UNIT_Y, j * 30.0) + drawer.rotate(Vector3.UNIT_X, i * 30.0) + drawer.vertexBuffer(sphere, DrawPrimitive.TRIANGLES) } } } } } -} \ No newline at end of file +} diff --git a/orx-color/src/jvmDemo/kotlin/DemoDeltaE.kt b/orx-color/src/jvmDemo/kotlin/DemoDeltaE.kt index f2bee108..784cf1b9 100644 --- a/orx-color/src/jvmDemo/kotlin/DemoDeltaE.kt +++ b/orx-color/src/jvmDemo/kotlin/DemoDeltaE.kt @@ -4,36 +4,34 @@ import org.openrndr.extra.color.spaces.toOKHSVa import org.openrndr.extra.color.statistics.deltaE76 import org.openrndr.math.Polar -fun main() { - application { - configure { - width = 720 - height = 720 - } - program { - extend { - drawer.clear(ColorRGBa.BLACK) - drawer.fill = null - drawer.stroke = ColorRGBa.WHITE.opacify(0.2) - for (i in 10 until 270 step 10) { - drawer.circle(drawer.bounds.center, i.toDouble()) - } +fun main() = application { + configure { + width = 720 + height = 720 + } + program { + extend { + drawer.clear(ColorRGBa.BLACK) + drawer.fill = null + drawer.stroke = ColorRGBa.WHITE.opacify(0.2) + for (i in 10 until 270 step 10) { + drawer.circle(drawer.bounds.center, i.toDouble()) + } - drawer.stroke = null + drawer.stroke = null - val startColor = ColorRGBa.RED.toOKHSVa().shiftHue(seconds*36.0).toRGBa() - drawer.circles { - for (j in 99 downTo 0) { - for (i in 0 until 360 step 10) { - val color = startColor.toOKHSVa().shiftHue(i.toDouble()).saturate(j / 99.0).toRGBa() - val distance = color.deltaE76(startColor) - val p = Polar(seconds * 36.0 + i.toDouble(), distance).cartesian + drawer.bounds.center - fill = color - circle(p, 2.0) - } + val startColor = ColorRGBa.RED.toOKHSVa().shiftHue(seconds * 36.0).toRGBa() + drawer.circles { + for (j in 99 downTo 0) { + for (i in 0 until 360 step 10) { + val color = startColor.toOKHSVa().shiftHue(i.toDouble()).saturate(j / 99.0).toRGBa() + val distance = color.deltaE76(startColor) + val p = Polar(seconds * 36.0 + i.toDouble(), distance).cartesian + drawer.bounds.center + fill = color + circle(p, 2.0) } } } } } -} \ No newline at end of file +} diff --git a/orx-color/src/jvmDemo/kotlin/DemoFettePalette01.kt b/orx-color/src/jvmDemo/kotlin/DemoFettePalette01.kt index 7c08f44a..45ffda96 100644 --- a/orx-color/src/jvmDemo/kotlin/DemoFettePalette01.kt +++ b/orx-color/src/jvmDemo/kotlin/DemoFettePalette01.kt @@ -6,81 +6,79 @@ import org.openrndr.extra.color.fettepalette.generateColorRamp import org.openrndr.math.Vector2 import kotlin.random.Random -fun main() { - application { - configure { - width = 720 - height = 720 - } +fun main() = application { + configure { + width = 720 + height = 720 + } - program { - 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) - } - } + program { + 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 { - 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) - } - } + drawer.fill = ramp.baseColors.random(random).toRGBa() + drawer.stroke = null + drawer.rectangle(position, width, width) - val random = Random(seconds.toInt()) - rampSquare(ramp, random, Vector2(180.0, 180.0), 360.0) + 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.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) } } -} \ No newline at end of file +} diff --git a/orx-color/src/jvmDemo/kotlin/DemoFettePalette02.kt b/orx-color/src/jvmDemo/kotlin/DemoFettePalette02.kt index e5d15891..f1287eba 100644 --- a/orx-color/src/jvmDemo/kotlin/DemoFettePalette02.kt +++ b/orx-color/src/jvmDemo/kotlin/DemoFettePalette02.kt @@ -8,70 +8,68 @@ import org.openrndr.extra.gui.addTo import org.openrndr.math.Vector2 import kotlin.random.Random -fun main() { - application { - configure { - width = 720 - height = 720 - } +fun main() = application { + configure { + width = 720 + height = 720 + } - program { - val gui = GUI() - val parameters = ColorRampParameters() - 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) + program { + val gui = GUI() + val parameters = ColorRampParameters() + parameters.addTo(gui) + extend(gui) + extend { + val ramp = generateColorRamp(parameters) + fun rampSquare(ramp: ColorRamp, random: Random, position: Vector2, width: Double) { 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) - } - } + drawer.fill = ramp.baseColors.random(random).toRGBa() + drawer.stroke = null + drawer.rectangle(position, width, width) - val random = Random(seconds.toInt()) - rampSquare(ramp, random, Vector2(20.0, 180.0), 360.0) + 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) + + 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) } } -} \ No newline at end of file +} diff --git a/orx-color/src/jvmDemo/kotlin/DemoHSLUV01.kt b/orx-color/src/jvmDemo/kotlin/DemoHSLUV01.kt index 6e6f7eb3..53a54873 100644 --- a/orx-color/src/jvmDemo/kotlin/DemoHSLUV01.kt +++ b/orx-color/src/jvmDemo/kotlin/DemoHSLUV01.kt @@ -10,37 +10,41 @@ import org.openrndr.extra.color.spaces.ColorHSLUVa import org.openrndr.math.Vector2 import org.openrndr.shape.Rectangle -fun main() { - application { - program { - val font = loadFont("demo-data/fonts/IBMPlexMono-Regular.ttf", 26.0) - extend { - drawer.stroke = null - drawer.clear(rgb(0.3)) - val s = mouse.position.x / width - val l = mouse.position.y / height - for (a in 0 until 360 step 12) { - val pos = Vector2(0.0, 110.0) - drawer.isolated { - translate(bounds.center) - rotate(a * 1.0) +fun main() = application { + configure { + width = 720 + height = 540 + } + program { + val font = loadFont("demo-data/fonts/IBMPlexMono-Regular.ttf", 26.0) + extend { + drawer.stroke = null + drawer.clear(rgb(0.3)) + val s = mouse.position.x / width + val l = mouse.position.y / height + for (a in 0 until 360 step 12) { + 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() - rectangle(Rectangle(pos * 1.2, 40.0, 300.0)) + fill = ColorHSLUVa(a * 1.0, s, l).toRGBa().toSRGB() + rectangle(Rectangle(pos * 1.2, 40.0, 300.0)) - fill = ColorHSLa(a * 1.0, s, l).toRGBa() - rectangle(Rectangle.fromCenter(pos, 30.0, 60.0)) - } + fill = ColorHSLa(a * 1.0, s, l).toRGBa() + rectangle(Rectangle.fromCenter(pos, 30.0, 60.0)) } - drawer.fontMap = font - drawer.fill = if(l > 0.8) ColorRGBa.BLACK else ColorRGBa.WHITE - drawer.text("HSLa", width * 0.48, height * 0.73) - drawer.text("HSLUVa", width * 0.8, height * 0.52) - drawer.text("hue: 0 to 360, " + + } + drawer.fontMap = font + drawer.fill = if (l > 0.8) ColorRGBa.BLACK else ColorRGBa.WHITE + drawer.text("HSLa", width * 0.48, height * 0.73) + drawer.text("HSLUVa", width * 0.8, height * 0.52) + drawer.text( + "hue: 0 to 360, " + "saturation: ${String.format("%.02f", s)}, " + "lightness: ${String.format("%.02f", l)}", - 30.0, 460.0) - } + 30.0, height - 30.0 + ) } } -} \ No newline at end of file +} diff --git a/orx-color/src/jvmDemo/kotlin/DemoHSLUV02.kt b/orx-color/src/jvmDemo/kotlin/DemoHSLUV02.kt index f42108cc..140d37d3 100644 --- a/orx-color/src/jvmDemo/kotlin/DemoHSLUV02.kt +++ b/orx-color/src/jvmDemo/kotlin/DemoHSLUV02.kt @@ -7,41 +7,40 @@ import org.openrndr.math.Polar import org.openrndr.math.Vector2 import kotlin.math.sqrt -fun main() { - application { - configure { - width = 720 - height = 720 +fun main() = application { + configure { + width = 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) - fun phyllotaxis(count: Int) = sequence { - for (i in 0 until count) { - yield(Polar(Math.toDegrees(i * 1.0), g * i)) - } - } + program { + extend { + drawer.clear(ColorRGBa.GRAY) + val color = ColorRGBa.RED + val hc = color.toHSLUVa() + drawer.stroke = null + drawer.strokeWeight = 0.0 - program { - extend { - drawer.clear(ColorRGBa.GRAY) - val color = ColorRGBa.RED - val hc = color.toHSLUVa() - drawer.stroke = null - drawer.strokeWeight = 0.0 + val count = 400 + val bobRadius = 20.0 - val count = 400 - val bobRadius = 20.0 - - for (i in phyllotaxis(count)) { - val h = i.theta - val s = i.radius / (count * g) - for (l in 9 downTo 0) { - val position = i.cartesian / (count * g) * (width / 2.0 - bobRadius) + Vector2(width / 2.0, height / 2.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) - } + for (i in phyllotaxis(count)) { + val h = i.theta + val s = i.radius / (count * g) + for (l in 9 downTo 0) { + val position = + i.cartesian / (count * g) * (width / 2.0 - bobRadius) + Vector2(width / 2.0, height / 2.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) } } } } -} \ No newline at end of file +} diff --git a/orx-color/src/jvmDemo/kotlin/DemoHueTools01.kt b/orx-color/src/jvmDemo/kotlin/DemoHueTools01.kt index 25f9a6fa..6ed5f060 100644 --- a/orx-color/src/jvmDemo/kotlin/DemoHueTools01.kt +++ b/orx-color/src/jvmDemo/kotlin/DemoHueTools01.kt @@ -5,37 +5,35 @@ import org.openrndr.extra.color.spaces.OKHSV import org.openrndr.extra.color.tools.mixHue import org.openrndr.extra.color.tools.withHue -fun main() { - application { - configure { - width = 800 - height = 800 - } - program { - extend { - val seedColor = ColorRGBa.PINK - val targetHue = seconds*100.0 +fun main() = application { + configure { + width = 720 + height = 720 + } + program { + extend { + val seedColor = ColorRGBa.PINK + val targetHue = seconds * 100.0 - val rows = 10 - val columns = 12 + val rows = 10 + val columns = 12 - val cellWidth = width / columns.toDouble() - val cellHeight = height / rows.toDouble() + val cellWidth = width / columns.toDouble() + val cellHeight = height / rows.toDouble() - drawer.stroke = null - for (j in 0 until 10) { - drawer.isolated { - for (i in 0 until columns) { - drawer.fill = seedColor - .withHue(i * 360.0 / columns) - .mixHue(targetHue, j / (rows.toDouble()-1.0)) - drawer.rectangle(0.0, 0.0, cellWidth, cellHeight) - drawer.translate(cellWidth, 0.0) - } + drawer.stroke = null + for (j in 0 until 10) { + drawer.isolated { + for (i in 0 until columns) { + drawer.fill = seedColor + .withHue(i * 360.0 / columns) + .mixHue(targetHue, j / (rows.toDouble() - 1.0)) + drawer.rectangle(0.0, 0.0, cellWidth, cellHeight) + drawer.translate(cellWidth, 0.0) } - drawer.translate(0.0, cellHeight) } + drawer.translate(0.0, cellHeight) } } } -} \ No newline at end of file +} diff --git a/orx-color/src/jvmDemo/kotlin/DemoMixSpectral01.kt b/orx-color/src/jvmDemo/kotlin/DemoMixSpectral01.kt index 43397fe2..39918a7b 100644 --- a/orx-color/src/jvmDemo/kotlin/DemoMixSpectral01.kt +++ b/orx-color/src/jvmDemo/kotlin/DemoMixSpectral01.kt @@ -3,41 +3,33 @@ import org.openrndr.color.ColorRGBa import org.openrndr.draw.isolated import org.openrndr.extra.color.mixing.mixSpectral 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 -fun main() { - application { - configure { - width = 800 - height = 800 - } - program { +fun main() = application { + configure { + width = 720 + height = 720 + } + program { + extend { + val a = ColorRGBa.BLUE.shiftHue(0.0).saturate(0.3).shadeLuminosity(0.3) + val b = ColorRGBa.BLUE.shiftHue(60.0).saturate(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) { - val p = 3.0 - val a = ColorRGBa.BLUE.shiftHue(j * p) - val b = ColorRGBa.BLUE.shiftHue(j * p + 180.0) + drawer.translate(width / 60.0, 0.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) } } -} \ No newline at end of file +} diff --git a/orx-color/src/jvmDemo/kotlin/DemoOKHSV01.kt b/orx-color/src/jvmDemo/kotlin/DemoOKHSV01.kt index 685c6b95..c2054dcf 100644 --- a/orx-color/src/jvmDemo/kotlin/DemoOKHSV01.kt +++ b/orx-color/src/jvmDemo/kotlin/DemoOKHSV01.kt @@ -1,11 +1,18 @@ import org.openrndr.application import org.openrndr.color.ColorRGBa +import org.openrndr.color.rgb import org.openrndr.extra.color.spaces.ColorOKHSLa import org.openrndr.extra.color.spaces.ColorOKHSVa fun main() = application { + configure { + width = 720 + height = 160 + } program { extend { + drawer.clear(rgb(0.2)) + val c = ColorRGBa.GREEN val okhsv = ColorOKHSVa.fromColorRGBa(c) val hsv = c.toHSVa() diff --git a/orx-color/src/jvmDemo/kotlin/DemoXSLUV01.kt b/orx-color/src/jvmDemo/kotlin/DemoXSLUV01.kt index 2a0ab059..97a19c68 100644 --- a/orx-color/src/jvmDemo/kotlin/DemoXSLUV01.kt +++ b/orx-color/src/jvmDemo/kotlin/DemoXSLUV01.kt @@ -3,15 +3,22 @@ import org.openrndr.application import org.openrndr.color.ColorRGBa import org.openrndr.extra.color.spaces.ColorXSLUVa -import org.openrndr.extra.color.spaces.toHSLUVa import org.openrndr.math.Polar 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) { fun split(offset: Double = 0.0): List { 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 @@ -31,30 +38,22 @@ fun main() { this + flatMap { it.split(it.height) }.split(depth - 1) } - application { - configure { - width = 720 - height = 720 - } + program { + val arcs = (0..4).map { Arc(it * 90.0 - 45.0, 50.0, 90.0, 50.0) }.split(5) - program { - val arcs = (0..4).map { Arc(it * 90.0 - 45.0, 50.0, 90.0, 50.0) }.split(5) - - extend { - drawer.clear(ColorRGBa.GRAY) - val color = ColorRGBa.RED - val hc = color.toHSLUVa() - drawer.stroke = ColorRGBa.BLACK - drawer.strokeWeight = 1.0 - drawer.translate(drawer.bounds.center) - val l = if (System.getProperty("takeScreenshot") == "true") 0.7 else mouse.position.y / height - val s = if (System.getProperty("takeScreenshot") == "true") 1.0 else mouse.position.x / width - 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) - } + extend { + drawer.clear(ColorRGBa.GRAY) + val color = ColorRGBa.RED + drawer.stroke = ColorRGBa.BLACK + drawer.strokeWeight = 1.0 + drawer.translate(drawer.bounds.center) + val l = if (System.getProperty("takeScreenshot") == "true") 0.7 else mouse.position.y / height + val s = if (System.getProperty("takeScreenshot") == "true") 1.0 else mouse.position.x / width + 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) } } } -} \ No newline at end of file +} diff --git a/orx-color/src/jvmDemo/kotlin/DemoColorRange01.kt b/orx-color/src/jvmDemo/kotlin/colorRange/DemoColorRange01.kt similarity index 95% rename from orx-color/src/jvmDemo/kotlin/DemoColorRange01.kt rename to orx-color/src/jvmDemo/kotlin/colorRange/DemoColorRange01.kt index ffd3e2a6..426954b2 100644 --- a/orx-color/src/jvmDemo/kotlin/DemoColorRange01.kt +++ b/orx-color/src/jvmDemo/kotlin/colorRange/DemoColorRange01.kt @@ -1,3 +1,5 @@ +package colorRange + // Comparison of color lists generated by interpolating from // PINK to BLUE in different color models @@ -10,6 +12,10 @@ import org.openrndr.math.map import org.openrndr.shape.Rectangle fun main() = application { + configure { + width = 720 + height = 540 + } program { val numColors = 10 val colorLists = listOf( diff --git a/orx-color/src/jvmDemo/kotlin/DemoColorRange02.kt b/orx-color/src/jvmDemo/kotlin/colorRange/DemoColorRange02.kt similarity index 89% rename from orx-color/src/jvmDemo/kotlin/DemoColorRange02.kt rename to orx-color/src/jvmDemo/kotlin/colorRange/DemoColorRange02.kt index e5cbdb97..003537bf 100644 --- a/orx-color/src/jvmDemo/kotlin/DemoColorRange02.kt +++ b/orx-color/src/jvmDemo/kotlin/colorRange/DemoColorRange02.kt @@ -1,3 +1,5 @@ +package colorRange + // Create a colorSequence with multiple color models import org.openrndr.application @@ -6,6 +8,10 @@ import org.openrndr.extra.color.palettes.colorSequence import org.openrndr.extra.color.spaces.toHSLUVa fun main() = application { + configure { + width = 720 + height = 360 + } program { extend { val cs = colorSequence(0.0 to ColorRGBa.PINK, diff --git a/orx-color/src/jvmDemo/kotlin/colorRange/DemoColorRange03.kt b/orx-color/src/jvmDemo/kotlin/colorRange/DemoColorRange03.kt new file mode 100644 index 00000000..7d52f148 --- /dev/null +++ b/orx-color/src/jvmDemo/kotlin/colorRange/DemoColorRange03.kt @@ -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) + } + } + } +} diff --git a/orx-color/src/jvmDemo/kotlin/colorRange/DemoColorRange04.kt b/orx-color/src/jvmDemo/kotlin/colorRange/DemoColorRange04.kt new file mode 100644 index 00000000..bf2d5721 --- /dev/null +++ b/orx-color/src/jvmDemo/kotlin/colorRange/DemoColorRange04.kt @@ -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), + ) + ) + } + } +} diff --git a/orx-color/src/jvmDemo/kotlin/DemoSpectralZucconiColormap.kt b/orx-color/src/jvmDemo/kotlin/colormap/DemoSpectralZucconiColormap.kt similarity index 89% rename from orx-color/src/jvmDemo/kotlin/DemoSpectralZucconiColormap.kt rename to orx-color/src/jvmDemo/kotlin/colormap/DemoSpectralZucconiColormap.kt index cf2cc372..b1f73f0e 100644 --- a/orx-color/src/jvmDemo/kotlin/DemoSpectralZucconiColormap.kt +++ b/orx-color/src/jvmDemo/kotlin/colormap/DemoSpectralZucconiColormap.kt @@ -1,9 +1,15 @@ +package colormap + import org.openrndr.application import org.openrndr.extra.color.colormaps.spectralZucconi6 import org.openrndr.extra.noise.fastFloor import kotlin.math.sin fun main() = application { + configure { + width = 720 + height = 360 + } program { extend { drawer.stroke = null diff --git a/orx-color/src/jvmDemo/kotlin/DemoSpectralZucconiColormapPhrase.kt b/orx-color/src/jvmDemo/kotlin/colormap/DemoSpectralZucconiColormapPhrase.kt similarity index 75% rename from orx-color/src/jvmDemo/kotlin/DemoSpectralZucconiColormapPhrase.kt rename to orx-color/src/jvmDemo/kotlin/colormap/DemoSpectralZucconiColormapPhrase.kt index df98801e..c69ad15f 100644 --- a/orx-color/src/jvmDemo/kotlin/DemoSpectralZucconiColormapPhrase.kt +++ b/orx-color/src/jvmDemo/kotlin/colormap/DemoSpectralZucconiColormapPhrase.kt @@ -1,9 +1,15 @@ +package colormap + import org.openrndr.application import org.openrndr.draw.shadeStyle import org.openrndr.extra.color.colormaps.ColormapPhraseBook import org.openrndr.extra.shaderphrases.preprocess fun main() = application { + configure { + width = 720 + height = 360 + } program { ColormapPhraseBook.register() val style = shadeStyle { @@ -11,10 +17,8 @@ fun main() = application { fragmentTransform = "x_fill.rgb = spectral_zucconi6(c_boundsPosition.x);" } extend { - drawer.run { - shadeStyle = style - rectangle(bounds) - } + drawer.shadeStyle = style + drawer.rectangle(drawer.bounds) } } } diff --git a/orx-color/src/jvmDemo/kotlin/DemoSpectralZucconiColormapPlot.kt b/orx-color/src/jvmDemo/kotlin/colormap/DemoSpectralZucconiColormapPlot.kt similarity index 83% rename from orx-color/src/jvmDemo/kotlin/DemoSpectralZucconiColormapPlot.kt rename to orx-color/src/jvmDemo/kotlin/colormap/DemoSpectralZucconiColormapPlot.kt index 58d4e145..167aedb4 100644 --- a/orx-color/src/jvmDemo/kotlin/DemoSpectralZucconiColormapPlot.kt +++ b/orx-color/src/jvmDemo/kotlin/colormap/DemoSpectralZucconiColormapPlot.kt @@ -1,3 +1,5 @@ +package colormap + import org.openrndr.application import org.openrndr.color.ColorRGBa import org.openrndr.draw.shadeStyle @@ -7,22 +9,28 @@ import org.openrndr.extra.shaderphrases.preprocess import org.openrndr.math.Vector2 fun main() = application { + configure { + width = 720 + height = 360 + } program { ColormapPhraseBook.register() val backgroundStyle = shadeStyle { fragmentPreamble = "#pragma import colormap.spectral_zucconi6".preprocess() fragmentTransform = "x_fill.rgb = spectral_zucconi6(c_boundsPosition.x);" } + fun getColormapPoints( block: ColorRGBa.() -> Double ) = List(width) { x -> Vector2( - x = x.toDouble(), - y = height.toDouble() - - block(spectralZucconi6(x / width.toDouble())) - * height.toDouble() + x.toDouble(), + height.toDouble() + - block(spectralZucconi6(x / width.toDouble())) + * height.toDouble() ) } + val redPoints = getColormapPoints { r } val greenPoints = getColormapPoints { g } val bluePoints = getColormapPoints { b } diff --git a/orx-color/src/jvmDemo/kotlin/DemoTurboColormap.kt b/orx-color/src/jvmDemo/kotlin/colormap/DemoTurboColormap.kt similarity index 89% rename from orx-color/src/jvmDemo/kotlin/DemoTurboColormap.kt rename to orx-color/src/jvmDemo/kotlin/colormap/DemoTurboColormap.kt index 4417fdd2..b1e2a522 100644 --- a/orx-color/src/jvmDemo/kotlin/DemoTurboColormap.kt +++ b/orx-color/src/jvmDemo/kotlin/colormap/DemoTurboColormap.kt @@ -1,9 +1,15 @@ +package colormap + import org.openrndr.application import org.openrndr.extra.color.colormaps.turboColormap import org.openrndr.extra.noise.fastFloor import kotlin.math.sin fun main() = application { + configure { + width = 720 + height = 360 + } program { extend { drawer.stroke = null diff --git a/orx-color/src/jvmDemo/kotlin/DemoTurboColormapPhrase.kt b/orx-color/src/jvmDemo/kotlin/colormap/DemoTurboColormapPhrase.kt similarity index 75% rename from orx-color/src/jvmDemo/kotlin/DemoTurboColormapPhrase.kt rename to orx-color/src/jvmDemo/kotlin/colormap/DemoTurboColormapPhrase.kt index 44ee5512..3fd886d7 100644 --- a/orx-color/src/jvmDemo/kotlin/DemoTurboColormapPhrase.kt +++ b/orx-color/src/jvmDemo/kotlin/colormap/DemoTurboColormapPhrase.kt @@ -1,9 +1,15 @@ +package colormap + import org.openrndr.application import org.openrndr.draw.shadeStyle import org.openrndr.extra.color.colormaps.ColormapPhraseBook import org.openrndr.extra.shaderphrases.preprocess fun main() = application { + configure { + width = 720 + height = 360 + } program { ColormapPhraseBook.register() val style = shadeStyle { @@ -11,10 +17,8 @@ fun main() = application { fragmentTransform = "x_fill.rgb = turbo_colormap(c_boundsPosition.x);" } extend { - drawer.run { - shadeStyle = style - rectangle(bounds) - } + drawer.shadeStyle = style + drawer.rectangle(drawer.bounds) } } } diff --git a/orx-color/src/jvmDemo/kotlin/DemoTurboColormapPlot.kt b/orx-color/src/jvmDemo/kotlin/colormap/DemoTurboColormapPlot.kt similarity index 94% rename from orx-color/src/jvmDemo/kotlin/DemoTurboColormapPlot.kt rename to orx-color/src/jvmDemo/kotlin/colormap/DemoTurboColormapPlot.kt index 8862573c..01cce346 100644 --- a/orx-color/src/jvmDemo/kotlin/DemoTurboColormapPlot.kt +++ b/orx-color/src/jvmDemo/kotlin/colormap/DemoTurboColormapPlot.kt @@ -1,3 +1,5 @@ +package colormap + import org.openrndr.application import org.openrndr.color.ColorRGBa import org.openrndr.draw.shadeStyle @@ -7,6 +9,10 @@ import org.openrndr.extra.shaderphrases.preprocess import org.openrndr.math.Vector2 fun main() = application { + configure { + width = 720 + height = 360 + } program { ColormapPhraseBook.register() val backgroundStyle = shadeStyle { diff --git a/orx-color/src/jvmDemo/kotlin/DemoHistogram01.kt b/orx-color/src/jvmDemo/kotlin/histogram/DemoHistogram01.kt similarity index 90% rename from orx-color/src/jvmDemo/kotlin/DemoHistogram01.kt rename to orx-color/src/jvmDemo/kotlin/histogram/DemoHistogram01.kt index a2c9ca9d..1ea43560 100644 --- a/orx-color/src/jvmDemo/kotlin/DemoHistogram01.kt +++ b/orx-color/src/jvmDemo/kotlin/histogram/DemoHistogram01.kt @@ -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.draw.loadImage import org.openrndr.extra.color.statistics.calculateHistogramRGB fun main() = application { + configure { + width = 720 + height = 540 + } program { val useColors = 32 val image = loadImage("demo-data/images/image-001.png") @@ -29,7 +33,7 @@ fun main() = application { "% of the image colors.") extend { - drawer.image(image) + drawer.image(image, 0.0, 0.0, width * 1.0, height * 1.0) drawer.stroke = null var x = 0.0 topColorsSortedByLuminosity.forEachIndexed { i, (color, freq) -> diff --git a/orx-color/src/jvmDemo/kotlin/DemoHistogram02.kt b/orx-color/src/jvmDemo/kotlin/histogram/DemoHistogram02.kt similarity index 82% rename from orx-color/src/jvmDemo/kotlin/DemoHistogram02.kt rename to orx-color/src/jvmDemo/kotlin/histogram/DemoHistogram02.kt index f29800df..c12ce3a3 100644 --- a/orx-color/src/jvmDemo/kotlin/DemoHistogram02.kt +++ b/orx-color/src/jvmDemo/kotlin/histogram/DemoHistogram02.kt @@ -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.draw.loadImage @@ -6,6 +6,10 @@ import org.openrndr.extra.color.statistics.calculateHistogramRGB import kotlin.math.pow fun main() = application { + configure { + width = 720 + height = 540 + } program { val image = loadImage("demo-data/images/image-001.png") // -- 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 extend { - drawer.image(image) + drawer.image(image, 0.0, 0.0, width * 1.0, height * 1.0) for (i in 0 until 32) { drawer.fill = colors[i].first drawer.stroke = null diff --git a/orx-color/src/jvmDemo/kotlin/DemoHistogram03.kt b/orx-color/src/jvmDemo/kotlin/histogram/DemoHistogram03.kt similarity index 79% rename from orx-color/src/jvmDemo/kotlin/DemoHistogram03.kt rename to orx-color/src/jvmDemo/kotlin/histogram/DemoHistogram03.kt index 57f7e2f8..1dee160f 100644 --- a/orx-color/src/jvmDemo/kotlin/DemoHistogram03.kt +++ b/orx-color/src/jvmDemo/kotlin/histogram/DemoHistogram03.kt @@ -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.draw.loadImage import org.openrndr.extra.color.statistics.calculateHistogramRGB fun main() = application { + configure { + width = 720 + height = 540 + } program { val image = loadImage("demo-data/images/image-001.png") val histogram = calculateHistogramRGB(image) extend { - drawer.image(image) for (j in 0 until height step 32) { for (i in 0 until width step 32) { drawer.stroke = null diff --git a/orx-jumpflood/src/jvmDemo/kotlin/DemoDirectionField01.kt b/orx-jumpflood/src/jvmDemo/kotlin/DemoDirectionField01.kt index c6d167a9..296f1715 100644 --- a/orx-jumpflood/src/jvmDemo/kotlin/DemoDirectionField01.kt +++ b/orx-jumpflood/src/jvmDemo/kotlin/DemoDirectionField01.kt @@ -18,8 +18,8 @@ import org.openrndr.shape.Rectangle */ fun main() = application { configure { - width = 1024 - height = 1024 + width = 720 + height = 720 } program { diff --git a/orx-jumpflood/src/jvmDemo/kotlin/DemoDirectionField02.kt b/orx-jumpflood/src/jvmDemo/kotlin/DemoDirectionField02.kt index 3963dfa3..0c3b929a 100644 --- a/orx-jumpflood/src/jvmDemo/kotlin/DemoDirectionField02.kt +++ b/orx-jumpflood/src/jvmDemo/kotlin/DemoDirectionField02.kt @@ -1,25 +1,23 @@ -import org.openrndr.MouseTracker import org.openrndr.application 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.extra.jumpfill.DirectionalField import org.openrndr.extra.noise.scatter -import org.openrndr.extra.noise.simplex import org.openrndr.math.IntVector2 -import org.openrndr.math.Vector2 import org.openrndr.math.Vector3 import org.openrndr.math.clamp -import org.openrndr.shape.Rectangle -import kotlin.math.abs /** * Create directional distance field and demonstrate signed distance */ fun main() = application { configure { - width = 1024 - height = 1024 + width = 720 + height = 720 } program { @@ -37,7 +35,10 @@ fun main() = application { ddf.shadow.download() 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 sdf3 = Vector3(c.r, c.g, c.b) diff --git a/orx-jumpflood/src/jvmDemo/kotlin/DemoDistanceField01.kt b/orx-jumpflood/src/jvmDemo/kotlin/DemoDistanceField01.kt index 04297740..2d01bc82 100644 --- a/orx-jumpflood/src/jvmDemo/kotlin/DemoDistanceField01.kt +++ b/orx-jumpflood/src/jvmDemo/kotlin/DemoDistanceField01.kt @@ -25,8 +25,8 @@ import org.openrndr.shape.Rectangle */ fun main() = application { configure { - width = 1024 - height = 1024 + width = 720 + height = 720 } program { diff --git a/orx-jumpflood/src/jvmDemo/kotlin/DemoInnerGlow01.kt b/orx-jumpflood/src/jvmDemo/kotlin/DemoInnerGlow01.kt index 7a0a485b..c77ca4ce 100644 --- a/orx-jumpflood/src/jvmDemo/kotlin/DemoInnerGlow01.kt +++ b/orx-jumpflood/src/jvmDemo/kotlin/DemoInnerGlow01.kt @@ -8,6 +8,10 @@ import org.openrndr.extra.fx.patterns.Checkers import org.openrndr.extra.jumpfill.fx.InnerGlow fun main() = application { + configure { + width = 720 + height = 720 + } program { val c = compose { layer { diff --git a/orx-jumpflood/src/jvmDemo/kotlin/DemoInnerGlow02.kt b/orx-jumpflood/src/jvmDemo/kotlin/DemoInnerGlow02.kt index d00f8dee..e008e3ab 100644 --- a/orx-jumpflood/src/jvmDemo/kotlin/DemoInnerGlow02.kt +++ b/orx-jumpflood/src/jvmDemo/kotlin/DemoInnerGlow02.kt @@ -8,6 +8,10 @@ import org.openrndr.extra.fx.patterns.Checkers import org.openrndr.extra.jumpfill.fx.InnerGlow fun main() = application { + configure { + width = 720 + height = 720 + } program { val c = compose { layer { diff --git a/orx-jumpflood/src/jvmDemo/kotlin/DemoShapeSDF01.kt b/orx-jumpflood/src/jvmDemo/kotlin/DemoShapeSDF01.kt index 2c7080af..0aa182c3 100644 --- a/orx-jumpflood/src/jvmDemo/kotlin/DemoShapeSDF01.kt +++ b/orx-jumpflood/src/jvmDemo/kotlin/DemoShapeSDF01.kt @@ -6,28 +6,26 @@ import org.openrndr.draw.colorBuffer import org.openrndr.extra.jumpfill.ShapeSDF import org.openrndr.extra.svg.loadSVG -fun main() { - application { - configure { - width = 1280 - height = 720 - } - program { - val sdf = ShapeSDF() - val df = colorBuffer(width, height, format = ColorFormat.RGBa, type = ColorType.FLOAT32) +fun main() = application { + configure { + width = 720 + height = 405 + } + program { + val sdf = ShapeSDF() + 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 } sdf.setShapes(shapes) sdf.apply(emptyArray(), df) - val mouseTracker = MouseTracker(mouse) + val mouseTracker = MouseTracker(mouse) - extend { - if(mouseTracker.pressedButtons.isEmpty()) - drawer.image(df) - else - drawer.shapes(shapes) - } + extend { + if(mouseTracker.pressedButtons.isEmpty()) + drawer.image(df) + else + drawer.shapes(shapes) } } -} \ No newline at end of file +} diff --git a/orx-jumpflood/src/jvmDemo/kotlin/DemoShapeSDF02.kt b/orx-jumpflood/src/jvmDemo/kotlin/DemoShapeSDF02.kt index 0d6af615..1a6cf928 100644 --- a/orx-jumpflood/src/jvmDemo/kotlin/DemoShapeSDF02.kt +++ b/orx-jumpflood/src/jvmDemo/kotlin/DemoShapeSDF02.kt @@ -13,50 +13,48 @@ import org.openrndr.math.transforms.transform import kotlin.math.min -fun main() { - application { - configure { - width = 1280 - height = 720 - } - program { - val sdf0 = ShapeSDF() - val df0 = colorBuffer(width, height, format = ColorFormat.RGBa, type = ColorType.FLOAT32) +fun main() = application { + configure { + width = 720 + height = 405 + } + program { + val sdf0 = ShapeSDF() + val df0 = colorBuffer(width, height, format = ColorFormat.RGBa, type = ColorType.FLOAT32) - val sdf1 = ShapeSDF() - val df1 = colorBuffer(width, height, format = ColorFormat.RGBa, type = ColorType.FLOAT32) + val sdf1 = ShapeSDF() + 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 onion = SDFOnion() + val union = SDFSmoothIntersection() + val onion = SDFOnion() - val strokeFill = SDFStrokeFill() + val strokeFill = SDFStrokeFill() - extend { - drawer.clear(ColorRGBa.PINK) + extend { + drawer.clear(ColorRGBa.PINK) - sdf0.setShapes(shapes) + sdf0.setShapes(shapes) - sdf1.setShapes(shapes.map { - it.transform(transform { - translate(1280 / 2.0, 720.0 / 2) - rotate(Vector3.Companion.UNIT_Z, seconds * 45.0 - 30.0) - translate(-1280 / 2.0, -720.0 / 2.0) - }) + sdf1.setShapes(shapes.map { + it.transform(transform { + translate(drawer.bounds.center) + rotate(Vector3.Companion.UNIT_Z, seconds * 45.0 - 30.0) + translate(-drawer.bounds.center) }) + }) - sdf0.apply(emptyArray(), df0) - sdf1.apply(emptyArray(), df1) - union.radius = 10.0 + min(mouse.position.y, 100.0) - union.apply(arrayOf(df0, df1), df0) - onion.radius = 20.0 - onion.apply(df0, df0) - strokeFill.strokeWeight = 2.0 - strokeFill.apply(df0, df0) - drawer.image(df0) - } + sdf0.apply(emptyArray(), df0) + sdf1.apply(emptyArray(), df1) + union.radius = 10.0 + min(mouse.position.y, 100.0) + union.apply(arrayOf(df0, df1), df0) + onion.radius = 20.0 + onion.apply(df0, df0) + strokeFill.strokeWeight = 2.0 + strokeFill.apply(df0, df0) + drawer.image(df0) } } -} \ No newline at end of file +} diff --git a/orx-jumpflood/src/jvmDemo/kotlin/DemoShapeSDF03.kt b/orx-jumpflood/src/jvmDemo/kotlin/DemoShapeSDF03.kt index b511bfc8..e1b52ad0 100644 --- a/orx-jumpflood/src/jvmDemo/kotlin/DemoShapeSDF03.kt +++ b/orx-jumpflood/src/jvmDemo/kotlin/DemoShapeSDF03.kt @@ -9,47 +9,44 @@ import org.openrndr.extra.jumpfill.draw.SDFStrokeFill import org.openrndr.extra.jumpfill.ops.SDFSmoothDifference 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() { - application { - 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() + fd.outputUV = true - val fd = FluidDistort() - fd.outputUV = true + val uvmap = colorBuffer(width, height, type = ColorType.FLOAT16) - 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 } - val union = SDFSmoothDifference() + sdf0.setShapes(shapes) + sdf1.setShapes(shapes) - sdf0.setShapes(shapes) - sdf1.setShapes(shapes) + val strokeFill = SDFStrokeFill() - val strokeFill = SDFStrokeFill() + extend { + drawer.clear(ColorRGBa.PINK) - extend { - drawer.clear(ColorRGBa.PINK) + fd.apply(emptyArray(), uvmap) - 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 - sdf0.apply(uvmap, df0) - sdf1.apply(uvmap, df1) - union.radius = 10.0 - union.apply(arrayOf(df0, df1), df0) - - strokeFill.strokeWeight = 10.0 - strokeFill.apply(df0, df0) - drawer.image(df0) - } + strokeFill.strokeWeight = 10.0 + strokeFill.apply(df0, df0) + drawer.image(df0) } } -} \ No newline at end of file +} diff --git a/orx-jumpflood/src/jvmDemo/kotlin/DemoShapeSDF04.kt b/orx-jumpflood/src/jvmDemo/kotlin/DemoShapeSDF04.kt index bec8706b..c354d45f 100644 --- a/orx-jumpflood/src/jvmDemo/kotlin/DemoShapeSDF04.kt +++ b/orx-jumpflood/src/jvmDemo/kotlin/DemoShapeSDF04.kt @@ -11,52 +11,49 @@ import org.openrndr.extra.jumpfill.ops.SDFSmoothDifference import org.openrndr.extra.svg.loadSVG 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() { - application { - 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() + perturb.outputUV = true - val perturb = Perturb() - perturb.outputUV = true + val uvmap = colorBuffer(width, height, type = ColorType.FLOAT16) - 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} - val shapes = loadSVG("orx-jumpflood/src/jvmDemo/resources/name.svg").findShapes().map { it.shape } + sdf0.setShapes(circleShapes) + sdf1.setShapes(shapes) - sdf0.setShapes(circleShapes) - sdf1.setShapes(shapes) + val difference = SDFSmoothDifference() + val strokeFill = SDFStrokeFill() - val difference = SDFSmoothDifference() - val strokeFill = SDFStrokeFill() + gui.add(perturb) + extend(gui) + extend { + drawer.clear(ColorRGBa.PINK) - gui.add(perturb) - extend(gui) - extend { - drawer.clear(ColorRGBa.PINK) + perturb.phase = seconds * 0.1 + perturb.apply(uvmap, uvmap) - perturb.phase = seconds * 0.1 - perturb.apply(uvmap, uvmap) + sdf0.useUV = true + sdf0.apply(uvmap, df0) + sdf1.apply(uvmap, df1) + difference.radius = 10.0 + difference.apply(arrayOf(df0, df1), df0) - sdf0.useUV = true - sdf0.apply(uvmap, df0) - sdf1.apply(uvmap, df1) - difference.radius = 10.0 - difference.apply(arrayOf(df0, df1), df0) - - strokeFill.strokeWeight = 10.0 - strokeFill.apply(df0, df0) - drawer.image(df0) - } + strokeFill.strokeWeight = 10.0 + strokeFill.apply(df0, df0) + drawer.image(df0) } } -} \ No newline at end of file +} diff --git a/orx-jumpflood/src/jvmDemo/kotlin/DemoShapeSDF05.kt b/orx-jumpflood/src/jvmDemo/kotlin/DemoShapeSDF05.kt index ddb30d47..a54dd184 100644 --- a/orx-jumpflood/src/jvmDemo/kotlin/DemoShapeSDF05.kt +++ b/orx-jumpflood/src/jvmDemo/kotlin/DemoShapeSDF05.kt @@ -11,66 +11,63 @@ import org.openrndr.extra.jumpfill.ops.SDFSmoothDifference import org.openrndr.extra.svg.loadSVG import org.openrndr.math.Vector2 import org.openrndr.shape.Circle - import kotlin.math.cos import kotlin.math.sin -fun main() { - application { - 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) +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) - 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.phase = seconds * 0.1 + perturb.apply(uvmap, uvmap) - val uvmap = colorBuffer(width, height, type = ColorType.FLOAT16) - val uvmap2 = colorBuffer(width, height, type = ColorType.FLOAT16) + perturb.offset = Vector2.ZERO + 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} - val shapes = loadSVG("orx-jumpflood/src/jvmDemo/resources/name.svg").findShapes().map { it.shape } + sdf0.apply(uvmap2, df0) + sdf1.apply(uvmap2, df1) - sdf0.setShapes(circleShapes) - sdf1.setShapes(shapes) + difference.apply(arrayOf(df0, df1), df0) - 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.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) - } + strokeFill.apply(df0, df0) + drawer.image(df0) } } -} \ No newline at end of file +} diff --git a/orx-jumpflood/src/jvmDemo/kotlin/DemoSkeleton01.kt b/orx-jumpflood/src/jvmDemo/kotlin/DemoSkeleton01.kt index b3e699c3..fb2e0b40 100644 --- a/orx-jumpflood/src/jvmDemo/kotlin/DemoSkeleton01.kt +++ b/orx-jumpflood/src/jvmDemo/kotlin/DemoSkeleton01.kt @@ -7,40 +7,38 @@ import org.openrndr.draw.renderTarget import org.openrndr.extra.jumpfill.fx.Skeleton import org.openrndr.extra.noise.simplex -fun main() { - application { - configure { - width = 1280 - height = 720 - } - program { - val skeleton = Skeleton() +fun main() = application { + configure { + width = 720 + height = 540 + } + program { + val skeleton = Skeleton() - val input = renderTarget(width, height) { - colorBuffer() - } - val field = input.colorBuffer(0).createEquivalent(type = ColorType.FLOAT32) - extend { - drawer.isolatedWithTarget(input) { - // -- draw something interesting - drawer.stroke = null - drawer.clear(ColorRGBa.BLACK) - drawer.fill = ColorRGBa.WHITE - drawer.circle(mouse.position, 300.0) - drawer.fill = ColorRGBa.BLACK - drawer.circle(mouse.position, 150.0) - drawer.fill = ColorRGBa.WHITE - for (i in 0 until 30) { - val time = seconds * 0.25 - val x = simplex(i * 20, time) * width / 2 + width / 2 - val y = simplex(i * 20 + 5, time) * height / 2 + height / 2 - val r = simplex(i*30, time) * 50.0 + 50.0 - drawer.circle(x, y, r) - } + val input = renderTarget(width, height) { + colorBuffer() + } + val field = input.colorBuffer(0).createEquivalent(type = ColorType.FLOAT32) + extend { + drawer.isolatedWithTarget(input) { + // -- draw something interesting + drawer.stroke = null + drawer.clear(ColorRGBa.BLACK) + drawer.fill = ColorRGBa.WHITE + drawer.circle(mouse.position, 300.0) + drawer.fill = ColorRGBa.BLACK + drawer.circle(mouse.position, 150.0) + drawer.fill = ColorRGBa.WHITE + for (i in 0 until 30) { + val time = seconds * 0.25 + val x = simplex(i * 20, time) * width / 2 + width / 2 + val y = simplex(i * 20 + 5, time) * height / 2 + height / 2 + val r = simplex(i * 30, time) * 50.0 + 50.0 + drawer.circle(x, y, r) } - skeleton.apply(input.colorBuffer(0), field) - drawer.image(field) } + skeleton.apply(input.colorBuffer(0), field) + drawer.image(field) } } -} \ No newline at end of file +} diff --git a/orx-jumpflood/src/jvmDemo/kotlin/DemoStraightSkeleton01.kt b/orx-jumpflood/src/jvmDemo/kotlin/DemoStraightSkeleton01.kt index 2f3dd70b..f8e4c83a 100644 --- a/orx-jumpflood/src/jvmDemo/kotlin/DemoStraightSkeleton01.kt +++ b/orx-jumpflood/src/jvmDemo/kotlin/DemoStraightSkeleton01.kt @@ -2,46 +2,43 @@ import org.openrndr.application import org.openrndr.color.ColorRGBa import org.openrndr.draw.ColorType import org.openrndr.draw.createEquivalent - import org.openrndr.draw.isolatedWithTarget import org.openrndr.draw.renderTarget import org.openrndr.extra.jumpfill.fx.StraightSkeleton import org.openrndr.extra.noise.simplex -fun main() { - application { - configure { - width = 1280 - height = 720 +fun main() = application { + configure { + width = 720 + height = 720 + } + program { + val straightSkeleton = StraightSkeleton() + val input = renderTarget(width, height) { + colorBuffer() } - program { - val straightSkeleton = StraightSkeleton() - val input = renderTarget(width, height) { - colorBuffer() - } - val field = input.colorBuffer(0).createEquivalent(type = ColorType.FLOAT32) + val field = input.colorBuffer(0).createEquivalent(type = ColorType.FLOAT32) - extend { - drawer.isolatedWithTarget(input) { - // -- draw something interesting - drawer.stroke = null - drawer.clear(ColorRGBa.BLACK) - drawer.fill = ColorRGBa.WHITE - drawer.circle(mouse.position, 300.0) - drawer.fill = ColorRGBa.BLACK - drawer.circle(mouse.position, 150.0) - drawer.fill = ColorRGBa.WHITE - for (i in 0 until 30) { - val time = seconds * 0.25 - val x = simplex(i * 20, time) * width / 2 + width / 2 - val y = simplex(i * 20 + 5, time) * height / 2 + height / 2 - val r = simplex(i*30, time) * 50.0 + 50.0 - drawer.circle(x, y, r) - } + extend { + drawer.isolatedWithTarget(input) { + // -- draw something interesting + drawer.stroke = null + drawer.clear(ColorRGBa.BLACK) + drawer.fill = ColorRGBa.WHITE + drawer.circle(mouse.position, 300.0) + drawer.fill = ColorRGBa.BLACK + drawer.circle(mouse.position, 150.0) + drawer.fill = ColorRGBa.WHITE + for (i in 0 until 30) { + val time = seconds * 0.25 + val x = simplex(i * 20, time) * width / 2 + width / 2 + val y = simplex(i * 20 + 5, time) * height / 2 + height / 2 + val r = simplex(i * 30, time) * 50.0 + 50.0 + drawer.circle(x, y, r) } - straightSkeleton.apply(input.colorBuffer(0), field) - drawer.image(field) } + straightSkeleton.apply(input.colorBuffer(0), field) + drawer.image(field) } } -} \ No newline at end of file +} diff --git a/orx-jumpflood/src/jvmDemo/kotlin/DemoVoronoi01.kt b/orx-jumpflood/src/jvmDemo/kotlin/DemoVoronoi01.kt index 062f3cc1..d57a3307 100644 --- a/orx-jumpflood/src/jvmDemo/kotlin/DemoVoronoi01.kt +++ b/orx-jumpflood/src/jvmDemo/kotlin/DemoVoronoi01.kt @@ -13,14 +13,14 @@ fun main() = application { height = 512 } program { - val rt = renderTarget(512, 512, 1.0) { + val rt = renderTarget(width, height, 1.0) { colorBuffer(type = ColorType.FLOAT32) } val encoder = EncodePoints() - val jf = JumpFlooder(512, 512, encodePoints = Passthrough()) - val jf2 = JumpFlooder(512, 512, encodePoints = Passthrough()) + val jf = JumpFlooder(width, height, encodePoints = Passthrough()) + val jf2 = JumpFlooder(width, height, encodePoints = Passthrough()) val idcontours = IdContourPoints() - val contoured = colorBuffer(512, 512, type = ColorType.FLOAT32) + val contoured = colorBuffer(width, height, type = ColorType.FLOAT32) extend { fun plot(x: Double, y: Double, id: Double) { drawer.fill = ColorRGBa(id, 0.0, 0.0, 1.0) @@ -53,7 +53,7 @@ fun main() = application { drawer.image(contoured) val flooded2 = jf2.jumpFlood(contoured) - drawer.image(flooded2, 512.0, 0.0) + drawer.image(flooded2, width * 1.0, 0.0) drawer.shadeStyle = shadeStyle { fragmentTransform = """ diff --git a/orx-jumpflood/src/jvmDemo/kotlin/DemoVoronoi02.kt b/orx-jumpflood/src/jvmDemo/kotlin/DemoVoronoi02.kt index 8e8d93cb..125c67c3 100644 --- a/orx-jumpflood/src/jvmDemo/kotlin/DemoVoronoi02.kt +++ b/orx-jumpflood/src/jvmDemo/kotlin/DemoVoronoi02.kt @@ -10,11 +10,11 @@ fun main() = application { height = 512 } program { - val rt = renderTarget(512, 512, 1.0) { + val rt = renderTarget(width, height, 1.0) { 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) diff --git a/orx-jumpflood/src/jvmDemo/kotlin/DemoVoronoi03.kt b/orx-jumpflood/src/jvmDemo/kotlin/DemoVoronoi03.kt index 22ebd802..200b7a1f 100644 --- a/orx-jumpflood/src/jvmDemo/kotlin/DemoVoronoi03.kt +++ b/orx-jumpflood/src/jvmDemo/kotlin/DemoVoronoi03.kt @@ -9,11 +9,11 @@ import org.openrndr.math.Vector2 fun main() = application { configure { - width = 720 - height = 720 + width = 512 + height = 512 } program { - val rt = renderTarget(720, 720, 1.0) { + val rt = renderTarget(width, height, 1.0) { colorBuffer(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) drawer.points { 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) { - 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)) } } } diff --git a/orx-jumpflood/src/jvmDemo/resources/name.svg b/orx-jumpflood/src/jvmDemo/resources/name.svg index 7d3f45b2..58076b04 100644 --- a/orx-jumpflood/src/jvmDemo/resources/name.svg +++ b/orx-jumpflood/src/jvmDemo/resources/name.svg @@ -1,12 +1,8 @@ - - - - - - - + + + + + + + + diff --git a/orx-no-clear/src/jvmDemo/kotlin/DemoNoClear.kt b/orx-no-clear/src/jvmDemo/kotlin/DemoNoClear.kt index 4994a97a..7d001a18 100644 --- a/orx-no-clear/src/jvmDemo/kotlin/DemoNoClear.kt +++ b/orx-no-clear/src/jvmDemo/kotlin/DemoNoClear.kt @@ -16,6 +16,12 @@ fun main() = application { program { var time = 0.0 + if (System.getProperty("takeScreenshot") == "true") { + extensions.filterIsInstance().forEach { + it.delayFrames = 200 + } + } + // ------------------------------------------------------------ // By default OPENRNDR clears the canvas on each animation // frame. NoClear disables that behavior, letting you @@ -29,11 +35,6 @@ fun main() = application { backdrop = { drawer.clear(rgb(0.15)) } } - if (System.getProperty("takeScreenshot") == "true") { - extensions.filterIsInstance().forEach { - it.delayFrames = 60 - } - } extend { // Draw something. For this demo *what* you draw is not so // important, only the fact that it stays on the canvas