Skip to content

Instantly share code, notes, and snippets.

@0q98ahdsg3987y1h987y
Created January 21, 2019 14:14
Show Gist options
  • Save 0q98ahdsg3987y1h987y/0a42ac26f5c763e19f52ad6f15338d3c to your computer and use it in GitHub Desktop.
Save 0q98ahdsg3987y1h987y/0a42ac26f5c763e19f52ad6f15338d3c to your computer and use it in GitHub Desktop.
import org.openrndr.Fullscreen
import org.openrndr.KEY_SPACEBAR
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.colorBuffer
import org.openrndr.draw.isolatedWithTarget
import org.openrndr.draw.renderTarget
import org.openrndr.draw.shadeStyle
import org.openrndr.filter.blur.BoxBlur
import org.openrndr.math.Vector3
import org.openrndr.shape.Circle
import kotlin.random.Random
fun main() = application {
configure {
width = 1920
height = 1080
fullscreen = Fullscreen.SET_DISPLAY_MODE
title = "Hattie Wah Dey"
}
program {
val offscreen = renderTarget(width, height) {
colorBuffer()
depthBuffer()
}
val blur = BoxBlur()
val blurred = colorBuffer(width, height)
var currentColor = ColorRGBa.RED
var drawing = false
var rainbow = false
extend {
// Blank canvas
drawer.background(ColorRGBa.WHITE)
// Change color?
if (rainbow) {
// Rainbow baybee
currentColor = pickNewColor()
}
if (drawing) {
// Set brush radius
val r = Random.nextDouble(20.0, 30.0)
drawer.isolatedWithTarget(offscreen) {
fill = currentColor
stroke = null
circle(mouse.position, r)
}
}
blur.window = 10
blur.apply(offscreen.colorBuffer(0), blurred)
drawer.image(blurred)
drawer.stroke = null
drawer.fill = currentColor
val point = Circle(mouse.position, 10.0).contour.position((seconds) % 1.0)
drawer.circle(point, 10.0)
mouse.buttonDown.listen {
if (it.button.toString() === "RIGHT") {
drawer.shadeStyle = null
drawer.isolatedWithTarget(offscreen) {
background(ColorRGBa.WHITE)
}
} else {
drawing = true
}
}
mouse.buttonUp.listen {
drawing = false
}
keyboard.keyDown.listen {
if (it.key == KEY_SPACEBAR) {
rainbow = true
}
}
keyboard.keyUp.listen {
rainbow = false
}
}
}
}
fun pickNewColor(): ColorRGBa {
return ColorRGBa.fromVector(
Vector3(
Random.nextDouble(),
Random.nextDouble(),
Random.nextDouble()
)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment