1+ import org.openrndr.application
2+ import org.openrndr.color.ColorRGBa
3+ import org.openrndr.draw.DrawPrimitive
4+ import org.openrndr.draw.shadeStyle
5+ import org.openrndr.extra.meshgenerators.toMesh
6+ import org.openrndr.shape.Circle
7+ import org.openrndr.shape.Rectangle
8+ import org.openrndr.shape.ShapeContour
9+
10+ /* *
11+ * Demonstrates how to convert shapes like a [Rectangle] and a [Circle]
12+ * into a vertex buffer to be drawn as a TRIANGLE_STRIP mesh.
13+ * Meshes can be drawn in 3D and deformed with vertex shaders.
14+ */
15+ fun main () = application {
16+ program {
17+ val rect = Rectangle .fromCenter(drawer.bounds.center, 350.0 ).contour
18+ val cir = Circle (drawer.bounds.center, 130.0 ).contour
19+
20+ val rectMesh = rect.toMesh(100 ) { 20.0 }
21+ val cirMesh = cir.toMesh(100 ) { 10.0 }
22+ extend {
23+ drawer.clear(ColorRGBa .PINK )
24+
25+ // Uses the texture coordinates to create an animated pattern
26+ drawer.shadeStyle = shadeStyle {
27+ fragmentTransform = """
28+ x_fill.a = step(0.5, fract(va_texCoord0.x * 10.0 + p_seconds));
29+ """ .trimIndent()
30+ parameter(" seconds" , seconds)
31+ }
32+
33+ drawer.vertexBuffer(rectMesh, DrawPrimitive .TRIANGLE_STRIP )
34+ drawer.vertexBuffer(cirMesh, DrawPrimitive .TRIANGLE_STRIP )
35+ }
36+ }
37+ }
0 commit comments