Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add poisson demo #111

Merged
merged 2 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
}
}
}
}