Fixes and move to jvmDemo (#286)
This commit is contained in:
28
orx-noise/src/jvmDemo/kotlin/DemoFunctionalComposition01.kt
Normal file
28
orx-noise/src/jvmDemo/kotlin/DemoFunctionalComposition01.kt
Normal file
@@ -0,0 +1,28 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.draw.LineJoin
|
||||
import org.openrndr.extra.noise.gradient
|
||||
import org.openrndr.extra.noise.simplex3D
|
||||
import org.openrndr.extra.noise.withVector2Output
|
||||
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
}
|
||||
program {
|
||||
val n = simplex3D.withVector2Output().gradient()
|
||||
extend {
|
||||
drawer.stroke = null
|
||||
drawer.fill = ColorRGBa.PINK
|
||||
drawer.lineJoin = LineJoin.ROUND
|
||||
drawer.stroke = ColorRGBa.WHITE
|
||||
for (y in 0 until height step 20) {
|
||||
for (x in 0 until width step 20) {
|
||||
val d = n(40, x * 0.003, y * 0.003,seconds) * 5.0
|
||||
drawer.lineSegment(x * 1.0, y * 1.0, x * 1.0 + d.x, y * 1.0 + d.y)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
28
orx-noise/src/jvmDemo/kotlin/DemoGradientPerturb2D.kt
Normal file
28
orx-noise/src/jvmDemo/kotlin/DemoGradientPerturb2D.kt
Normal file
@@ -0,0 +1,28 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.draw.colorBuffer
|
||||
import org.openrndr.extensions.SingleScreenshot
|
||||
import org.openrndr.extra.noise.gradientPerturbFractal
|
||||
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)
|
||||
}
|
||||
}
|
||||
shad.upload()
|
||||
drawer.image(cb)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
28
orx-noise/src/jvmDemo/kotlin/DemoGradientPerturb3D.kt
Normal file
28
orx-noise/src/jvmDemo/kotlin/DemoGradientPerturb3D.kt
Normal file
@@ -0,0 +1,28 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.draw.colorBuffer
|
||||
import org.openrndr.extensions.SingleScreenshot
|
||||
import org.openrndr.extra.noise.gradientPerturbFractal
|
||||
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)
|
||||
}
|
||||
}
|
||||
shad.upload()
|
||||
drawer.image(cb)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
66
orx-noise/src/jvmDemo/kotlin/DemoNoisesGLSL.kt
Normal file
66
orx-noise/src/jvmDemo/kotlin/DemoNoisesGLSL.kt
Normal file
@@ -0,0 +1,66 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.draw.colorBuffer
|
||||
import org.openrndr.extra.noise.filters.*
|
||||
import org.openrndr.math.Vector2
|
||||
import org.openrndr.math.Vector3
|
||||
import org.openrndr.math.Vector4
|
||||
import kotlin.math.sin
|
||||
|
||||
/**
|
||||
* Render existing GLSL noise algorithms side by side.
|
||||
* Re-use the same color buffer for the rendering.
|
||||
* Not all noise properties are used. Explore each noise class
|
||||
* to find out more adjustable properties.
|
||||
* The noise color can be set using a `color` or a `gain` property.
|
||||
*/
|
||||
fun main() = application {
|
||||
program {
|
||||
val noises = listOf(
|
||||
HashNoise(), SpeckleNoise(), CellNoise(),
|
||||
ValueNoise(), SimplexNoise3D(), WorleyNoise()
|
||||
)
|
||||
|
||||
val img = colorBuffer(width / noises.size, height * 8 / 10)
|
||||
|
||||
extend {
|
||||
val seed = seconds * 0.1
|
||||
val scale = 1.0 + sin(seed) * 0.5
|
||||
noises.forEach { noise ->
|
||||
when (noise) {
|
||||
is HashNoise -> {
|
||||
noise.seed = seed
|
||||
noise.gain = Vector4(0.5 + sin(seconds) * 0.5)
|
||||
noise.monochrome = frameCount % 100 < 50
|
||||
}
|
||||
is SpeckleNoise -> {
|
||||
noise.seed = seed
|
||||
noise.density = 0.1 + sin(seconds) * 0.1
|
||||
}
|
||||
is CellNoise -> {
|
||||
noise.seed = Vector2(seed)
|
||||
noise.scale = Vector2(scale)
|
||||
}
|
||||
is ValueNoise -> {
|
||||
noise.seed = Vector2(seed)
|
||||
noise.scale = Vector2(scale)
|
||||
noise.gain = Vector4(0.5)
|
||||
}
|
||||
is SimplexNoise3D -> {
|
||||
noise.seed = Vector3(seed)
|
||||
noise.scale = Vector3(scale)
|
||||
}
|
||||
is WorleyNoise -> {
|
||||
noise.scale = scale
|
||||
noise.offset = Vector2(seed)
|
||||
}
|
||||
}
|
||||
noise.apply(emptyArray(), img)
|
||||
drawer.image(img)
|
||||
drawer.translate(
|
||||
width / noises.size * 1.0,
|
||||
height * 2 / 10 / (noises.size - 1.0)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
34
orx-noise/src/jvmDemo/kotlin/DemoNoisesGLSLGui.kt
Normal file
34
orx-noise/src/jvmDemo/kotlin/DemoNoisesGLSLGui.kt
Normal file
@@ -0,0 +1,34 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.draw.colorBuffer
|
||||
import org.openrndr.extra.gui.GUI
|
||||
import org.openrndr.extra.noise.filters.*
|
||||
|
||||
/**
|
||||
* Render existing GLSL noise algorithms side by side.
|
||||
* Use the GUI to explore the effects.
|
||||
*/
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 200 * 6 + 200
|
||||
height = 500
|
||||
}
|
||||
program {
|
||||
val noises = listOf(
|
||||
HashNoise(), SpeckleNoise(), CellNoise(),
|
||||
ValueNoise(), SimplexNoise3D(), WorleyNoise()
|
||||
)
|
||||
|
||||
val img = colorBuffer(200, 460)
|
||||
|
||||
val gui = GUI()
|
||||
noises.forEach { gui.add(it) }
|
||||
extend(gui)
|
||||
|
||||
extend {
|
||||
noises.forEachIndexed { i, noise ->
|
||||
noise.apply(emptyArray(), img)
|
||||
drawer.image(img, 200.0 + i * 200.0, 20.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
30
orx-noise/src/jvmDemo/kotlin/DemoScatter01.kt
Normal file
30
orx-noise/src/jvmDemo/kotlin/DemoScatter01.kt
Normal file
@@ -0,0 +1,30 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.math.Vector2
|
||||
import org.openrndr.math.mod_
|
||||
|
||||
import org.openrndr.extra.noise.scatter
|
||||
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)
|
||||
|
||||
if (seconds.mod_(2.0) < 1.0) {
|
||||
drawer.stroke = ColorRGBa.PINK
|
||||
drawer.fill = null
|
||||
drawer.shape(shape)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
35
orx-noise/src/jvmDemo/kotlin/DemoSimplex01.kt
Normal file
35
orx-noise/src/jvmDemo/kotlin/DemoSimplex01.kt
Normal file
@@ -0,0 +1,35 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.draw.LineJoin
|
||||
import org.openrndr.extensions.SingleScreenshot
|
||||
import org.openrndr.extra.noise.simplex
|
||||
import org.openrndr.shape.contour
|
||||
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
}
|
||||
program {
|
||||
extend {
|
||||
drawer.stroke = null
|
||||
drawer.fill = ColorRGBa.PINK
|
||||
drawer.lineJoin = LineJoin.ROUND
|
||||
for (y in 0..height step 20) {
|
||||
val c = contour {
|
||||
moveTo(0.0, 0.0)
|
||||
for (x in 0..width step 40) {
|
||||
val cx = simplex(y, x * 0.1 + seconds) * 10.0 + x
|
||||
val cy = simplex(y + 3000, x * 0.1 + seconds) * 20.0
|
||||
val px = simplex(y + 8000, x * 0.1 + seconds) * 10.0 + x
|
||||
val py = simplex(y + 6000, x * 0.1 + seconds) * 20.0
|
||||
continueTo(cx, cy, px, py)
|
||||
}
|
||||
}
|
||||
val points = c.equidistantPositions(50)
|
||||
drawer.circles(points, 10.0)
|
||||
drawer.translate(0.0, 20.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
47
orx-noise/src/jvmDemo/kotlin/DemoSimplexGLSL.kt
Normal file
47
orx-noise/src/jvmDemo/kotlin/DemoSimplexGLSL.kt
Normal file
@@ -0,0 +1,47 @@
|
||||
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.math.Vector3
|
||||
import org.openrndr.math.Vector4
|
||||
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)
|
||||
operator fun invoke() = sin(System.currentTimeMillis() * 0.0001 * freq + phase) * mul + add
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an animated Simplex3D texture using shaders.
|
||||
*
|
||||
* The uniforms in the shader are controlled by
|
||||
* randomized sine oscillators.
|
||||
*/
|
||||
fun main() = application {
|
||||
program {
|
||||
val noise = SimplexNoise3D()
|
||||
val img = colorBuffer(width, height)
|
||||
val wav = List(21) { SinOsc() }
|
||||
|
||||
extend {
|
||||
noise.seed = Vector3(wav[0](), wav[1](), wav[2]()) // = position
|
||||
noise.scale = Vector3(wav[3](), wav[4](), wav[5]())
|
||||
noise.lacunarity = Vector3(wav[6](), wav[7](), wav[8]())
|
||||
noise.gain = Vector4(wav[9](), wav[10](), wav[11](), wav[12]())
|
||||
noise.decay = Vector4(wav[13](), wav[14](), wav[15](), wav[16]())
|
||||
noise.octaves = 4
|
||||
noise.bias = Vector4(wav[17](), wav[18](), wav[19](), wav[20]())
|
||||
|
||||
noise.apply(emptyArray(), img)
|
||||
drawer.clear(rgb(0.20, 0.18, 0.16))
|
||||
drawer.image(img)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user