-
Notifications
You must be signed in to change notification settings - Fork 37
/
DemoNoClear.kt
63 lines (55 loc) · 2.4 KB
/
DemoNoClear.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import org.openrndr.application
import org.openrndr.color.ColorHSLa
import org.openrndr.color.rgb
import org.openrndr.draw.isolated
import org.openrndr.extra.noclear.NoClear
import org.openrndr.math.Polar
import org.openrndr.shape.contour
import kotlin.math.sin
fun main() {
application {
program {
var time = 0.0
// ------------------------------------------------------------
// By default OPENRNDR clears the canvas on each animation
// frame. NoClear disables that behavior, letting you
// draw on top of what you drew previously.
// That's the default in some other frameworks.
// ------------------------------------------------------------
extend(NoClear()) {
// backdrop is optional and it sets the initial state
// of the canvas. It can be a generative pattern, an image
// loaded from disk... In this case we start with dark gray.
backdrop = { drawer.clear(rgb(0.15)) }
}
extend {
// Draw something. For this demo *what* you draw is not so
// important, only the fact that it stays on the canvas
// until you draw something else on top of it.
drawer.isolated {
// center the origin
translate(bounds.center)
for(i in 0..5) {
time += 0.01
// Make a list of 4 points rotating around the center at
// different speeds
val points = List(4) {
Polar(time * (15.0 + it * 5),
250.0 * sin(time + it * 65)).cartesian
}
// Use those 4 points to create a bezier curve
val c = contour {
moveTo(points.first())
curveTo(points[1], points[2], points.last())
}
// Draw the curve with increasing hue and lightness modulation
fill = null
stroke = ColorHSLa(time * 10.0, 0.8,
0.5 + 0.2 * sin(time * 3), 0.5).toRGBa()
contour(c)
}
}
}
}
}
}