Skip to content

Commit

Permalink
Add poisson demo (#111)
Browse files Browse the repository at this point in the history
* Add poisson fill demo

* Add missing screenshot code in demo
  • Loading branch information
hamoid authored May 21, 2020
1 parent 8eae54d commit e2831dc
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 1 deletion.
18 changes: 17 additions & 1 deletion orx-poisson-fill/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
sourceSets {
demo {
java {
srcDirs = ["src/demo/kotlin"]
compileClasspath += main.getCompileClasspath()
runtimeClasspath += main.getRuntimeClasspath()
}
}
}
dependencies {
implementation project(":orx-fx")
}
implementation project(":orx-noise")

demoImplementation("org.openrndr:openrndr-core:$openrndrVersion")
demoImplementation("org.openrndr:openrndr-extensions:$openrndrVersion")
demoRuntimeOnly("org.openrndr:openrndr-gl3:$openrndrVersion")
demoRuntimeOnly("org.openrndr:openrndr-gl3-natives-$openrndrOS:$openrndrVersion")
demoImplementation(sourceSets.getByName("main").output)
}
92 changes: 92 additions & 0 deletions orx-poisson-fill/src/demo/kotlin/DemoPoissonFill01.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import org.openrndr.MouseButton
import org.openrndr.application
import org.openrndr.color.ColorHSVa
import org.openrndr.color.ColorRGBa
import org.openrndr.color.rgb
import org.openrndr.draw.ColorType
import org.openrndr.draw.colorBuffer
import org.openrndr.draw.isolatedWithTarget
import org.openrndr.draw.renderTarget
import org.openrndr.extensions.SingleScreenshot
import org.openrndr.extra.noise.Random
import org.openrndr.math.Polar
import org.openrndr.math.clamp
import org.openrndr.math.mix
import org.openrndr.poissonfill.PoissonFill
import org.openrndr.shape.Rectangle
import kotlin.math.sin

data class Thing(val color: ColorRGBa, var pos: Polar, val speed: Polar)

fun main() {
application {
program {

// -- this block is for automation purposes only
if (System.getProperty("takeScreenshot") == "true") {
extend(SingleScreenshot()) {
this.outputFile = System.getProperty("screenshotPath")
}
}

val dry = renderTarget(width, height) {
colorBuffer(type = ColorType.FLOAT32)
}
val wet = colorBuffer(width, height)

val fx = PoissonFill()

var borderOpacity = 0.0

// Create a list of things with
// color, polar position and polar speed
val things = List(10) {
Thing(
ColorHSVa(it * 182.0,
Random.double(0.3, 0.6),
Random.double(0.1, 0.9)).toRGBa(),
Polar(Random.double0(360.0),
100.0 + it * 10.0),
Polar(Random.double(-1.0, 1.0), 0.0))
}

extend {
drawer.isolatedWithTarget(dry) {
stroke = null
clear(ColorRGBa.TRANSPARENT)

// draw color circles
things.forEach { thing ->
fill = thing.color.shade(0.9 +
0.1 * sin(thing.pos.theta * 0.3))
circle(thing.pos.cartesian + bounds.center, 5.0)
// A. Use after fix in Polar.kt
//thing.pos += thing.speed
// B. temporary solution
thing.pos = Polar(thing.pos.theta +
thing.speed.theta, thing.pos.radius)
}

// draw dark gray window border.
// hold mouse button to fade in.
borderOpacity += if (MouseButton.LEFT in mouse.pressedButtons) 0.01 else -0.01
borderOpacity = borderOpacity.clamp(0.0, 1.0)
stroke = rgb(0.2).opacify(borderOpacity)
fill = null
strokeWeight = 3.0
rectangle(bounds)
}

fx.apply(dry.colorBuffer(0), wet)
drawer.image(wet)

// draw white rectangle
drawer.stroke = ColorRGBa.WHITE.opacify(0.9)
drawer.fill = null
drawer.strokeWeight = 6.0
drawer.rectangle(Rectangle.fromCenter(drawer.bounds.center,
300.0, 300.0))
}
}
}
}

0 comments on commit e2831dc

Please sign in to comment.