/
C340_Shade_styles005.kt
52 lines (46 loc) · 1.79 KB
/
C340_Shade_styles005.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
package examples.`30_Drawing`
import org.intellij.lang.annotations.Language
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.*
import org.openrndr.extra.camera.OrbitalCamera
import org.openrndr.extra.meshgenerators.sphereMesh
import org.openrndr.math.Vector3
import org.openrndr.shape.Circle
import kotlin.math.cos
import kotlin.math.sin
fun main() {
application {
program {
val style = shadeStyle {
// Define the `random` function and declare a `c`
// variable to pass to the fragment shader.
vertexPreamble = """
float random(vec2 st) {
return fract(sin(dot(st.xy,
vec2(12.9898, 78.233))) * 43758.5453123);
}
out vec3 c;
""".trimIndent()
// Calculate the value of `c` per vertex.
// It will get interpolated by the GPU.
vertexTransform = """
c.r = random(x_position.xy);
c.g = random(x_position.yx);
c.b = random(x_position.xy + 1.0);
""".trimIndent()
// Declare a `c` variable to receive from the vertex shader.
fragmentPreamble = "in vec3 c;"
// Use the value of `c` to set the color of a pixel.
fragmentTransform = "x_fill.rgb = c;"
}
extend {
drawer.shadeStyle = style
repeat(7) {
// Notice how we do not set `drawer.fill`.
drawer.rectangle(50.0 + it * 77, 50.0, 70.0, 390.0)
}
}
}
}
}