diff --git a/orx-noise/README.md b/orx-noise/README.md index dd045c64..9ceddd72 100644 --- a/orx-noise/README.md +++ b/orx-noise/README.md @@ -185,21 +185,8 @@ val v7 = billow(seed, x, y, z, ::perlinLinear, octaves, lacunarity, gain) val v8 = billow(seed, x, y, z, ::perlinLinear, octaves, lacunarity, gain) ``` - ## Demos -### DemoCircleHash01 -[source code](src/jvmDemo/kotlin/DemoCircleHash01.kt) - -![DemoCircleHash01Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-noise/images/DemoCircleHash01Kt.png) - ### DemoCubicNoise2D01 [source code](src/jvmDemo/kotlin/DemoCubicNoise2D01.kt) @@ -220,21 +207,6 @@ val v8 = billow(seed, x, y, z, ::perlinLinear, octaves, lacunarity, gain) ![DemoGradientPerturb3DKt](https://raw.githubusercontent.com/openrndr/orx/media/orx-noise/images/DemoGradientPerturb3DKt.png) -### DemoNoisesGLSLGui -[source code](src/jvmDemo/kotlin/DemoNoisesGLSLGui.kt) - -![DemoNoisesGLSLGuiKt](https://raw.githubusercontent.com/openrndr/orx/media/orx-noise/images/DemoNoisesGLSLGuiKt.png) - -### DemoNoisesGLSL -[source code](src/jvmDemo/kotlin/DemoNoisesGLSL.kt) - -![DemoNoisesGLSLKt](https://raw.githubusercontent.com/openrndr/orx/media/orx-noise/images/DemoNoisesGLSLKt.png) - -### DemoRectangleHash01 -[source code](src/jvmDemo/kotlin/DemoRectangleHash01.kt) - -![DemoRectangleHash01Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-noise/images/DemoRectangleHash01Kt.png) - ### DemoScatter01 [source code](src/jvmDemo/kotlin/DemoScatter01.kt) @@ -245,26 +217,31 @@ val v8 = billow(seed, x, y, z, ::perlinLinear, octaves, lacunarity, gain) ![DemoSimplex01Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-noise/images/DemoSimplex01Kt.png) -### DemoSimplexGLSL -[source code](src/jvmDemo/kotlin/DemoSimplexGLSL.kt) - -![DemoSimplexGLSLKt](https://raw.githubusercontent.com/openrndr/orx/media/orx-noise/images/DemoSimplexGLSLKt.png) - ### DemoTriangleNoise01 [source code](src/jvmDemo/kotlin/DemoTriangleNoise01.kt) ![DemoTriangleNoise01Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-noise/images/DemoTriangleNoise01Kt.png) -### DemoUHash01 -[source code](src/jvmDemo/kotlin/DemoUHash01.kt) - -![DemoUHash01Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-noise/images/DemoUHash01Kt.png) - ### DemoValueNoise2D01 [source code](src/jvmDemo/kotlin/DemoValueNoise2D01.kt) ![DemoValueNoise2D01Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-noise/images/DemoValueNoise2D01Kt.png) +### glsl/DemoNoisesGLSLGui +[source code](src/jvmDemo/kotlin/glsl/DemoNoisesGLSLGui.kt) + +![glsl-DemoNoisesGLSLGuiKt](https://raw.githubusercontent.com/openrndr/orx/media/orx-noise/images/glsl-DemoNoisesGLSLGuiKt.png) + +### glsl/DemoNoisesGLSL +[source code](src/jvmDemo/kotlin/glsl/DemoNoisesGLSL.kt) + +![glsl-DemoNoisesGLSLKt](https://raw.githubusercontent.com/openrndr/orx/media/orx-noise/images/glsl-DemoNoisesGLSLKt.png) + +### glsl/DemoSimplexGLSL +[source code](src/jvmDemo/kotlin/glsl/DemoSimplexGLSL.kt) + +![glsl-DemoSimplexGLSLKt](https://raw.githubusercontent.com/openrndr/orx/media/orx-noise/images/glsl-DemoSimplexGLSLKt.png) + ### hammersley/DemoHammersley2D01 [source code](src/jvmDemo/kotlin/hammersley/DemoHammersley2D01.kt) @@ -280,6 +257,21 @@ val v8 = billow(seed, x, y, z, ::perlinLinear, octaves, lacunarity, gain) ![hammersley-DemoHammersley4D01Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-noise/images/hammersley-DemoHammersley4D01Kt.png) +### hash/DemoCircleHash01 +[source code](src/jvmDemo/kotlin/hash/DemoCircleHash01.kt) + +![hash-DemoCircleHash01Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-noise/images/hash-DemoCircleHash01Kt.png) + +### hash/DemoRectangleHash01 +[source code](src/jvmDemo/kotlin/hash/DemoRectangleHash01.kt) + +![hash-DemoRectangleHash01Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-noise/images/hash-DemoRectangleHash01Kt.png) + +### hash/DemoUHash01 +[source code](src/jvmDemo/kotlin/hash/DemoUHash01.kt) + +![hash-DemoUHash01Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-noise/images/hash-DemoUHash01Kt.png) + ### phrases/DemoUHashPhrase01 [source code](src/jvmDemo/kotlin/phrases/DemoUHashPhrase01.kt) diff --git a/orx-noise/src/jvmDemo/kotlin/DemoCircleHash01.kt b/orx-noise/src/jvmDemo/kotlin/DemoCircleHash01.kt deleted file mode 100644 index 8610bcdb..00000000 --- a/orx-noise/src/jvmDemo/kotlin/DemoCircleHash01.kt +++ /dev/null @@ -1,33 +0,0 @@ -import org.openrndr.application -import org.openrndr.extra.noise.shapes.hash -import org.openrndr.extra.noise.shapes.uniform -import org.openrndr.shape.Circle -import kotlin.random.Random - -fun main() { - application { - configure { - width = 720 - height = 720 - } - program { - extend { - val b = drawer.bounds - val b0 = b.sub(0.0, 0.0, 0.5, 1.0).offsetEdges(-10.0) - val b1 = b.sub(0.5, 0.0, 1.0, 1.0).offsetEdges(-10.0) - - val c0 = Circle(b0.center, b0.width/2.0) - val c1 = Circle(b1.center, b1.width/2.0) - - val r = Random(0) - for (i in 0 until 2000) { - drawer.circle(c0.uniform(r), 2.0) - drawer.circle(c1.hash(909, i),2.0) - - } - - } - - } - } -} \ No newline at end of file diff --git a/orx-noise/src/jvmDemo/kotlin/DemoCubicNoise2D01.kt b/orx-noise/src/jvmDemo/kotlin/DemoCubicNoise2D01.kt index b834d117..41442d44 100644 --- a/orx-noise/src/jvmDemo/kotlin/DemoCubicNoise2D01.kt +++ b/orx-noise/src/jvmDemo/kotlin/DemoCubicNoise2D01.kt @@ -1,21 +1,23 @@ import org.openrndr.application import org.openrndr.color.ColorRGBa -import org.openrndr.extra.noise.* +import org.openrndr.extra.noise.cubicHermite3D -fun main() { - application { - program { - extend { - drawer.points { - for (y in 0 until height) { - for (x in 0 until width) { - val c = cubicHermite3D(100, (x + y) * 0.04, (x - y) * 0.04, seconds * 1.0) * 0.5 + 0.5 - fill = ColorRGBa(c, c, c, 1.0) - point(x.toDouble(), y.toDouble()) - } +fun main() = application { + configure { + width = 720 + height = 360 + } + program { + extend { + drawer.points { + for (y in 0 until height) { + for (x in 0 until width) { + val c = cubicHermite3D(100, (x + y) * 0.04, (x - y) * 0.04, seconds * 1.0) * 0.5 + 0.5 + fill = ColorRGBa(c, c, c, 1.0) + point(x.toDouble(), y.toDouble()) } } } } } -} \ No newline at end of file +} diff --git a/orx-noise/src/jvmDemo/kotlin/DemoGradientPerturb2D.kt b/orx-noise/src/jvmDemo/kotlin/DemoGradientPerturb2D.kt index 883ec047..8b9bb6ed 100644 --- a/orx-noise/src/jvmDemo/kotlin/DemoGradientPerturb2D.kt +++ b/orx-noise/src/jvmDemo/kotlin/DemoGradientPerturb2D.kt @@ -6,22 +6,25 @@ import org.openrndr.extra.noise.simplex import org.openrndr.math.Vector2 import kotlin.math.absoluteValue -fun main() { - application { - program { - val cb = colorBuffer(width, height) - val shad = cb.shadow - extend { - for (y in 0 until height) { - for (x in 0 until width) { - val p = gradientPerturbFractal(300, frequency = 0.8, position = Vector2(seconds + x/320.0,y/240.0)) - val d = simplex(300, p.x, p.y+seconds, seconds).absoluteValue - shad[x, y] = ColorRGBa(d, d, d, 1.0) - } +fun main() = application { + configure { + width = 720 + height = 360 + } + program { + val cb = colorBuffer(width, height) + val shad = cb.shadow + extend { + for (y in 0 until height) { + for (x in 0 until width) { + val p = + gradientPerturbFractal(300, frequency = 0.8, position = Vector2(seconds + x / 320.0, y / 240.0)) + val d = simplex(300, p.x, p.y + seconds, seconds).absoluteValue + shad[x, y] = ColorRGBa(d, d, d, 1.0) } - shad.upload() - drawer.image(cb) } + shad.upload() + drawer.image(cb) } } } \ No newline at end of file diff --git a/orx-noise/src/jvmDemo/kotlin/DemoGradientPerturb3D.kt b/orx-noise/src/jvmDemo/kotlin/DemoGradientPerturb3D.kt index c707b063..fc5b09fa 100644 --- a/orx-noise/src/jvmDemo/kotlin/DemoGradientPerturb3D.kt +++ b/orx-noise/src/jvmDemo/kotlin/DemoGradientPerturb3D.kt @@ -6,22 +6,25 @@ import org.openrndr.extra.noise.simplex import org.openrndr.math.Vector3 import kotlin.math.absoluteValue -fun main() { - application { - program { - val cb = colorBuffer(width, height) - val shad = cb.shadow - extend { - for (y in 0 until height) { - for (x in 0 until width) { - val p = gradientPerturbFractal(300, frequency = 0.8, position = Vector3(x/320.0,y/240.0, seconds)) - val d = simplex(300, p.x, p.y, p.z).absoluteValue - shad[x, y] = ColorRGBa(d, d, d, 1.0) - } +fun main() = application { + configure { + width = 720 + height = 360 + } + program { + val cb = colorBuffer(width, height) + val shad = cb.shadow + extend { + for (y in 0 until height) { + for (x in 0 until width) { + val p = + gradientPerturbFractal(300, frequency = 0.8, position = Vector3(x / 320.0, y / 240.0, seconds)) + val d = simplex(300, p.x, p.y, p.z).absoluteValue + shad[x, y] = ColorRGBa(d, d, d, 1.0) } - shad.upload() - drawer.image(cb) } + shad.upload() + drawer.image(cb) } } -} \ No newline at end of file +} diff --git a/orx-noise/src/jvmDemo/kotlin/DemoRectangleHash01.kt b/orx-noise/src/jvmDemo/kotlin/DemoRectangleHash01.kt deleted file mode 100644 index eb53df28..00000000 --- a/orx-noise/src/jvmDemo/kotlin/DemoRectangleHash01.kt +++ /dev/null @@ -1,29 +0,0 @@ -import org.openrndr.application -import org.openrndr.extra.noise.shapes.hash -import org.openrndr.extra.noise.shapes.uniform -import kotlin.random.Random - -fun main() { - application { - configure { - width = 720 - height = 720 - } - program { - extend { - val b = drawer.bounds - val b0 = b.sub(0.0, 0.0, 0.5, 1.0).offsetEdges(-10.0) - val b1 = b.sub(0.5, 0.0, 1.0, 1.0).offsetEdges(-10.0) - - val r = Random(0) - for (i in 0 until 20000) { - drawer.circle(b0.uniform(r), 2.0) - drawer.circle(b1.hash(909, i),2.0) - - } - - } - - } - } -} \ No newline at end of file diff --git a/orx-noise/src/jvmDemo/kotlin/DemoScatter01.kt b/orx-noise/src/jvmDemo/kotlin/DemoScatter01.kt index eaa63630..66f8f591 100644 --- a/orx-noise/src/jvmDemo/kotlin/DemoScatter01.kt +++ b/orx-noise/src/jvmDemo/kotlin/DemoScatter01.kt @@ -6,23 +6,25 @@ import org.openrndr.shape.Ellipse import kotlin.math.cos import kotlin.random.Random -fun main() { - application { - program { - extend { - val shape = Ellipse(Vector2(width/2.0, height/2.0), 200.0, 150.0 + cos(seconds)*125.0).shape - val points = shape.scatter(20.0, random = Random(0)) - drawer.clear(ColorRGBa.BLACK) - drawer.stroke = null - drawer.fill = ColorRGBa.PINK - drawer.circles(points, 4.0) +fun main() = application { + configure { + width = 720 + height = 540 + } + program { + extend { + val shape = Ellipse(Vector2(width / 2.0, height / 2.0), 200.0, 150.0 + cos(seconds) * 125.0).shape + val points = shape.scatter(20.0, random = Random(0)) + drawer.clear(ColorRGBa.BLACK) + drawer.stroke = null + drawer.fill = ColorRGBa.PINK + drawer.circles(points, 4.0) - if (seconds.mod(2.0) < 1.0) { - drawer.stroke = ColorRGBa.PINK - drawer.fill = null - drawer.shape(shape) - } + if (seconds.mod(2.0) < 1.0) { + drawer.stroke = ColorRGBa.PINK + drawer.fill = null + drawer.shape(shape) } } } -} \ No newline at end of file +} diff --git a/orx-noise/src/jvmDemo/kotlin/DemoTriangleNoise01.kt b/orx-noise/src/jvmDemo/kotlin/DemoTriangleNoise01.kt index 7a3d5f0c..5cb60cb2 100644 --- a/orx-noise/src/jvmDemo/kotlin/DemoTriangleNoise01.kt +++ b/orx-noise/src/jvmDemo/kotlin/DemoTriangleNoise01.kt @@ -7,26 +7,24 @@ import org.openrndr.shape.Triangle * Demonstrate the generation of uniformly distributed points inside a list of triangles * @see */ -fun main() { - application { - configure { - width = 720 - height = 720 - } - program { - val r = drawer.bounds.offsetEdges(-100.0) - val triangle = Triangle(r.position(0.5, 0.0), r.position(0.0, 1.0), r.position(1.0, 1.0)) - //val pts = listOf(triangle).uniform(1000, Random(0)) +fun main() = application { + configure { + width = 720 + height = 720 + } + program { + val r = drawer.bounds.offsetEdges(-100.0) + val triangle = Triangle(r.position(0.5, 0.0), r.position(0.0, 1.0), r.position(1.0, 1.0)) + //val pts = listOf(triangle).uniform(1000, Random(0)) - extend { - val pts = listOf(triangle).hash(1000, 0, (seconds*500.0).toInt()) - drawer.clear(ColorRGBa.PINK) - drawer.stroke = null - drawer.contour(triangle.contour) - drawer.fill = ColorRGBa.BLACK + extend { + val pts = listOf(triangle).hash(1000, 0, (seconds * 500.0).toInt()) + drawer.clear(ColorRGBa.PINK) + drawer.stroke = null + drawer.contour(triangle.contour) + drawer.fill = ColorRGBa.BLACK - drawer.circles(pts, 5.0) - } + drawer.circles(pts, 5.0) } } -} \ No newline at end of file +} diff --git a/orx-noise/src/jvmDemo/kotlin/DemoUHash01.kt b/orx-noise/src/jvmDemo/kotlin/DemoUHash01.kt deleted file mode 100644 index 42632f29..00000000 --- a/orx-noise/src/jvmDemo/kotlin/DemoUHash01.kt +++ /dev/null @@ -1,26 +0,0 @@ -import org.openrndr.application -import org.openrndr.color.ColorRGBa -import org.openrndr.drawImage -import org.openrndr.extra.noise.* - -fun main() { - application { - program { - - - extend { - drawer.points { - for (y in 0 until height) { - for (x in 0 until width) { - val c = fhash3D(100, x + (seconds*60.0).toInt(), y, (0).toInt()) - //val u = uhash11(x.toUInt()).toDouble() / UInt.MAX_VALUE.toDouble() - fill = ColorRGBa(c, c, c, 1.0) - point(x.toDouble(), y.toDouble()) - } - } - } - - } - } - } -} \ No newline at end of file diff --git a/orx-noise/src/jvmDemo/kotlin/DemoValueNoise2D01.kt b/orx-noise/src/jvmDemo/kotlin/DemoValueNoise2D01.kt index cd40521b..8ea743f6 100644 --- a/orx-noise/src/jvmDemo/kotlin/DemoValueNoise2D01.kt +++ b/orx-noise/src/jvmDemo/kotlin/DemoValueNoise2D01.kt @@ -1,21 +1,23 @@ import org.openrndr.application import org.openrndr.color.ColorRGBa -import org.openrndr.extra.noise.* +import org.openrndr.extra.noise.valueQuintic3D -fun main() { - application { - program { - extend { - drawer.points { - for (y in 0 until height) { - for (x in 0 until width) { - val c = valueQuintic3D(100, (x + y) * 0.04, (x - y) * 0.04, seconds * 0.1) * 0.5 + 0.5 - fill = ColorRGBa(c, c, c, 1.0) - point(x.toDouble(), y.toDouble()) - } +fun main() = application { + configure { + width = 720 + height = 360 + } + program { + extend { + drawer.points { + for (y in 0 until height) { + for (x in 0 until width) { + val c = valueQuintic3D(100, (x + y) * 0.04, (x - y) * 0.04, seconds * 0.1) * 0.5 + 0.5 + fill = ColorRGBa(c, c, c, 1.0) + point(x.toDouble(), y.toDouble()) } } } } } -} \ No newline at end of file +} diff --git a/orx-noise/src/jvmDemo/kotlin/DemoNoisesGLSL.kt b/orx-noise/src/jvmDemo/kotlin/glsl/DemoNoisesGLSL.kt similarity index 96% rename from orx-noise/src/jvmDemo/kotlin/DemoNoisesGLSL.kt rename to orx-noise/src/jvmDemo/kotlin/glsl/DemoNoisesGLSL.kt index 2dd28de4..b5530a96 100644 --- a/orx-noise/src/jvmDemo/kotlin/DemoNoisesGLSL.kt +++ b/orx-noise/src/jvmDemo/kotlin/glsl/DemoNoisesGLSL.kt @@ -1,3 +1,5 @@ +package glsl + import org.openrndr.application import org.openrndr.draw.colorBuffer import org.openrndr.extra.noise.filters.* @@ -14,6 +16,10 @@ import kotlin.math.sin * The noise color can be set using a `color` or a `gain` property. */ fun main() = application { + configure { + width = 720 + height = 360 + } program { val noises = listOf( HashNoise(), SpeckleNoise(), CellNoise(), diff --git a/orx-noise/src/jvmDemo/kotlin/DemoNoisesGLSLGui.kt b/orx-noise/src/jvmDemo/kotlin/glsl/DemoNoisesGLSLGui.kt similarity index 75% rename from orx-noise/src/jvmDemo/kotlin/DemoNoisesGLSLGui.kt rename to orx-noise/src/jvmDemo/kotlin/glsl/DemoNoisesGLSLGui.kt index 07cf207e..1f4a3c03 100644 --- a/orx-noise/src/jvmDemo/kotlin/DemoNoisesGLSLGui.kt +++ b/orx-noise/src/jvmDemo/kotlin/glsl/DemoNoisesGLSLGui.kt @@ -1,3 +1,5 @@ +package glsl + import org.openrndr.application import org.openrndr.draw.colorBuffer import org.openrndr.extra.gui.GUI @@ -9,8 +11,10 @@ import org.openrndr.extra.noise.filters.* */ fun main() = application { configure { - width = 200 * 6 + 200 - height = 500 + configure { + width = 720 + height = 360 + } } program { val noises = listOf( @@ -18,7 +22,7 @@ fun main() = application { ValueNoise(), SimplexNoise3D(), WorleyNoise() ) - val img = colorBuffer(200, 460) + val img = colorBuffer((width - 200) / noises.size, 460) val gui = GUI() noises.forEach { gui.add(it) } @@ -27,7 +31,7 @@ fun main() = application { extend { noises.forEachIndexed { i, noise -> noise.apply(emptyArray(), img) - drawer.image(img, 200.0 + i * 200.0, 20.0) + drawer.image(img, 200.0 + i * img.width, 20.0) } } } diff --git a/orx-noise/src/jvmDemo/kotlin/DemoSimplexGLSL.kt b/orx-noise/src/jvmDemo/kotlin/glsl/DemoSimplexGLSL.kt similarity index 77% rename from orx-noise/src/jvmDemo/kotlin/DemoSimplexGLSL.kt rename to orx-noise/src/jvmDemo/kotlin/glsl/DemoSimplexGLSL.kt index ba5c4370..fb13de6b 100644 --- a/orx-noise/src/jvmDemo/kotlin/DemoSimplexGLSL.kt +++ b/orx-noise/src/jvmDemo/kotlin/glsl/DemoSimplexGLSL.kt @@ -1,8 +1,10 @@ +package glsl + import org.openrndr.application import org.openrndr.color.rgb import org.openrndr.draw.colorBuffer -import org.openrndr.extra.noise.Random -import org.openrndr.extra.noise.filters.* +import org.openrndr.extra.noise.filters.SimplexNoise3D +import org.openrndr.extra.noise.uniform import org.openrndr.math.Vector3 import org.openrndr.math.Vector4 import kotlin.math.sin @@ -11,10 +13,10 @@ import kotlin.math.sin * A sine oscillator with randomized parameters */ class SinOsc { - private val freq = Random.double(0.1, 2.0) - private val phase = Random.double(0.0, 6.28) - private val add = Random.double(0.0, 1.0) - private val mul = Random.double(0.0, 1.0 - add) + private val freq = Double.uniform(0.1, 2.0) + private val phase = Double.uniform(0.0, 6.28) + private val add = Double.uniform(0.0, 1.0) + private val mul = Double.uniform(0.0, 1.0 - add) operator fun invoke() = sin(System.currentTimeMillis() * 0.0001 * freq + phase) * mul + add } @@ -25,6 +27,10 @@ class SinOsc { * randomized sine oscillators. */ fun main() = application { + configure { + width = 720 + height = 540 + } program { val noise = SimplexNoise3D() val img = colorBuffer(width, height) diff --git a/orx-noise/src/jvmDemo/kotlin/hammersley/DemoHammersley2D01.kt b/orx-noise/src/jvmDemo/kotlin/hammersley/DemoHammersley2D01.kt index addee41f..17cf4fca 100644 --- a/orx-noise/src/jvmDemo/kotlin/hammersley/DemoHammersley2D01.kt +++ b/orx-noise/src/jvmDemo/kotlin/hammersley/DemoHammersley2D01.kt @@ -10,20 +10,18 @@ import org.openrndr.extra.noise.hammersley.hammersley2D * 400 2D Hammersley points mapped within the bounds of the application's resolution. * These points are visualized by rendering circles at their respective positions. */ -fun main() { - application { - configure { - width = 720 - height = 720 - } +fun main() = application { + configure { + width = 720 + height = 720 + } - program { - extend { - val points = (0 until 400).map { - hammersley2D(it, 400) * 720.0 - } - drawer.circles(points, 5.0) + program { + extend { + val points = (0 until 400).map { + hammersley2D(it, 400) * 720.0 } + drawer.circles(points, 5.0) } } -} \ No newline at end of file +} diff --git a/orx-noise/src/jvmDemo/kotlin/hammersley/DemoHammersley3D01.kt b/orx-noise/src/jvmDemo/kotlin/hammersley/DemoHammersley3D01.kt index 33df6acd..49d4653a 100644 --- a/orx-noise/src/jvmDemo/kotlin/hammersley/DemoHammersley3D01.kt +++ b/orx-noise/src/jvmDemo/kotlin/hammersley/DemoHammersley3D01.kt @@ -20,27 +20,25 @@ import org.openrndr.math.Vector3 * to navigate the scene. The visualization relies on the draw loop for continuous * rendering of the points. */ -fun main() { - application { - configure { - width = 720 - height = 720 - } +fun main() = application { + configure { + width = 720 + height = 720 + } - program { - val sphere = sphereMesh(radius = 0.1) - extend(Orbital()) - extend { - val points = (0 until 1400).map { - (hammersley3D(it, 1400) - Vector3(0.5)) * 10.0 - } - for (point in points) { - drawer.isolated { - drawer.translate(point) - drawer.vertexBuffer(sphere, DrawPrimitive.TRIANGLES) - } + program { + val sphere = sphereMesh(radius = 0.1) + extend(Orbital()) + extend { + val points = (0 until 1400).map { + (hammersley3D(it, 1400) - Vector3(0.5)) * 10.0 + } + for (point in points) { + drawer.isolated { + drawer.translate(point) + drawer.vertexBuffer(sphere, DrawPrimitive.TRIANGLES) } } } } -} \ No newline at end of file +} diff --git a/orx-noise/src/jvmDemo/kotlin/hammersley/DemoHammersley4D01.kt b/orx-noise/src/jvmDemo/kotlin/hammersley/DemoHammersley4D01.kt index 1c4b872a..ee38d1de 100644 --- a/orx-noise/src/jvmDemo/kotlin/hammersley/DemoHammersley4D01.kt +++ b/orx-noise/src/jvmDemo/kotlin/hammersley/DemoHammersley4D01.kt @@ -7,10 +7,7 @@ import org.openrndr.draw.isolated import org.openrndr.extra.camera.Orbital import org.openrndr.extra.meshgenerators.sphereMesh import org.openrndr.extra.noise.hammersley.hammersley4D -import org.openrndr.extra.noise.rsequence.rSeq4D import org.openrndr.math.Vector4 -import kotlin.math.abs -import kotlin.math.min /** * Demo that visualizes a 4D Hammersley point set in a 3D space, with colors determined by the 4th dimension. @@ -25,28 +22,26 @@ import kotlin.math.min * of the scene. Rendering occurs within the draw loop, providing continuous visualization * of the point distribution. */ -fun main() { - application { - configure { - width = 720 - height = 720 - } +fun main() = application { + configure { + width = 720 + height = 720 + } - program { - val sphere = sphereMesh(radius = 0.1) - extend(Orbital()) - extend { - val points = (0 until 10000).map { - (hammersley4D(it, 10000) - Vector4(0.5, 0.5, 0.5, 0.0)) * Vector4(10.0, 10.0, 10.0, 1.0) - } - for (point in points) { - drawer.isolated { - drawer.translate(point.xyz) - drawer.fill = ColorRGBa.RED.toHSVa().shiftHue(point.w * 360.0).toRGBa() - drawer.vertexBuffer(sphere, DrawPrimitive.TRIANGLES) - } + program { + val sphere = sphereMesh(radius = 0.1) + extend(Orbital()) + extend { + val points = (0 until 10000).map { + (hammersley4D(it, 10000) - Vector4(0.5, 0.5, 0.5, 0.0)) * Vector4(10.0, 10.0, 10.0, 1.0) + } + for (point in points) { + drawer.isolated { + drawer.translate(point.xyz) + drawer.fill = ColorRGBa.RED.toHSVa().shiftHue(point.w * 360.0).toRGBa() + drawer.vertexBuffer(sphere, DrawPrimitive.TRIANGLES) } } } } -} \ No newline at end of file +} diff --git a/orx-noise/src/jvmDemo/kotlin/hash/DemoCircleHash01.kt b/orx-noise/src/jvmDemo/kotlin/hash/DemoCircleHash01.kt new file mode 100644 index 00000000..c1f94924 --- /dev/null +++ b/orx-noise/src/jvmDemo/kotlin/hash/DemoCircleHash01.kt @@ -0,0 +1,30 @@ +package hash + +import org.openrndr.application +import org.openrndr.extra.noise.shapes.hash +import org.openrndr.extra.noise.shapes.uniform +import org.openrndr.shape.Circle +import kotlin.random.Random + +fun main() = application { + configure { + width = 720 + height = 360 + } + program { + extend { + val b = drawer.bounds + val b0 = b.sub(0.0, 0.0, 0.5, 1.0).offsetEdges(-10.0) + val b1 = b.sub(0.5, 0.0, 1.0, 1.0).offsetEdges(-10.0) + + val c0 = Circle(b0.center, b0.width / 2.0) + val c1 = Circle(b1.center, b1.width / 2.0) + + val r = Random(0) + for (i in 0 until 2000) { + drawer.circle(c0.uniform(r), 2.0) + drawer.circle(c1.hash(909, i), 2.0) + } + } + } +} diff --git a/orx-noise/src/jvmDemo/kotlin/hash/DemoRectangleHash01.kt b/orx-noise/src/jvmDemo/kotlin/hash/DemoRectangleHash01.kt new file mode 100644 index 00000000..88c0a609 --- /dev/null +++ b/orx-noise/src/jvmDemo/kotlin/hash/DemoRectangleHash01.kt @@ -0,0 +1,27 @@ +package hash + +import org.openrndr.application +import org.openrndr.extra.noise.shapes.hash +import org.openrndr.extra.noise.shapes.uniform +import kotlin.random.Random + +fun main() = application { + configure { + width = 720 + height = 540 + } + program { + extend { + val b = drawer.bounds + val b0 = b.sub(0.0, 0.0, 0.5, 1.0).offsetEdges(-10.0) + val b1 = b.sub(0.5, 0.0, 1.0, 1.0).offsetEdges(-10.0) + + val r = Random(0) + for (i in 0 until 20000) { + drawer.circle(b0.uniform(r), 2.0) + drawer.circle(b1.hash(909, i), 2.0) + + } + } + } +} diff --git a/orx-noise/src/jvmDemo/kotlin/hash/DemoUHash01.kt b/orx-noise/src/jvmDemo/kotlin/hash/DemoUHash01.kt new file mode 100644 index 00000000..ad99a9d5 --- /dev/null +++ b/orx-noise/src/jvmDemo/kotlin/hash/DemoUHash01.kt @@ -0,0 +1,26 @@ +package hash + +import org.openrndr.application +import org.openrndr.color.ColorRGBa +import org.openrndr.extra.noise.fhash3D + +fun main() = application { + configure { + width = 720 + height = 360 + } + program { + extend { + drawer.points { + for (y in 0 until height) { + for (x in 0 until width) { + val c = fhash3D(100, x + (seconds * 60.0).toInt(), y, (0).toInt()) + //val u = uhash11(x.toUInt()).toDouble() / UInt.MAX_VALUE.toDouble() + fill = ColorRGBa(c, c, c, 1.0) + point(x.toDouble(), y.toDouble()) + } + } + } + } + } +} diff --git a/orx-noise/src/jvmDemo/kotlin/phrases/DemoUHashPhrase01.kt b/orx-noise/src/jvmDemo/kotlin/phrases/DemoUHashPhrase01.kt index df01d427..2182ce69 100644 --- a/orx-noise/src/jvmDemo/kotlin/phrases/DemoUHashPhrase01.kt +++ b/orx-noise/src/jvmDemo/kotlin/phrases/DemoUHashPhrase01.kt @@ -2,27 +2,29 @@ package phrases import org.openrndr.application import org.openrndr.draw.shadeStyle -import org.openrndr.extra.noise.phrases.* +import org.openrndr.extra.noise.phrases.fhash13 /** * Demonstrate uniform hashing function phrase in a shadestyle */ -fun main() { - application { - program { - extend { - /** A custom shadestyle */ - val ss = shadeStyle { - fragmentPreamble = """$fhash13""" - fragmentTransform = """ +fun main() = application { + configure { + width = 720 + height = 360 + } + program { + extend { + /** A custom shadestyle */ + val ss = shadeStyle { + fragmentPreamble = """$fhash13""" + fragmentTransform = """ float cf = fhash13(vec3(c_screenPosition, p_time)); x_fill = vec4(cf, cf, cf, 1.0); """.trimIndent() - parameter("time", seconds) - } - drawer.shadeStyle = ss - drawer.circle(drawer.bounds.center, 100.0) + parameter("time", seconds) } + drawer.shadeStyle = ss + drawer.circle(drawer.bounds.center, 100.0) } } -} \ No newline at end of file +} diff --git a/orx-noise/src/jvmDemo/kotlin/rseq/DemoRseq2D01.kt b/orx-noise/src/jvmDemo/kotlin/rseq/DemoRseq2D01.kt index a0272016..9f0d910f 100644 --- a/orx-noise/src/jvmDemo/kotlin/rseq/DemoRseq2D01.kt +++ b/orx-noise/src/jvmDemo/kotlin/rseq/DemoRseq2D01.kt @@ -8,20 +8,18 @@ import org.openrndr.extra.noise.rsequence.rSeq2D * demonstrating 2D quasirandomly distributed points. The points are generated * using the R2 sequence and drawn as circles with a radius of 5.0. */ -fun main() { - application { - configure { - width = 720 - height = 720 - } +fun main() = application { + configure { + width = 720 + height = 720 + } - program { - extend { - val points = (0 until 4000).map { - rSeq2D(it) * 720.0 - } - drawer.circles(points, 5.0) + program { + extend { + val points = (0 until 4000).map { + rSeq2D(it) * 720.0 } + drawer.circles(points, 5.0) } } -} \ No newline at end of file +} diff --git a/orx-noise/src/jvmDemo/kotlin/rseq/DemoRseq3D01.kt b/orx-noise/src/jvmDemo/kotlin/rseq/DemoRseq3D01.kt index 94b50757..31be28f4 100644 --- a/orx-noise/src/jvmDemo/kotlin/rseq/DemoRseq3D01.kt +++ b/orx-noise/src/jvmDemo/kotlin/rseq/DemoRseq3D01.kt @@ -19,27 +19,25 @@ import org.openrndr.math.Vector3 * - Generation of quasirandom points in 3D space using the `rSeq3D` function. * - Transformation and rendering of each point as a sphere using vertex buffers. */ -fun main() { - application { - configure { - width = 720 - height = 720 - } +fun main() = application { + configure { + width = 720 + height = 720 + } - program { - val sphere = sphereMesh(radius = 0.1) - extend(Orbital()) - extend { - val points = (0 until 1400).map { - (rSeq3D(it) - Vector3(0.5)) * 10.0 - } - for (point in points) { - drawer.isolated { - drawer.translate(point) - drawer.vertexBuffer(sphere, DrawPrimitive.TRIANGLES) - } + program { + val sphere = sphereMesh(radius = 0.1) + extend(Orbital()) + extend { + val points = (0 until 1400).map { + (rSeq3D(it) - Vector3(0.5)) * 10.0 + } + for (point in points) { + drawer.isolated { + drawer.translate(point) + drawer.vertexBuffer(sphere, DrawPrimitive.TRIANGLES) } } } } -} \ No newline at end of file +} diff --git a/orx-noise/src/jvmDemo/kotlin/rseq/DemoRseq4D01.kt b/orx-noise/src/jvmDemo/kotlin/rseq/DemoRseq4D01.kt index 589a4285..c2153888 100644 --- a/orx-noise/src/jvmDemo/kotlin/rseq/DemoRseq4D01.kt +++ b/orx-noise/src/jvmDemo/kotlin/rseq/DemoRseq4D01.kt @@ -27,28 +27,26 @@ import kotlin.math.min * of the point and its color calculated by shifting the hue of a base color using * the w-coordinate value. */ -fun main() { - application { - configure { - width = 720 - height = 720 - } +fun main() = application { + configure { + width = 720 + height = 720 + } - program { - val sphere = sphereMesh(radius = 0.1) - val points = (0 until 10000).map { - (rSeq4D(it) - Vector4(0.5, 0.5, 0.5, 0.0)) * Vector4(10.0, 10.0, 10.0, 1.0) - } - extend(Orbital()) - extend { - for (point in points) { - drawer.isolated { - drawer.translate(point.xyz) - drawer.fill = ColorRGBa.RED.toHSVa().shiftHue(point.w * 360.0).toRGBa() - drawer.vertexBuffer(sphere, DrawPrimitive.TRIANGLES) - } + program { + val sphere = sphereMesh(radius = 0.1) + val points = (0 until 10000).map { + (rSeq4D(it) - Vector4(0.5, 0.5, 0.5, 0.0)) * Vector4(10.0, 10.0, 10.0, 1.0) + } + extend(Orbital()) + extend { + for (point in points) { + drawer.isolated { + drawer.translate(point.xyz) + drawer.fill = ColorRGBa.RED.toHSVa().shiftHue(point.w * 360.0).toRGBa() + drawer.vertexBuffer(sphere, DrawPrimitive.TRIANGLES) } } } } -} \ No newline at end of file +}