-
Notifications
You must be signed in to change notification settings - Fork 37
/
FindContours04.kt
36 lines (34 loc) · 1.18 KB
/
FindContours04.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.grayscale
import org.openrndr.draw.loadImage
import org.openrndr.extra.marchingsquares.findContours
import org.openrndr.math.Vector2
import kotlin.math.PI
import kotlin.math.cos
fun main() {
application {
configure {
width = 640
height = 480
}
program {
val image = loadImage("demo-data/images/image-001.png")
image.shadow.download()
extend {
drawer.clear(ColorRGBa.BLACK)
drawer.stroke = ColorRGBa.BLACK
drawer.fill = null
fun f(v: Vector2): Double {
val iv = v.toInt()
val d = if (iv.x >= 0 && iv.y >= 0 && iv.x < image.width && iv.y < image.height) image.shadow[iv.x, iv.y].luminance else 0.0
return cos(d * PI * 8.0 + seconds)
}
val contours = findContours(::f, drawer.bounds.offsetEdges(32.0), 4.0)
drawer.drawStyle.colorMatrix = grayscale()
drawer.image(image)
drawer.contours(contours)
}
}
}
}