Demos: ensure 720px wide, reduce indentation
This commit is contained in:
@@ -11,34 +11,32 @@ import org.openrndr.shape.LineSegment
|
||||
* cursor are highlighted with circles and lines connecting them to the cursor.
|
||||
*
|
||||
* Key features:
|
||||
* - Generates 1000 random 2D points within the canvas dimensions (1080x720).
|
||||
* - Generates 1000 random 2D points within the canvas.
|
||||
* - Builds a KD-tree from the list of points for optimized spatial querying.
|
||||
* - Visualizes the points and highlights the 7 nearest neighbors to the user's cursor position dynamically.
|
||||
* - Highlights include red-colored circles around the nearest points and red lines connecting them to the cursor.
|
||||
*/
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 1080
|
||||
height = 720
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
}
|
||||
|
||||
program {
|
||||
val points = MutableList(1000) {
|
||||
Vector2(Math.random() * width, Math.random() * height)
|
||||
}
|
||||
val tree = points.kdTree()
|
||||
|
||||
program {
|
||||
val points = MutableList(1000) {
|
||||
Vector2(Math.random() * width, Math.random() * height)
|
||||
}
|
||||
val tree = points.kdTree()
|
||||
extend {
|
||||
drawer.circles(points, 5.0)
|
||||
|
||||
extend {
|
||||
drawer.circles(points, 5.0)
|
||||
|
||||
val kNearest = tree.findKNearest(mouse.position, k = 7)
|
||||
drawer.fill = ColorRGBa.RED
|
||||
drawer.stroke = ColorRGBa.RED
|
||||
drawer.strokeWeight = 2.0
|
||||
drawer.circles(kNearest, 7.0)
|
||||
drawer.lineSegments(kNearest.map { LineSegment(mouse.position, it) })
|
||||
}
|
||||
val kNearest = tree.findKNearest(mouse.position, k = 7)
|
||||
drawer.fill = ColorRGBa.RED
|
||||
drawer.stroke = ColorRGBa.RED
|
||||
drawer.strokeWeight = 2.0
|
||||
drawer.circles(kNearest, 7.0)
|
||||
drawer.lineSegments(kNearest.map { LineSegment(mouse.position, it) })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ import org.openrndr.extra.kdtree.kdTree
|
||||
import org.openrndr.math.Vector2
|
||||
|
||||
/**
|
||||
* Initializes an interactive graphical application that displays 1000 randomly distributed 2D points
|
||||
* on a canvas of dimensions 1280x720. The points are organized into a KD-tree for efficient spatial querying.
|
||||
* Initializes an interactive graphical application that displays 1000 randomly distributed 2D points.
|
||||
* The points are organized into a KD-tree for efficient spatial querying.
|
||||
*
|
||||
* Key functionality:
|
||||
* - Displays the points as small circles on the canvas.
|
||||
@@ -14,24 +14,22 @@ import org.openrndr.math.Vector2
|
||||
* - KD-tree structure enables efficient nearest-neighbor searches.
|
||||
* - The nearest point to the cursor is determined and visually emphasized in real-time as the cursor moves.
|
||||
*/
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 1280
|
||||
height = 720
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
}
|
||||
program {
|
||||
val points = MutableList(1000) {
|
||||
Vector2(Math.random() * width, Math.random() * height)
|
||||
}
|
||||
program {
|
||||
val points = MutableList(1000) {
|
||||
Vector2(Math.random() * width, Math.random() * height)
|
||||
}
|
||||
val tree = points.kdTree()
|
||||
extend {
|
||||
drawer.circles(points, 5.0)
|
||||
val nearest = tree.findNearest(mouse.position)
|
||||
nearest?.let {
|
||||
drawer.circle(it.x, it.y, 20.0)
|
||||
}
|
||||
val tree = points.kdTree()
|
||||
extend {
|
||||
drawer.circles(points, 5.0)
|
||||
val nearest = tree.findNearest(mouse.position)
|
||||
nearest?.let {
|
||||
drawer.circle(it.x, it.y, 20.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,40 +11,37 @@ import org.openrndr.math.Vector2
|
||||
* user's cursor position.
|
||||
*
|
||||
* Key features:
|
||||
* - Generates and displays 1000 random 2D points within canvas dimensions of 1080x720.
|
||||
* - Generates and displays 1000 random 2D points within the canvas.
|
||||
* - Builds a KD-tree structure for optimized querying of spatial data.
|
||||
* - Dynamically highlights points within a specified radius (50.0) from the cursor position.
|
||||
* - Visualizes the current query radius around the cursor as an outline circle.
|
||||
* - Uses different fill and stroke styles to distinguish highlighted points and query visuals.
|
||||
*/
|
||||
fun main() {
|
||||
application {
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
}
|
||||
|
||||
configure {
|
||||
width = 1080
|
||||
height = 720
|
||||
program {
|
||||
val points = MutableList(1000) {
|
||||
Vector2(Math.random() * width, Math.random() * height)
|
||||
}
|
||||
val tree = points.kdTree()
|
||||
val radius = 50.0
|
||||
|
||||
program {
|
||||
val points = MutableList(1000) {
|
||||
Vector2(Math.random() * width, Math.random() * height)
|
||||
}
|
||||
val tree = points.kdTree()
|
||||
val radius = 50.0
|
||||
extend {
|
||||
drawer.circles(points, 5.0)
|
||||
|
||||
extend {
|
||||
drawer.circles(points, 5.0)
|
||||
val allInRange = tree.findAllInRadius(mouse.position, radius = radius)
|
||||
drawer.fill = ColorRGBa.PINK
|
||||
drawer.stroke = ColorRGBa.PINK
|
||||
drawer.strokeWeight = 2.0
|
||||
drawer.circles(allInRange, 7.0)
|
||||
|
||||
val allInRange = tree.findAllInRadius(mouse.position, radius = radius)
|
||||
drawer.fill = ColorRGBa.PINK
|
||||
drawer.stroke = ColorRGBa.PINK
|
||||
drawer.strokeWeight = 2.0
|
||||
drawer.circles(allInRange, 7.0)
|
||||
|
||||
drawer.fill = null
|
||||
drawer.strokeWeight = 1.0
|
||||
drawer.circle(mouse.position, radius)
|
||||
}
|
||||
drawer.fill = null
|
||||
drawer.strokeWeight = 1.0
|
||||
drawer.circle(mouse.position, radius)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,21 +3,19 @@ import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.marchingsquares.findContours
|
||||
import org.openrndr.math.Vector2
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
}
|
||||
program {
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.BLACK)
|
||||
drawer.stroke = ColorRGBa.PINK
|
||||
fun f(v: Vector2) = v.distanceTo(drawer.bounds.center) - 200.0
|
||||
val contours = findContours(::f, drawer.bounds, 16.0)
|
||||
drawer.fill = null
|
||||
drawer.contours(contours)
|
||||
}
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
}
|
||||
program {
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.BLACK)
|
||||
drawer.stroke = ColorRGBa.PINK
|
||||
fun f(v: Vector2) = v.distanceTo(drawer.bounds.center) - 200.0
|
||||
val contours = findContours(::f, drawer.bounds, 16.0)
|
||||
drawer.fill = null
|
||||
drawer.contours(contours)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,21 +5,19 @@ import org.openrndr.math.Vector2
|
||||
import kotlin.math.PI
|
||||
import kotlin.math.cos
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
}
|
||||
program {
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.BLACK)
|
||||
drawer.stroke = ColorRGBa.PINK
|
||||
fun f(v: Vector2) = cos((v.distanceTo(drawer.bounds.center) / 100.0) * 2 * PI)
|
||||
val contours = findContours(::f, drawer.bounds.offsetEdges(-24.0), 16.0)
|
||||
drawer.fill = null
|
||||
drawer.contours(contours)
|
||||
}
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
}
|
||||
program {
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.BLACK)
|
||||
drawer.stroke = ColorRGBa.PINK
|
||||
fun f(v: Vector2) = cos((v.distanceTo(drawer.bounds.center) / 100.0) * 2 * PI)
|
||||
val contours = findContours(::f, drawer.bounds.offsetEdges(-24.0), 16.0)
|
||||
drawer.fill = null
|
||||
drawer.contours(contours)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,24 +6,23 @@ import kotlin.math.PI
|
||||
import kotlin.math.cos
|
||||
import kotlin.math.sin
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
}
|
||||
program {
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.BLACK)
|
||||
drawer.stroke = ColorRGBa.PINK
|
||||
drawer.fill = null
|
||||
fun f(v: Vector2): Double {
|
||||
val p = v + Vector2(cos(v.y * 0.1 + seconds) * 40.0, sin(v.x * 0.1 + seconds) * 40.0)
|
||||
return cos((p.distanceTo(drawer.bounds.center) / 720.0) * 12 * PI)
|
||||
}
|
||||
val contours = findContours(::f, drawer.bounds.offsetEdges(-2.0), 4.0)
|
||||
drawer.contours(contours)
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
}
|
||||
program {
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.BLACK)
|
||||
drawer.stroke = ColorRGBa.PINK
|
||||
drawer.fill = null
|
||||
fun f(v: Vector2): Double {
|
||||
val p = v + Vector2(cos(v.y * 0.1 + seconds) * 40.0, sin(v.x * 0.1 + seconds) * 40.0)
|
||||
return cos((p.distanceTo(drawer.bounds.center) / 720.0) * 12 * PI)
|
||||
}
|
||||
|
||||
val contours = findContours(::f, drawer.bounds.offsetEdges(-2.0), 4.0)
|
||||
drawer.contours(contours)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,30 +7,30 @@ 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)
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 540
|
||||
}
|
||||
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.scale(width.toDouble() / image.width, height.toDouble() / image.height)
|
||||
drawer.image(image)
|
||||
drawer.contours(contours)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,62 +8,62 @@ import org.openrndr.math.Vector2
|
||||
import org.openrndr.math.Vector3
|
||||
import org.openrndr.shape.Rectangle
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
multisample = WindowMultisample.SampleCount(8)
|
||||
}
|
||||
program {
|
||||
val meshes = listOf(
|
||||
boxMesh(1.0, 1.0, 1.0),
|
||||
sphereMesh(radius = 0.5),
|
||||
dodecahedronMesh(0.5),
|
||||
cylinderMesh(radius = 0.5, length = 1.0, center = true),
|
||||
planeMesh(Vector3.ZERO, Vector3.UNIT_X, Vector3.UNIT_Y),
|
||||
capMesh(
|
||||
15, 0.5,
|
||||
listOf(Vector2.ZERO, Vector2(0.5, 0.2), Vector2.UNIT_X)
|
||||
),
|
||||
revolveMesh(5, 0.5)
|
||||
)
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
multisample = WindowMultisample.SampleCount(8)
|
||||
}
|
||||
program {
|
||||
val meshes = listOf(
|
||||
boxMesh(1.0, 1.0, 1.0),
|
||||
sphereMesh(radius = 0.5),
|
||||
dodecahedronMesh(0.5),
|
||||
cylinderMesh(radius = 0.5, length = 1.0, center = true),
|
||||
planeMesh(Vector3.ZERO, Vector3.UNIT_X, Vector3.UNIT_Y),
|
||||
capMesh(
|
||||
15, 0.5,
|
||||
listOf(Vector2.ZERO, Vector2(0.5, 0.2), Vector2.UNIT_X)
|
||||
),
|
||||
revolveMesh(5, 0.5)
|
||||
)
|
||||
|
||||
val texture = colorBuffer(256, 256)
|
||||
val s = texture.shadow
|
||||
for (y in 0 until 256) {
|
||||
for (x in 0 until 256) {
|
||||
s[x, y] = ColorRGBa(x / 256.0, y / 256.0, 0.0, 1.0)
|
||||
}
|
||||
val texture = colorBuffer(256, 256)
|
||||
val s = texture.shadow
|
||||
for (y in 0 until 256) {
|
||||
for (x in 0 until 256) {
|
||||
s[x, y] = ColorRGBa(x / 256.0, y / 256.0, 0.0, 1.0)
|
||||
}
|
||||
s.upload()
|
||||
}
|
||||
s.upload()
|
||||
|
||||
val positions = Rectangle.fromCenter(Vector2.ZERO, width * 0.01, height * 0.01)
|
||||
.grid(4, 2).flatten().map {
|
||||
it.center.vector3(z = -5.0)
|
||||
}
|
||||
val positions = Rectangle.fromCenter(Vector2.ZERO, width * 0.01, height * 0.01)
|
||||
.grid(4, 2).flatten().map {
|
||||
it.center.vector3(z = -5.0)
|
||||
}
|
||||
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.PINK)
|
||||
drawer.perspective(60.0, width * 1.0 / height, 0.01, 1000.0)
|
||||
drawer.depthWrite = true
|
||||
drawer.depthTestPass = DepthTestPass.LESS_OR_EQUAL
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.PINK)
|
||||
drawer.perspective(60.0, width * 1.0 / height, 0.01, 1000.0)
|
||||
drawer.depthWrite = true
|
||||
drawer.depthTestPass = DepthTestPass.LESS_OR_EQUAL
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """
|
||||
float light = dot(v_worldNormal, p_light) * 0.5 + 0.5;
|
||||
x_fill = texture(p_texture, va_texCoord0.xy);
|
||||
x_fill.rgb *= light;
|
||||
""".trimIndent()
|
||||
parameter("texture", texture)
|
||||
parameter("light", Vector3(1.0).normalized)
|
||||
}
|
||||
meshes.forEachIndexed { i, mesh ->
|
||||
drawer.isolated {
|
||||
translate(positions[i])
|
||||
rotate(Vector3.UNIT_Y, seconds * 12)
|
||||
rotate(Vector3.UNIT_X, seconds * 25)
|
||||
vertexBuffer(mesh, DrawPrimitive.TRIANGLES)
|
||||
}
|
||||
parameter("texture", texture)
|
||||
parameter("light", Vector3(1.0).normalized)
|
||||
}
|
||||
meshes.forEachIndexed { i, mesh ->
|
||||
drawer.isolated {
|
||||
translate(positions[i])
|
||||
rotate(Vector3.UNIT_Y, seconds * 12)
|
||||
rotate(Vector3.UNIT_X, seconds * 25)
|
||||
vertexBuffer(mesh, DrawPrimitive.TRIANGLES)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,37 +9,37 @@ import org.openrndr.extra.camera.Orbital
|
||||
import org.openrndr.extra.meshgenerators.boxMesh
|
||||
import org.openrndr.math.Vector3
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
multisample = WindowMultisample.SampleCount(8)
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
multisample = WindowMultisample.SampleCount(8)
|
||||
}
|
||||
program {
|
||||
val box = boxMesh(1.0, 1.0, 1.0)
|
||||
|
||||
val texture = colorBuffer(256, 256)
|
||||
val s = texture.shadow
|
||||
for (y in 0 until 256) {
|
||||
for (x in 0 until 256) {
|
||||
s[x, y] = ColorRGBa(x / 256.0, y / 256.0, 0.0, 1.0)
|
||||
}
|
||||
}
|
||||
program {
|
||||
val box = boxMesh(1.0, 1.0, 1.0)
|
||||
s.upload()
|
||||
|
||||
val texture = colorBuffer(256, 256)
|
||||
val s = texture.shadow
|
||||
for (y in 0 until 256) {
|
||||
for (x in 0 until 256) {
|
||||
s[x, y] = ColorRGBa(x/256.0, y/256.0, 0.0, 1.0)
|
||||
}
|
||||
}
|
||||
s.upload()
|
||||
|
||||
extend(Orbital()) {
|
||||
eye = Vector3(1.0, 1.0, 1.0)
|
||||
}
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.PINK)
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """
|
||||
extend(Orbital()) {
|
||||
eye = Vector3(1.0, 1.0, 1.0)
|
||||
}
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.PINK)
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """
|
||||
x_fill = texture(p_texture, va_texCoord0.xy);
|
||||
""".trimIndent()
|
||||
parameter("texture", texture)
|
||||
}
|
||||
drawer.drawStyle.cullTestPass = CullTestPass.FRONT
|
||||
drawer.vertexBuffer(box, DrawPrimitive.TRIANGLES)
|
||||
parameter("texture", texture)
|
||||
}
|
||||
drawer.drawStyle.cullTestPass = CullTestPass.FRONT
|
||||
drawer.vertexBuffer(box, DrawPrimitive.TRIANGLES)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,38 +9,36 @@ import org.openrndr.extra.meshgenerators.buildTriangleMesh
|
||||
import org.openrndr.extra.meshgenerators.sphere
|
||||
import org.openrndr.math.Vector3
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 800
|
||||
height = 800
|
||||
multisample = WindowMultisample.SampleCount(8)
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
multisample = WindowMultisample.SampleCount(8)
|
||||
}
|
||||
program {
|
||||
val m = buildTriangleMesh {
|
||||
color = ColorRGBa.PINK
|
||||
sphere(32, 32, 1.0)
|
||||
|
||||
color = ColorRGBa.WHITE
|
||||
translate(0.0, -2.0, 0.0)
|
||||
box(4.0, 4.0, 4.0)
|
||||
|
||||
}
|
||||
program {
|
||||
val m = buildTriangleMesh {
|
||||
color = ColorRGBa.PINK
|
||||
sphere(32, 32, 1.0)
|
||||
|
||||
color = ColorRGBa.WHITE
|
||||
translate(0.0, -2.0, 0.0)
|
||||
box(4.0, 4.0, 4.0)
|
||||
extend(Orbital()) {
|
||||
this.eye = Vector3(0.0, 3.0, 7.0)
|
||||
this.lookAt = Vector3(0.0, 2.0, 0.0)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extend(Orbital()) {
|
||||
this.eye = Vector3(0.0, 3.0, 7.0)
|
||||
this.lookAt = Vector3(0.0, 2.0, 0.0)
|
||||
}
|
||||
|
||||
extend {
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """
|
||||
extend {
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """
|
||||
x_fill = va_color;
|
||||
x_fill.rgb *= v_viewNormal.z;
|
||||
""".trimIndent()
|
||||
}
|
||||
drawer.vertexBuffer(m, DrawPrimitive.TRIANGLES)
|
||||
}
|
||||
drawer.vertexBuffer(m, DrawPrimitive.TRIANGLES)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,60 +8,58 @@ import org.openrndr.extra.meshgenerators.cylinder
|
||||
import org.openrndr.extra.meshgenerators.hemisphere
|
||||
import org.openrndr.math.Vector3
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 800
|
||||
height = 800
|
||||
multisample = WindowMultisample.SampleCount(8)
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
multisample = WindowMultisample.SampleCount(8)
|
||||
}
|
||||
program {
|
||||
extend(Orbital()) {
|
||||
this.eye = Vector3(0.0, 10.0, 20.0)
|
||||
this.lookAt = Vector3(0.0, 5.0, 0.0)
|
||||
}
|
||||
program {
|
||||
extend(Orbital()) {
|
||||
this.eye = Vector3(0.0, 10.0, 20.0)
|
||||
this.lookAt = Vector3(0.0, 5.0, 0.0)
|
||||
val m = buildTriangleMesh {
|
||||
isolated {
|
||||
translate(0.0, 12.0, 0.0)
|
||||
hemisphere(32, 16, 5.0)
|
||||
}
|
||||
val m = buildTriangleMesh {
|
||||
isolated {
|
||||
translate(0.0, 12.0, 0.0)
|
||||
hemisphere(32, 16, 5.0)
|
||||
}
|
||||
|
||||
isolated {
|
||||
translate(0.0, 9.0, 0.0)
|
||||
rotate(Vector3.UNIT_X, 90.0)
|
||||
cylinder(32, 1, 5.0, 6.0, center = true)
|
||||
}
|
||||
isolated {
|
||||
translate(0.0, 6.0, 0.0)
|
||||
rotate(Vector3.UNIT_X, 180.0)
|
||||
hemisphere(32, 16, 5.0)
|
||||
}
|
||||
isolated {
|
||||
val legCount = 12
|
||||
val baseRadius = 3.0
|
||||
val legRadius = 0.05
|
||||
val legLength = 4.0
|
||||
for (i in 0 until legCount) {
|
||||
isolated {
|
||||
val dphi = 360.0 / legCount
|
||||
rotate(Vector3.UNIT_Y, dphi * i)
|
||||
translate(baseRadius, 0.0, 0.0)
|
||||
rotate(Vector3.UNIT_Z, -15.0)
|
||||
translate(0.0, legLength / 2.0, 0.0)
|
||||
rotate(Vector3.UNIT_X, 90.0)
|
||||
cylinder(32, 1, legRadius, legLength, center = true)
|
||||
}
|
||||
isolated {
|
||||
translate(0.0, 9.0, 0.0)
|
||||
rotate(Vector3.UNIT_X, 90.0)
|
||||
cylinder(32, 1, 5.0, 6.0, center = true)
|
||||
}
|
||||
isolated {
|
||||
translate(0.0, 6.0, 0.0)
|
||||
rotate(Vector3.UNIT_X, 180.0)
|
||||
hemisphere(32, 16, 5.0)
|
||||
}
|
||||
isolated {
|
||||
val legCount = 12
|
||||
val baseRadius = 3.0
|
||||
val legRadius = 0.05
|
||||
val legLength = 4.0
|
||||
for (i in 0 until legCount) {
|
||||
isolated {
|
||||
val dphi = 360.0 / legCount
|
||||
rotate(Vector3.UNIT_Y, dphi * i)
|
||||
translate(baseRadius, 0.0, 0.0)
|
||||
rotate(Vector3.UNIT_Z, -15.0)
|
||||
translate(0.0, legLength / 2.0, 0.0)
|
||||
rotate(Vector3.UNIT_X, 90.0)
|
||||
cylinder(32, 1, legRadius, legLength, center = true)
|
||||
}
|
||||
}
|
||||
}
|
||||
extend {
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """
|
||||
}
|
||||
extend {
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """
|
||||
x_fill.rgb *= v_viewNormal.z;
|
||||
""".trimIndent()
|
||||
}
|
||||
drawer.vertexBuffer(m, DrawPrimitive.TRIANGLES)
|
||||
}
|
||||
drawer.vertexBuffer(m, DrawPrimitive.TRIANGLES)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,78 +6,80 @@ import org.openrndr.extra.camera.Orbital
|
||||
import org.openrndr.extra.meshgenerators.*
|
||||
import org.openrndr.math.Vector3
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 800
|
||||
height = 800
|
||||
multisample = WindowMultisample.SampleCount(8)
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
multisample = WindowMultisample.SampleCount(8)
|
||||
}
|
||||
program {
|
||||
extend(Orbital()) {
|
||||
this.eye = Vector3(0.0, 10.0, 20.0)
|
||||
this.lookAt = Vector3(0.0, 5.0, 0.0)
|
||||
}
|
||||
program {
|
||||
extend(Orbital()) {
|
||||
this.eye = Vector3(0.0, 10.0, 20.0)
|
||||
this.lookAt = Vector3(0.0, 5.0, 0.0)
|
||||
val m = buildTriangleMesh {
|
||||
isolated {
|
||||
translate(0.0, 12.0, 0.0)
|
||||
hemisphere(32, 16, 5.0)
|
||||
}
|
||||
val m = buildTriangleMesh {
|
||||
|
||||
val ridges = 5
|
||||
val midLength = 6.0
|
||||
val ridgeLength = midLength / ridges
|
||||
val ridgeRadius = 5.5
|
||||
|
||||
for (r in 0 until ridges) {
|
||||
isolated {
|
||||
translate(0.0, 12.0, 0.0)
|
||||
hemisphere(32, 16, 5.0)
|
||||
translate(
|
||||
0.0,
|
||||
ridgeLength / 4.0 + r * ridgeLength + 6.0,
|
||||
0.0
|
||||
)
|
||||
rotate(Vector3.UNIT_X, 270.0)
|
||||
taperedCylinder(32, 1, 5.0, ridgeRadius, ridgeLength / 2.0, center = true)
|
||||
}
|
||||
|
||||
val ridges = 5
|
||||
val midLength = 6.0
|
||||
val ridgeLength = midLength / ridges
|
||||
val ridgeRadius = 5.5
|
||||
|
||||
for (r in 0 until ridges) {
|
||||
isolated {
|
||||
translate(
|
||||
0.0,
|
||||
ridgeLength / 4.0 + ridgeLength / 2.0 + r * ridgeLength + 6.0,
|
||||
0.0
|
||||
)
|
||||
rotate(Vector3.UNIT_X, 270.0)
|
||||
taperedCylinder(32, 1, ridgeRadius, 5.0, ridgeLength / 2.0, center = true)
|
||||
}
|
||||
}
|
||||
isolated {
|
||||
translate(0.0, 6.0, 0.0)
|
||||
rotate(Vector3.UNIT_X, 180.0)
|
||||
hemisphere(32, 16, 5.0)
|
||||
}
|
||||
isolated {
|
||||
val legCount = 12
|
||||
val baseRadius = 3.0
|
||||
val legRadius = 0.05
|
||||
val legLength = 4.0
|
||||
for (i in 0 until legCount) {
|
||||
isolated {
|
||||
translate(0.0,
|
||||
ridgeLength/4.0 + r * ridgeLength + 6.0,
|
||||
0.0)
|
||||
rotate(Vector3.UNIT_X, 270.0)
|
||||
taperedCylinder(32, 1, 5.0, ridgeRadius, ridgeLength/ 2.0, center = true)
|
||||
}
|
||||
|
||||
isolated {
|
||||
translate(0.0,
|
||||
ridgeLength/4.0 + ridgeLength/2.0 + r * ridgeLength + 6.0,
|
||||
0.0)
|
||||
rotate(Vector3.UNIT_X, 270.0)
|
||||
taperedCylinder(32, 1, ridgeRadius, 5.0, ridgeLength/2.0, center = true)
|
||||
}
|
||||
}
|
||||
isolated {
|
||||
translate(0.0, 6.0, 0.0)
|
||||
rotate(Vector3.UNIT_X, 180.0)
|
||||
hemisphere(32, 16, 5.0)
|
||||
}
|
||||
isolated {
|
||||
val legCount = 12
|
||||
val baseRadius = 3.0
|
||||
val legRadius = 0.05
|
||||
val legLength = 4.0
|
||||
for (i in 0 until legCount) {
|
||||
isolated {
|
||||
val dphi = 360.0 / legCount
|
||||
rotate(Vector3.UNIT_Y, dphi * i)
|
||||
translate(baseRadius, 0.0, 0.0)
|
||||
rotate(Vector3.UNIT_Z, -15.0)
|
||||
translate(0.0, legLength/2.0, 0.0)
|
||||
rotate(Vector3.UNIT_X, 90.0)
|
||||
cylinder(32, 1, legRadius, legLength, center = true)
|
||||
}
|
||||
val dphi = 360.0 / legCount
|
||||
rotate(Vector3.UNIT_Y, dphi * i)
|
||||
translate(baseRadius, 0.0, 0.0)
|
||||
rotate(Vector3.UNIT_Z, -15.0)
|
||||
translate(0.0, legLength / 2.0, 0.0)
|
||||
rotate(Vector3.UNIT_X, 90.0)
|
||||
cylinder(32, 1, legRadius, legLength, center = true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extend {
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """
|
||||
extend {
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """
|
||||
x_fill.rgb *= v_viewNormal.z;
|
||||
""".trimIndent()
|
||||
}
|
||||
drawer.vertexBuffer(m, DrawPrimitive.TRIANGLES)
|
||||
}
|
||||
drawer.vertexBuffer(m, DrawPrimitive.TRIANGLES)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,98 +7,98 @@ import org.openrndr.extra.meshgenerators.*
|
||||
import org.openrndr.math.Vector2
|
||||
import org.openrndr.math.Vector3
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 800
|
||||
height = 800
|
||||
multisample = WindowMultisample.SampleCount(8)
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
multisample = WindowMultisample.SampleCount(8)
|
||||
}
|
||||
program {
|
||||
extend(Orbital()) {
|
||||
this.eye = Vector3(0.0, 15.0, 15.0)
|
||||
}
|
||||
program {
|
||||
extend(Orbital()) {
|
||||
this.eye = Vector3(0.0, 15.0, 15.0)
|
||||
}
|
||||
|
||||
val m = buildTriangleMesh {
|
||||
val sides = 12
|
||||
isolated {
|
||||
translate(0.0, 12.0, 0.0)
|
||||
cap(sides, 5.0, listOf(
|
||||
Vector2(0.0, 1.0),
|
||||
Vector2(0.5, 1.0),
|
||||
Vector2(0.5, 0.5),
|
||||
Vector2(0.9, 0.5),
|
||||
Vector2(1.0, 0.0))
|
||||
val m = buildTriangleMesh {
|
||||
val sides = 12
|
||||
isolated {
|
||||
translate(0.0, 12.0, 0.0)
|
||||
cap(
|
||||
sides, 5.0, listOf(
|
||||
Vector2(0.0, 1.0),
|
||||
Vector2(0.5, 1.0),
|
||||
Vector2(0.5, 0.5),
|
||||
Vector2(0.9, 0.5),
|
||||
Vector2(1.0, 0.0)
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
val ridges = 5
|
||||
val midLength = 6.0
|
||||
val ridgeLength = midLength / ridges
|
||||
val ridgeRadius = 5.5
|
||||
val ridges = 5
|
||||
val midLength = 6.0
|
||||
val ridgeLength = midLength / ridges
|
||||
val ridgeRadius = 5.5
|
||||
|
||||
|
||||
for (r in 0 until ridges) {
|
||||
isolated {
|
||||
translate(
|
||||
0.0,
|
||||
ridgeLength / 6.0 + r * ridgeLength + 6.0,
|
||||
0.0
|
||||
)
|
||||
rotate(Vector3.UNIT_X, 270.0)
|
||||
taperedCylinder(sides, 1, 5.0, ridgeRadius, ridgeLength / 3.0, center = true)
|
||||
}
|
||||
isolated {
|
||||
translate(
|
||||
0.0,
|
||||
ridgeLength / 6.0 + ridgeLength / 3.0 + r * ridgeLength + 6.0,
|
||||
0.0
|
||||
)
|
||||
rotate(Vector3.UNIT_X, 270.0)
|
||||
taperedCylinder(sides, 1, ridgeRadius, ridgeRadius, ridgeLength / 3.0, center = true)
|
||||
}
|
||||
|
||||
isolated {
|
||||
translate(
|
||||
0.0,
|
||||
ridgeLength / 6.0 + 2 * ridgeLength / 3.0 + r * ridgeLength + 6.0,
|
||||
0.0
|
||||
)
|
||||
rotate(Vector3.UNIT_X, 270.0)
|
||||
taperedCylinder(sides, 1, ridgeRadius, 5.0, ridgeLength / 3.0, center = true)
|
||||
}
|
||||
for (r in 0 until ridges) {
|
||||
isolated {
|
||||
translate(
|
||||
0.0,
|
||||
ridgeLength / 6.0 + r * ridgeLength + 6.0,
|
||||
0.0
|
||||
)
|
||||
rotate(Vector3.UNIT_X, 270.0)
|
||||
taperedCylinder(sides, 1, 5.0, ridgeRadius, ridgeLength / 3.0, center = true)
|
||||
}
|
||||
isolated {
|
||||
translate(0.0, 6.0, 0.0)
|
||||
rotate(Vector3.UNIT_X, 180.0)
|
||||
cap(sides, 5.0, listOf(Vector2(0.0, 0.0), Vector2(1.0, 0.0)))
|
||||
translate(
|
||||
0.0,
|
||||
ridgeLength / 6.0 + ridgeLength / 3.0 + r * ridgeLength + 6.0,
|
||||
0.0
|
||||
)
|
||||
rotate(Vector3.UNIT_X, 270.0)
|
||||
taperedCylinder(sides, 1, ridgeRadius, ridgeRadius, ridgeLength / 3.0, center = true)
|
||||
}
|
||||
|
||||
isolated {
|
||||
val legCount = 12
|
||||
val baseRadius = 4.5
|
||||
val legRadius = 0.05
|
||||
val legLength = 7.0
|
||||
for (i in 0 until legCount) {
|
||||
isolated {
|
||||
val dphi = 360.0 / legCount
|
||||
rotate(Vector3.UNIT_Y, dphi * i)
|
||||
translate(baseRadius, 0.0, 0.0)
|
||||
translate(0.0, legLength / 2.0, 0.0)
|
||||
rotate(Vector3.UNIT_X, 90.0)
|
||||
cylinder(sides, 1, legRadius, legLength, center = true)
|
||||
}
|
||||
translate(
|
||||
0.0,
|
||||
ridgeLength / 6.0 + 2 * ridgeLength / 3.0 + r * ridgeLength + 6.0,
|
||||
0.0
|
||||
)
|
||||
rotate(Vector3.UNIT_X, 270.0)
|
||||
taperedCylinder(sides, 1, ridgeRadius, 5.0, ridgeLength / 3.0, center = true)
|
||||
}
|
||||
}
|
||||
isolated {
|
||||
translate(0.0, 6.0, 0.0)
|
||||
rotate(Vector3.UNIT_X, 180.0)
|
||||
cap(sides, 5.0, listOf(Vector2(0.0, 0.0), Vector2(1.0, 0.0)))
|
||||
}
|
||||
isolated {
|
||||
val legCount = 12
|
||||
val baseRadius = 4.5
|
||||
val legRadius = 0.05
|
||||
val legLength = 7.0
|
||||
for (i in 0 until legCount) {
|
||||
isolated {
|
||||
val dphi = 360.0 / legCount
|
||||
rotate(Vector3.UNIT_Y, dphi * i)
|
||||
translate(baseRadius, 0.0, 0.0)
|
||||
translate(0.0, legLength / 2.0, 0.0)
|
||||
rotate(Vector3.UNIT_X, 90.0)
|
||||
cylinder(sides, 1, legRadius, legLength, center = true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extend {
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """
|
||||
extend {
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """
|
||||
x_fill.rgb *= v_viewNormal.z;
|
||||
""".trimIndent()
|
||||
}
|
||||
drawer.vertexBuffer(m, DrawPrimitive.TRIANGLES)
|
||||
}
|
||||
drawer.vertexBuffer(m, DrawPrimitive.TRIANGLES)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,38 +11,36 @@ import org.openrndr.extra.meshgenerators.twist
|
||||
import org.openrndr.math.Vector3
|
||||
import org.openrndr.shape.Circle
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 800
|
||||
height = 800
|
||||
multisample = WindowMultisample.SampleCount(8)
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
multisample = WindowMultisample.SampleCount(8)
|
||||
}
|
||||
program {
|
||||
extend(Orbital()) {
|
||||
this.eye = Vector3(0.0, 30.0, 50.0)
|
||||
}
|
||||
program {
|
||||
extend(Orbital()) {
|
||||
this.eye = Vector3(0.0, 30.0, 50.0)
|
||||
}
|
||||
val m = buildTriangleMesh {
|
||||
grid(5, 5, 5) { u, v, w ->
|
||||
isolated {
|
||||
translate(u * 20.0, v * 20.0, w * 20.0)
|
||||
extrudeShape(Circle(0.0, 0.0, 50.0).shape, 4.0, scale = 0.1)
|
||||
}
|
||||
val m = buildTriangleMesh {
|
||||
grid(5, 5, 5) { u, v, w ->
|
||||
isolated {
|
||||
translate(u * 20.0, v * 20.0, w * 20.0)
|
||||
extrudeShape(Circle(0.0, 0.0, 50.0).shape, 4.0, scale = 0.1)
|
||||
}
|
||||
twist(360.0 / 200.0, 0.0)
|
||||
twist(360.0 / 200.0, 0.0, Vector3.UNIT_X)
|
||||
twist(360.0 / 200.0, 0.0, Vector3.UNIT_Z)
|
||||
}
|
||||
twist(360.0 / 200.0, 0.0)
|
||||
twist(360.0 / 200.0, 0.0, Vector3.UNIT_X)
|
||||
twist(360.0 / 200.0, 0.0, Vector3.UNIT_Z)
|
||||
}
|
||||
|
||||
extend {
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """
|
||||
extend {
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """
|
||||
x_fill.rgb *= v_viewNormal.z;
|
||||
""".trimIndent()
|
||||
}
|
||||
drawer.drawStyle.cullTestPass = CullTestPass.FRONT
|
||||
drawer.vertexBuffer(m, DrawPrimitive.TRIANGLES)
|
||||
}
|
||||
drawer.drawStyle.cullTestPass = CullTestPass.FRONT
|
||||
drawer.vertexBuffer(m, DrawPrimitive.TRIANGLES)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,50 +13,48 @@ import org.openrndr.math.Vector3
|
||||
* Interactive orbital camera.
|
||||
*
|
||||
*/
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 800
|
||||
height = 800
|
||||
multisample = WindowMultisample.SampleCount(8)
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
multisample = WindowMultisample.SampleCount(8)
|
||||
}
|
||||
program {
|
||||
extend(Orbital()) {
|
||||
this.eye = Vector3(3.0, 3.0, 10.0)
|
||||
this.fov = 60.0
|
||||
}
|
||||
program {
|
||||
extend(Orbital()) {
|
||||
this.eye = Vector3(3.0, 3.0, 10.0)
|
||||
this.fov = 60.0
|
||||
}
|
||||
val m = buildTriangleMesh {
|
||||
grid(5, 5) { u, v ->
|
||||
isolated {
|
||||
grid(3, 3, 3, GridCoordinates.UNIPOLAR) { x, y, z ->
|
||||
val pos0 = Vector3(u, v, 0.0) * 10.0
|
||||
val pos1 = Vector3(x, y, z) * 2.0
|
||||
val pos2 = pos0 + pos1 + Vector3(
|
||||
y * 0.12 + z * 0.3,
|
||||
x * 0.14 + z * 0.15,
|
||||
x * 0.16 + y * 0.17
|
||||
)
|
||||
// Drop some boxes
|
||||
if(simplex(0, pos1 * 0.5 + pos0 * 0.05) > 0) {
|
||||
translate(pos2)
|
||||
color = rgb(x, y, z)
|
||||
box(1.2, 1.2, 1.2)
|
||||
}
|
||||
val m = buildTriangleMesh {
|
||||
grid(5, 5) { u, v ->
|
||||
isolated {
|
||||
grid(3, 3, 3, GridCoordinates.UNIPOLAR) { x, y, z ->
|
||||
val pos0 = Vector3(u, v, 0.0) * 10.0
|
||||
val pos1 = Vector3(x, y, z) * 2.0
|
||||
val pos2 = pos0 + pos1 + Vector3(
|
||||
y * 0.12 + z * 0.3,
|
||||
x * 0.14 + z * 0.15,
|
||||
x * 0.16 + y * 0.17
|
||||
)
|
||||
// Drop some boxes
|
||||
if (simplex(0, pos1 * 0.5 + pos0 * 0.05) > 0) {
|
||||
translate(pos2)
|
||||
color = rgb(x, y, z)
|
||||
box(1.2, 1.2, 1.2)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extend {
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """
|
||||
extend {
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """
|
||||
x_fill = va_color;
|
||||
vec3 s = sin(v_worldPosition.xyz * 2.5);
|
||||
x_fill.rgb += s * 0.1 - 0.1;
|
||||
""".trimIndent()
|
||||
}
|
||||
drawer.vertexBuffer(m, DrawPrimitive.TRIANGLES)
|
||||
}
|
||||
drawer.vertexBuffer(m, DrawPrimitive.TRIANGLES)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,57 +11,55 @@ import org.openrndr.extra.shapes.splines.toPath3D
|
||||
import org.openrndr.math.Vector3
|
||||
import org.openrndr.shape.Circle
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 800
|
||||
height = 800
|
||||
multisample = WindowMultisample.SampleCount(8)
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
multisample = WindowMultisample.SampleCount(8)
|
||||
}
|
||||
program {
|
||||
val m = buildTriangleMesh {
|
||||
color = ColorRGBa.PINK
|
||||
|
||||
val path = listOf(
|
||||
Vector3(0.0, 0.0, 0.0),
|
||||
Vector3(-2.0, 2.0, 2.0),
|
||||
Vector3(2.0, -4.0, 4.0),
|
||||
Vector3(0.0, 0.0, 8.0)
|
||||
).catmullRom(0.5, closed = false).toPath3D()
|
||||
|
||||
|
||||
translate(-1.0, 0.0, 0.0)
|
||||
|
||||
for (i in 0 until 3) {
|
||||
extrudeContourSteps(
|
||||
Circle(0.0, 0.0, 0.5).contour,
|
||||
path,
|
||||
160,
|
||||
Vector3.UNIT_Y,
|
||||
contourDistanceTolerance = 0.02,
|
||||
pathDistanceTolerance = 0.001
|
||||
)
|
||||
translate(1.0, 0.0, 0.0)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
program {
|
||||
val m = buildTriangleMesh {
|
||||
color = ColorRGBa.PINK
|
||||
|
||||
val path = listOf(
|
||||
Vector3(0.0, 0.0, 0.0),
|
||||
Vector3(-2.0, 2.0, 2.0),
|
||||
Vector3(2.0, -4.0, 4.0),
|
||||
Vector3(0.0, 0.0, 8.0)
|
||||
).catmullRom(0.5, closed = false).toPath3D()
|
||||
extend(Orbital()) {
|
||||
this.eye = Vector3(0.0, 3.0, 7.0)
|
||||
this.lookAt = Vector3(0.0, 2.0, 0.0)
|
||||
}
|
||||
|
||||
|
||||
translate(-1.0, 0.0, 0.0)
|
||||
|
||||
for (i in 0 until 3) {
|
||||
extrudeContourSteps(
|
||||
Circle(0.0, 0.0, 0.5).contour,
|
||||
path,
|
||||
160,
|
||||
Vector3.UNIT_Y,
|
||||
contourDistanceTolerance = 0.02,
|
||||
pathDistanceTolerance = 0.001
|
||||
)
|
||||
translate(1.0, 0.0, 0.0)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
extend(Orbital()) {
|
||||
this.eye = Vector3(0.0, 3.0, 7.0)
|
||||
this.lookAt = Vector3(0.0, 2.0, 0.0)
|
||||
}
|
||||
|
||||
extend {
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """
|
||||
extend {
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """
|
||||
x_fill = va_color;
|
||||
x_fill.rgb *= v_viewNormal.z;
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
drawer.vertexBuffer(m, DrawPrimitive.TRIANGLES)
|
||||
}
|
||||
|
||||
drawer.vertexBuffer(m, DrawPrimitive.TRIANGLES)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,60 +12,56 @@ import org.openrndr.math.Vector3
|
||||
import org.openrndr.shape.Circle
|
||||
import org.openrndr.shape.Shape
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 800
|
||||
height = 800
|
||||
multisample = WindowMultisample.SampleCount(8)
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
multisample = WindowMultisample.SampleCount(8)
|
||||
}
|
||||
program {
|
||||
val m = buildTriangleMesh {
|
||||
color = ColorRGBa.PINK
|
||||
|
||||
val path = listOf(
|
||||
Vector3(0.0, 0.0, 0.0),
|
||||
Vector3(-2.0, 2.0, 2.0),
|
||||
Vector3(2.0, -4.0, 4.0),
|
||||
Vector3(0.0, 0.0, 8.0)
|
||||
).catmullRom(0.5, closed = false).toPath3D()
|
||||
|
||||
|
||||
translate(-5.0, 0.0, 0.0)
|
||||
|
||||
|
||||
val ring = Shape(listOf(Circle(0.0, 0.0, 0.5).contour, Circle(0.0, 0.0, 0.25).contour.reversed))
|
||||
|
||||
for (i in 0 until 5) {
|
||||
extrudeShapeSteps(
|
||||
ring,
|
||||
path,
|
||||
160,
|
||||
Vector3.UNIT_Y,
|
||||
contourDistanceTolerance = 0.02,
|
||||
pathDistanceTolerance = 0.001
|
||||
)
|
||||
translate(2.0, 0.0, 0.0)
|
||||
}
|
||||
}
|
||||
program {
|
||||
val m = buildTriangleMesh {
|
||||
color = ColorRGBa.PINK
|
||||
|
||||
val path = listOf(
|
||||
Vector3(0.0, 0.0, 0.0),
|
||||
Vector3(-2.0, 2.0, 2.0),
|
||||
Vector3(2.0, -4.0, 4.0),
|
||||
Vector3(0.0, 0.0, 8.0)
|
||||
).catmullRom(0.5, closed = false).toPath3D()
|
||||
extend(Orbital()) {
|
||||
this.eye = Vector3(0.0, 3.0, 7.0)
|
||||
this.lookAt = Vector3(0.0, 2.0, 0.0)
|
||||
}
|
||||
|
||||
|
||||
translate(-5.0, 0.0, 0.0)
|
||||
|
||||
|
||||
val ring = Shape(listOf(Circle(0.0, 0.0, 0.5).contour, Circle(0.0, 0.0, 0.25).contour.reversed))
|
||||
|
||||
for (i in 0 until 5) {
|
||||
extrudeShapeSteps(
|
||||
ring,
|
||||
path,
|
||||
160,
|
||||
Vector3.UNIT_Y,
|
||||
contourDistanceTolerance = 0.02,
|
||||
pathDistanceTolerance = 0.001
|
||||
)
|
||||
translate(2.0, 0.0, 0.0)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
extend(Orbital()) {
|
||||
this.eye = Vector3(0.0, 3.0, 7.0)
|
||||
this.lookAt = Vector3(0.0, 2.0, 0.0)
|
||||
}
|
||||
|
||||
extend {
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """
|
||||
extend {
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """
|
||||
x_fill = va_color;
|
||||
x_fill.rgb *= v_viewNormal.z;
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
drawer.vertexBuffer(m, DrawPrimitive.TRIANGLES)
|
||||
}
|
||||
|
||||
drawer.vertexBuffer(m, DrawPrimitive.TRIANGLES)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,82 +15,76 @@ import org.openrndr.shape.Path3D
|
||||
import kotlin.math.PI
|
||||
import kotlin.math.exp
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 800
|
||||
height = 800
|
||||
multisample = WindowMultisample.SampleCount(8)
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
multisample = WindowMultisample.SampleCount(8)
|
||||
}
|
||||
program {
|
||||
fun spiralPath(a: Double, k: Double, cycles: Double, steps: Int, direction: Double = 1.0): Path3D {
|
||||
val points = (0 until steps).map {
|
||||
|
||||
val theta = ((PI * 2.0 * cycles) / steps) * it
|
||||
val radius = a * exp(k * theta)
|
||||
|
||||
val c = Polar(theta.asDegrees, radius).cartesian
|
||||
c.xy0
|
||||
}
|
||||
return Path3D.fromPoints(points, false)
|
||||
}
|
||||
program {
|
||||
fun spiralPath(a: Double, k: Double, cycles: Double, steps: Int, direction:Double = 1.0): Path3D {
|
||||
val points = (0 until steps).map {
|
||||
|
||||
val theta = ((PI * 2.0 * cycles) / steps) * it
|
||||
val radius = a * exp(k * theta)
|
||||
val spiral = buildTriangleMesh {
|
||||
for (i in -1..1 step 2) {
|
||||
val p = spiralPath(0.2 * i, 0.25, 4.0, 400)
|
||||
|
||||
val c = Polar(theta.asDegrees, radius).cartesian
|
||||
c.xy0
|
||||
}
|
||||
return Path3D.fromPoints(points, false)
|
||||
extrudeContourAdaptive(
|
||||
Circle(0.0, 0.0, 0.1).contour,
|
||||
p,
|
||||
Vector3.UNIT_Z,
|
||||
contourDistanceTolerance = 0.02,
|
||||
pathDistanceTolerance = 0.001
|
||||
)
|
||||
}
|
||||
|
||||
val spiral = buildTriangleMesh {
|
||||
for (i in -1..1 step 2) {
|
||||
val p = spiralPath(0.2 * i, 0.25, 4.0, 400)
|
||||
isolated {
|
||||
color = ColorRGBa.YELLOW
|
||||
rotate(Vector3.UNIT_X, 90.0)
|
||||
|
||||
extrudeContourAdaptive(
|
||||
Circle(0.0, 0.0, 0.1).contour,
|
||||
p,
|
||||
Vector3.UNIT_Z,
|
||||
contourDistanceTolerance = 0.02,
|
||||
pathDistanceTolerance = 0.001
|
||||
)
|
||||
}
|
||||
//rotate(Vector3.UNIT_Y, 45.0)
|
||||
for (j in 0 until 1) {
|
||||
for (i in -1..1 step 2) {
|
||||
|
||||
isolated {
|
||||
color = ColorRGBa.YELLOW
|
||||
rotate(Vector3.UNIT_X, 90.0)
|
||||
val rotationDegrees = j * 180.0 / 1.0
|
||||
val rotation = rotationDegrees.asRadians
|
||||
val scale = exp(rotation * 0.25)
|
||||
|
||||
//rotate(Vector3.UNIT_Y, 45.0)
|
||||
for (j in 0 until 1) {
|
||||
for (i in -1..1 step 2) {
|
||||
val p = spiralPath(0.2 * i * scale, 0.25, 4.0, 400)
|
||||
|
||||
val rotationDegrees = j * 180.0 / 1.0
|
||||
val rotation = rotationDegrees.asRadians
|
||||
val scale = exp(rotation * 0.25)
|
||||
|
||||
val p = spiralPath(0.2 * i * scale, 0.25, 4.0, 400)
|
||||
|
||||
extrudeContourAdaptive(
|
||||
Circle(0.0, 0.0, 0.1).contour,
|
||||
p,
|
||||
Vector3.UNIT_Z,
|
||||
contourDistanceTolerance = 0.02,
|
||||
pathDistanceTolerance = 0.001
|
||||
)
|
||||
}
|
||||
rotate(Vector3.UNIT_Y, 180.0 / 1.0)
|
||||
extrudeContourAdaptive(
|
||||
Circle(0.0, 0.0, 0.1).contour,
|
||||
p,
|
||||
Vector3.UNIT_Z,
|
||||
contourDistanceTolerance = 0.02,
|
||||
pathDistanceTolerance = 0.001
|
||||
)
|
||||
}
|
||||
rotate(Vector3.UNIT_Y, 180.0 / 1.0)
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
extend(Orbital())
|
||||
extend {
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """
|
||||
extend(Orbital())
|
||||
extend {
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """
|
||||
x_fill = va_color;
|
||||
x_fill.rgb *= v_viewNormal.z;
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
drawer.rotate(Vector3.UNIT_X, seconds*20.0)
|
||||
drawer.vertexBuffer(spiral, DrawPrimitive.TRIANGLES)
|
||||
|
||||
}
|
||||
|
||||
drawer.rotate(Vector3.UNIT_X, seconds * 20.0)
|
||||
drawer.vertexBuffer(spiral, DrawPrimitive.TRIANGLES)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,71 +16,69 @@ import org.openrndr.shape.Segment3D
|
||||
* Extruded Bézier tubes grown on a morphing Bézier surface.
|
||||
*
|
||||
*/
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 800
|
||||
height = 800
|
||||
multisample = WindowMultisample.SampleCount(8)
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
multisample = WindowMultisample.SampleCount(8)
|
||||
}
|
||||
program {
|
||||
val crossSection = Circle(0.0, 0.0, 0.2).contour
|
||||
|
||||
extend(Orbital()) {
|
||||
this.eye = Vector3(0.0, 3.0, 7.0)
|
||||
this.lookAt = Vector3(0.0, 0.0, 0.0)
|
||||
}
|
||||
program {
|
||||
val crossSection = Circle(0.0, 0.0, 0.2).contour
|
||||
|
||||
extend(Orbital()) {
|
||||
this.eye = Vector3(0.0, 3.0, 7.0)
|
||||
this.lookAt = Vector3(0.0, 0.0, 0.0)
|
||||
}
|
||||
|
||||
extend {
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """
|
||||
extend {
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """
|
||||
x_fill = va_color;
|
||||
x_fill.rgb *= v_viewNormal.z;
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
val m = buildTriangleMesh {
|
||||
val beziers = List(4) { curveId ->
|
||||
val n = List(12) {
|
||||
Random.simplex(it * 7.387, curveId * 5.531 + seconds * 0.05) * 10.0
|
||||
}
|
||||
Segment3D(
|
||||
Vector3(n[0], n[1], n[2]),
|
||||
Vector3(n[3], n[4], n[5]),
|
||||
Vector3(n[6], n[7], n[8]),
|
||||
Vector3(n[9], n[10], n[11])
|
||||
)
|
||||
}
|
||||
|
||||
for (i in 0 until 20) {
|
||||
val t = i / (20.0 - 1.0)
|
||||
val path = Path3D(
|
||||
listOf(
|
||||
Segment3D(
|
||||
beziers[0].position(t),
|
||||
beziers[1].position(t),
|
||||
beziers[2].position(t),
|
||||
beziers[3].position(t)
|
||||
)
|
||||
), false
|
||||
)
|
||||
color = if(i % 2 == 0) ColorRGBa.PINK else ColorRGBa.WHITE.shade(0.1)
|
||||
extrudeContourSteps(
|
||||
crossSection,
|
||||
path,
|
||||
120,
|
||||
Vector3.UNIT_Y,
|
||||
contourDistanceTolerance = 0.05,
|
||||
pathDistanceTolerance = 0.05
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
drawer.vertexBuffer(m, DrawPrimitive.TRIANGLES)
|
||||
|
||||
// Remember to free the memory! Otherwise, the computer will quickly run out of RAM.
|
||||
m.destroy()
|
||||
}
|
||||
|
||||
val m = buildTriangleMesh {
|
||||
val beziers = List(4) { curveId ->
|
||||
val n = List(12) {
|
||||
Random.simplex(it * 7.387, curveId * 5.531 + seconds * 0.05) * 10.0
|
||||
}
|
||||
Segment3D(
|
||||
Vector3(n[0], n[1], n[2]),
|
||||
Vector3(n[3], n[4], n[5]),
|
||||
Vector3(n[6], n[7], n[8]),
|
||||
Vector3(n[9], n[10], n[11])
|
||||
)
|
||||
}
|
||||
|
||||
for (i in 0 until 20) {
|
||||
val t = i / (20.0 - 1.0)
|
||||
val path = Path3D(
|
||||
listOf(
|
||||
Segment3D(
|
||||
beziers[0].position(t),
|
||||
beziers[1].position(t),
|
||||
beziers[2].position(t),
|
||||
beziers[3].position(t)
|
||||
)
|
||||
), false
|
||||
)
|
||||
color = if (i % 2 == 0) ColorRGBa.PINK else ColorRGBa.WHITE.shade(0.1)
|
||||
extrudeContourSteps(
|
||||
crossSection,
|
||||
path,
|
||||
120,
|
||||
Vector3.UNIT_Y,
|
||||
contourDistanceTolerance = 0.05,
|
||||
pathDistanceTolerance = 0.05
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
drawer.vertexBuffer(m, DrawPrimitive.TRIANGLES)
|
||||
|
||||
// Remember to free the memory! Otherwise, the computer will quickly run out of RAM.
|
||||
m.destroy()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,72 +18,70 @@ import kotlin.math.cos
|
||||
* Extruded Bézier tubes grown on a morphing Bézier surface.
|
||||
*
|
||||
*/
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 800
|
||||
height = 800
|
||||
multisample = WindowMultisample.SampleCount(8)
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
multisample = WindowMultisample.SampleCount(8)
|
||||
}
|
||||
program {
|
||||
val crossSection = Circle(0.0, 0.0, 0.2).contour
|
||||
|
||||
extend(Orbital()) {
|
||||
this.eye = Vector3(0.0, 3.0, 7.0)
|
||||
this.lookAt = Vector3(0.0, 0.0, 0.0)
|
||||
}
|
||||
program {
|
||||
val crossSection = Circle(0.0, 0.0, 0.2).contour
|
||||
|
||||
extend(Orbital()) {
|
||||
this.eye = Vector3(0.0, 3.0, 7.0)
|
||||
this.lookAt = Vector3(0.0, 0.0, 0.0)
|
||||
}
|
||||
|
||||
extend {
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """
|
||||
extend {
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """
|
||||
x_fill = va_color;
|
||||
x_fill.rgb *= v_viewNormal.z;
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
val m = buildTriangleMesh {
|
||||
val beziers = List(4) { curveId ->
|
||||
val n = List(12) {
|
||||
Random.simplex(it * 7.387, curveId * 5.531 + seconds * 0.05) * 10.0
|
||||
}
|
||||
Segment3D(
|
||||
Vector3(n[0], n[1], n[2]),
|
||||
Vector3(n[3], n[4], n[5]),
|
||||
Vector3(n[6], n[7], n[8]),
|
||||
Vector3(n[9], n[10], n[11])
|
||||
)
|
||||
}
|
||||
|
||||
for (i in 0 until 20) {
|
||||
val t = i / (20.0 - 1.0)
|
||||
val path = Path3D(
|
||||
listOf(
|
||||
Segment3D(
|
||||
beziers[0].position(t),
|
||||
beziers[1].position(t),
|
||||
beziers[2].position(t),
|
||||
beziers[3].position(t)
|
||||
)
|
||||
), false
|
||||
)
|
||||
color = if(i % 2 == 0) ColorRGBa.PINK else ColorRGBa.WHITE.shade(0.1)
|
||||
extrudeContourStepsScaled(
|
||||
crossSection,
|
||||
path,
|
||||
120,
|
||||
Vector3.UNIT_Y,
|
||||
contourDistanceTolerance = 0.05,
|
||||
pathDistanceTolerance = 0.05,
|
||||
scale = { tt: Double -> 0.5 - 0.5 * cos(tt * 2 * PI) }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
drawer.vertexBuffer(m, DrawPrimitive.TRIANGLES)
|
||||
|
||||
// Remember to free the memory! Otherwise, the computer will quickly run out of RAM.
|
||||
m.destroy()
|
||||
}
|
||||
|
||||
val m = buildTriangleMesh {
|
||||
val beziers = List(4) { curveId ->
|
||||
val n = List(12) {
|
||||
Random.simplex(it * 7.387, curveId * 5.531 + seconds * 0.05) * 10.0
|
||||
}
|
||||
Segment3D(
|
||||
Vector3(n[0], n[1], n[2]),
|
||||
Vector3(n[3], n[4], n[5]),
|
||||
Vector3(n[6], n[7], n[8]),
|
||||
Vector3(n[9], n[10], n[11])
|
||||
)
|
||||
}
|
||||
|
||||
for (i in 0 until 20) {
|
||||
val t = i / (20.0 - 1.0)
|
||||
val path = Path3D(
|
||||
listOf(
|
||||
Segment3D(
|
||||
beziers[0].position(t),
|
||||
beziers[1].position(t),
|
||||
beziers[2].position(t),
|
||||
beziers[3].position(t)
|
||||
)
|
||||
), false
|
||||
)
|
||||
color = if (i % 2 == 0) ColorRGBa.PINK else ColorRGBa.WHITE.shade(0.1)
|
||||
extrudeContourStepsScaled(
|
||||
crossSection,
|
||||
path,
|
||||
120,
|
||||
Vector3.UNIT_Y,
|
||||
contourDistanceTolerance = 0.05,
|
||||
pathDistanceTolerance = 0.05,
|
||||
scale = { tt: Double -> 0.5 - 0.5 * cos(tt * 2 * PI) }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
drawer.vertexBuffer(m, DrawPrimitive.TRIANGLES)
|
||||
|
||||
// Remember to free the memory! Otherwise, the computer will quickly run out of RAM.
|
||||
m.destroy()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,25 +22,24 @@ import kotlin.math.cos
|
||||
* based on the t value along a Path3D. In other words, a tube in which the cross-section does not need
|
||||
* to be constant, but can be scaled, rotated and displaced along its curvy axis.
|
||||
*/
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 800
|
||||
height = 800
|
||||
multisample = WindowMultisample.SampleCount(8)
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
multisample = WindowMultisample.SampleCount(8)
|
||||
}
|
||||
program {
|
||||
Random.seed = System.currentTimeMillis().toString()
|
||||
|
||||
val texture = loadImage("demo-data/images/peopleCity01.jpg").also {
|
||||
it.wrapU = WrapMode.REPEAT
|
||||
it.wrapV = WrapMode.REPEAT
|
||||
it.filterMag = MagnifyingFilter.LINEAR
|
||||
it.filterMin = MinifyingFilter.LINEAR
|
||||
}
|
||||
program {
|
||||
Random.seed = System.currentTimeMillis().toString()
|
||||
|
||||
val texture = loadImage("demo-data/images/peopleCity01.jpg").also {
|
||||
it.wrapU = WrapMode.REPEAT
|
||||
it.wrapV = WrapMode.REPEAT
|
||||
it.filterMag = MagnifyingFilter.LINEAR
|
||||
it.filterMin = MinifyingFilter.LINEAR
|
||||
}
|
||||
|
||||
val shader = shadeStyle {
|
||||
fragmentTransform = """
|
||||
val shader = shadeStyle {
|
||||
fragmentTransform = """
|
||||
// A. Passed color
|
||||
x_fill = va_color;
|
||||
|
||||
@@ -56,38 +55,37 @@ fun main() {
|
||||
// Black fog (darken far away shapes)
|
||||
x_fill.rgb += v_viewPosition.z * 0.05;
|
||||
""".trimIndent()
|
||||
parameter("img", texture)
|
||||
}
|
||||
parameter("img", texture)
|
||||
}
|
||||
|
||||
extend(Orbital()) {
|
||||
eye = Vector3(0.0, 3.0, 7.0)
|
||||
lookAt = Vector3(0.0, 0.0, 0.0)
|
||||
}
|
||||
extend {
|
||||
drawer.stroke = null
|
||||
extend(Orbital()) {
|
||||
eye = Vector3(0.0, 3.0, 7.0)
|
||||
lookAt = Vector3(0.0, 0.0, 0.0)
|
||||
}
|
||||
extend {
|
||||
drawer.stroke = null
|
||||
|
||||
val path = get3DPath(10.0, seconds * 0.05, 400)
|
||||
val tubes = makeTubes(path, seconds * 0.2)
|
||||
val path = get3DPath(10.0, seconds * 0.05, 400)
|
||||
val tubes = makeTubes(path, seconds * 0.2)
|
||||
|
||||
shader.parameter("seconds", seconds * 0.1)
|
||||
drawer.fill = ColorRGBa.WHITE
|
||||
drawer.shadeStyle = shader
|
||||
tubes.forEachIndexed { i, vb ->
|
||||
shader.parameter("offset", i * 0.3 + 0.2)
|
||||
shader.parameter("seconds", seconds * 0.1)
|
||||
drawer.fill = ColorRGBa.WHITE
|
||||
drawer.shadeStyle = shader
|
||||
tubes.forEachIndexed { i, vb ->
|
||||
shader.parameter("offset", i * 0.3 + 0.2)
|
||||
|
||||
// Mirror the mesh 5 times
|
||||
repeat(5) {
|
||||
drawer.isolated {
|
||||
rotate(Vector3.UNIT_Z, it * 72.0)
|
||||
vertexBuffer(vb, DrawPrimitive.TRIANGLES)
|
||||
}
|
||||
// Mirror the mesh 5 times
|
||||
repeat(5) {
|
||||
drawer.isolated {
|
||||
rotate(Vector3.UNIT_Z, it * 72.0)
|
||||
vertexBuffer(vb, DrawPrimitive.TRIANGLES)
|
||||
}
|
||||
|
||||
// Remember to free the memory! Otherwise, the computer will quickly run out of RAM.
|
||||
vb.destroy()
|
||||
}
|
||||
|
||||
// Remember to free the memory! Otherwise, the computer will quickly run out of RAM.
|
||||
vb.destroy()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,42 +15,40 @@ import java.io.File
|
||||
* Demonstrate decal generator as an object slicer
|
||||
* @see <img src="https://raw.githubusercontent.com/openrndr/orx/media/orx-mesh-generators/images/decal-DemoDecal01Kt.png">
|
||||
*/
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
}
|
||||
program {
|
||||
val obj = loadOBJMeshData(File("demo-data/obj-models/suzanne/Suzanne.obj")).toMeshData().triangulate()
|
||||
|
||||
val slices = 25
|
||||
val sliceStep = 0.1
|
||||
val sliceWidth = 0.14
|
||||
|
||||
val sliceVBs = (0 until slices).map {
|
||||
val projector = buildTransform {
|
||||
translate(0.0, 0.0, -1.0 + it * sliceStep)
|
||||
}
|
||||
val decal = obj.decal(projector, Vector3(4.0, 4.0, sliceWidth))
|
||||
val vb = decal.toVertexBuffer()
|
||||
vb
|
||||
}
|
||||
program {
|
||||
val obj = loadOBJMeshData(File("demo-data/obj-models/suzanne/Suzanne.obj")).toMeshData().triangulate()
|
||||
|
||||
val slices = 25
|
||||
val sliceStep = 0.1
|
||||
val sliceWidth = 0.14
|
||||
|
||||
val sliceVBs = (0 until slices).map {
|
||||
val projector = buildTransform {
|
||||
translate(0.0, 0.0, -1.0 + it * sliceStep)
|
||||
}
|
||||
val decal = obj.decal(projector, Vector3(4.0, 4.0, sliceWidth))
|
||||
val vb = decal.toVertexBuffer()
|
||||
vb
|
||||
extend(Orbital()) {
|
||||
eye = Vector3(0.0, 0.0, 2.0)
|
||||
}
|
||||
extend {
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """x_fill.rgb = v_viewNormal.rgb * 0.5 + 0.5; """
|
||||
}
|
||||
|
||||
extend(Orbital()) {
|
||||
eye = Vector3(0.0, 0.0, 2.0)
|
||||
}
|
||||
extend {
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """x_fill.rgb = v_viewNormal.rgb * 0.5 + 0.5; """
|
||||
}
|
||||
|
||||
drawer.translate(0.0, 0.0, slices * 0.5 * 0.5)
|
||||
for (i in 0 until sliceVBs.size) {
|
||||
drawer.vertexBuffer(sliceVBs[i], DrawPrimitive.TRIANGLES)
|
||||
drawer.translate(0.0, 0.0, -0.5)
|
||||
}
|
||||
drawer.translate(0.0, 0.0, slices * 0.5 * 0.5)
|
||||
for (i in 0 until sliceVBs.size) {
|
||||
drawer.vertexBuffer(sliceVBs[i], DrawPrimitive.TRIANGLES)
|
||||
drawer.translate(0.0, 0.0, -0.5)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,71 +17,69 @@ import kotlin.math.PI
|
||||
* Demonstrate decal generation and rendering
|
||||
* @see <img src="https://raw.githubusercontent.com/openrndr/orx/media/orx-mesh-generators/images/decal-DemoDecal02Kt.png">
|
||||
*/
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
}
|
||||
program {
|
||||
/** base object */
|
||||
val obj = loadOBJMeshData(File("demo-data/obj-models/suzanne/Suzanne.obj"))
|
||||
.toMeshData() // convert from CompoundMeshData to MeshData
|
||||
.triangulate() // convert to triangles, we need this for the decal generation steps
|
||||
|
||||
/** object [VertexBuffer] */
|
||||
val objVB = obj.toVertexBuffer()
|
||||
|
||||
|
||||
/** positions for the decal projectors */
|
||||
val decalPositions = listOf(
|
||||
Vector3(0.35, 0.245, 0.8),
|
||||
Vector3(-0.35, 0.245, 0.8)
|
||||
)
|
||||
|
||||
/** decal vertex buffers */
|
||||
val decalVBs = decalPositions.map {
|
||||
val projector = buildTransform {
|
||||
translate(it)
|
||||
}
|
||||
val decal = obj.decal(projector, Vector3(2.0, 2.0, 0.5))
|
||||
val vb = decal.toVertexBuffer()
|
||||
vb
|
||||
}
|
||||
program {
|
||||
/** base object */
|
||||
val obj = loadOBJMeshData(File("demo-data/obj-models/suzanne/Suzanne.obj"))
|
||||
.toMeshData() // convert from CompoundMeshData to MeshData
|
||||
.triangulate() // convert to triangles, we need this for the decal generation steps
|
||||
|
||||
/** object [VertexBuffer] */
|
||||
val objVB = obj.toVertexBuffer()
|
||||
|
||||
|
||||
/** positions for the decal projectors */
|
||||
val decalPositions = listOf(
|
||||
Vector3(0.35, 0.245, 0.8),
|
||||
Vector3(-0.35, 0.245, 0.8)
|
||||
)
|
||||
|
||||
/** decal vertex buffers */
|
||||
val decalVBs = decalPositions.map {
|
||||
val projector = buildTransform {
|
||||
translate(it)
|
||||
extend(Orbital()) {
|
||||
eye = Vector3(0.0, 0.0, 2.0)
|
||||
}
|
||||
extend {
|
||||
/* draw the base mesh */
|
||||
drawer.isolated {
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """x_fill.rgb = vec3(v_viewNormal * 0.5 + 0.5); """
|
||||
}
|
||||
val decal = obj.decal(projector, Vector3(2.0, 2.0, 0.5))
|
||||
val vb = decal.toVertexBuffer()
|
||||
vb
|
||||
drawer.vertexBuffer(objVB, DrawPrimitive.TRIANGLES)
|
||||
}
|
||||
|
||||
extend(Orbital()) {
|
||||
eye = Vector3(0.0, 0.0, 2.0)
|
||||
}
|
||||
extend {
|
||||
/* draw the base mesh */
|
||||
drawer.isolated {
|
||||
/* draw the decals */
|
||||
drawer.isolated {
|
||||
for ((index, decal) in decalVBs.withIndex()) {
|
||||
/* offset the projection transform to avoid z-fighting */
|
||||
drawer.projection = buildTransform {
|
||||
translate(0.0, 0.0, -1e-4)
|
||||
} * drawer.projection
|
||||
|
||||
/* draw effects on the decal geometry */
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """x_fill.rgb = vec3(v_viewNormal * 0.5 + 0.5); """
|
||||
}
|
||||
drawer.vertexBuffer(objVB, DrawPrimitive.TRIANGLES)
|
||||
}
|
||||
|
||||
/* draw the decals */
|
||||
drawer.isolated {
|
||||
for ((index, decal) in decalVBs.withIndex()) {
|
||||
/* offset the projection transform to avoid z-fighting */
|
||||
drawer.projection = buildTransform {
|
||||
translate(0.0, 0.0, -1e-4)
|
||||
} * drawer.projection
|
||||
|
||||
/* draw effects on the decal geometry */
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """
|
||||
fragmentTransform = """
|
||||
float d = length(va_texCoord0.xy - vec2(0.5));
|
||||
float sd = smoothstep(-0.01, 0.01, cos(p_time + d * 3.1415 * 2.0 * 10.0));
|
||||
float l = max(0.0, va_normal.z);
|
||||
x_fill = vec4(0.0, 0.0, 0.0, l * sd * 0.5); """
|
||||
parameter("time", seconds * PI * 2 + index * PI)
|
||||
}
|
||||
drawer.vertexBuffer(decal, DrawPrimitive.TRIANGLES)
|
||||
parameter("time", seconds * PI * 2 + index * PI)
|
||||
}
|
||||
drawer.vertexBuffer(decal, DrawPrimitive.TRIANGLES)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,10 @@ import org.openrndr.math.Vector3
|
||||
import java.io.File
|
||||
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
}
|
||||
program {
|
||||
val obj = loadOBJMeshData(File("demo-data/obj-models/suzanne/Suzanne.obj")).toMeshData().triangulate()
|
||||
val tangentObj = obj.estimateTangents()
|
||||
|
||||
@@ -25,7 +25,7 @@ Optionally, a static `backdrop` may be setup by providing custom code.
|
||||
- Example 1. Customising the backdrop with an image
|
||||
```kotlin
|
||||
extend(NoClear()) {
|
||||
val img = loadImage("data\\backdrop.png")
|
||||
val img = loadImage("data/backdrop.png")
|
||||
backdrop = {
|
||||
drawer.image(img, 0.0, 0.0, width * 1.0, height * 1.0)
|
||||
}
|
||||
|
||||
@@ -2,60 +2,72 @@ import org.openrndr.application
|
||||
import org.openrndr.color.ColorHSLa
|
||||
import org.openrndr.color.rgb
|
||||
import org.openrndr.draw.isolated
|
||||
import org.openrndr.extensions.SingleScreenshot
|
||||
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
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 540
|
||||
}
|
||||
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)) }
|
||||
// ------------------------------------------------------------
|
||||
// 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 code generated or an image
|
||||
// loaded from disk. In this case we start with dark gray.
|
||||
backdrop = { drawer.clear(rgb(0.15)) }
|
||||
}
|
||||
|
||||
if (System.getProperty("takeScreenshot") == "true") {
|
||||
extensions.filterIsInstance<SingleScreenshot>().forEach {
|
||||
it.delayFrames = 60
|
||||
}
|
||||
}
|
||||
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.
|
||||
|
||||
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)
|
||||
|
||||
drawer.isolated {
|
||||
// center the origin
|
||||
translate(bounds.center)
|
||||
for (i in 0..5) {
|
||||
time += 0.01
|
||||
|
||||
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)
|
||||
// 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 Bézier 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,32 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.draw.loadFont
|
||||
import org.openrndr.extra.objloader.loadOBJMeshData
|
||||
import org.openrndr.extra.objloader.toObj
|
||||
import org.openrndr.math.Vector2
|
||||
import java.io.File
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
program {
|
||||
val path = "demo-data/obj-models"
|
||||
val cm = loadOBJMeshData(File("$path/suzanne/Suzanne.obj"))
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
}
|
||||
program {
|
||||
val path = "demo-data/obj-models"
|
||||
val cm = loadOBJMeshData(File("$path/suzanne/Suzanne.obj"))
|
||||
|
||||
println(cm.toObj())
|
||||
// Convert mesh data to Wavefront OBJ String representation
|
||||
val obj = cm.toObj()
|
||||
|
||||
println(obj)
|
||||
|
||||
val font = loadFont("demo-data/fonts/IBMPlexMono-Regular.ttf", 24.0)
|
||||
|
||||
extend {
|
||||
// Draw part of the OBJ data as text
|
||||
drawer.fontMap = font
|
||||
drawer.texts(obj.split("\n").take(50), List(50) {
|
||||
Vector2(10.0, 20.0 + it * 20.0)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@ import org.openrndr.extra.objloader.loadOBJasVertexBuffer
|
||||
import org.openrndr.math.Vector3
|
||||
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 540
|
||||
}
|
||||
program {
|
||||
val mesh = loadOBJasVertexBuffer("demo-data/obj-models/suzanne/Suzanne.obj")
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.openrndr.extra.objloader.saveOBJ
|
||||
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 100
|
||||
}
|
||||
program {
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.openrndr.extra.objloader.saveOBJ
|
||||
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 100
|
||||
}
|
||||
program {
|
||||
|
||||
@@ -16,48 +16,46 @@ import org.openrndr.shape.Path3D
|
||||
import java.io.File
|
||||
import kotlin.math.cos
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
multisample = WindowMultisample.SampleCount(4)
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
multisample = WindowMultisample.SampleCount(4)
|
||||
}
|
||||
program {
|
||||
val vb = loadOBJasVertexBuffer("orx-obj-loader/test-data/non-planar.obj")
|
||||
val md = readObjMeshData(File("orx-obj-loader/test-data/non-planar.obj").readLines())
|
||||
|
||||
val paths = md.wireframe().map {
|
||||
Path3D.fromPoints(it, true)
|
||||
}
|
||||
program {
|
||||
val vb = loadOBJasVertexBuffer("orx-obj-loader/test-data/non-planar.obj")
|
||||
val md = readObjMeshData(File("orx-obj-loader/test-data/non-planar.obj").readLines())
|
||||
|
||||
val paths = md.wireframe().map {
|
||||
Path3D.fromPoints(it, true)
|
||||
}
|
||||
|
||||
extend(Orbital())
|
||||
extend {
|
||||
drawer.rotate(Vector3.Companion.UNIT_Y, seconds * 45.0 + 45.0, TransformTarget.MODEL)
|
||||
drawer.translate(0.0, 0.0, 9.0, TransformTarget.VIEW)
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """
|
||||
extend(Orbital())
|
||||
extend {
|
||||
drawer.rotate(Vector3.Companion.UNIT_Y, seconds * 45.0 + 45.0, TransformTarget.MODEL)
|
||||
drawer.translate(0.0, 0.0, 9.0, TransformTarget.VIEW)
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """
|
||||
x_fill.rgb = normalize(v_viewNormal) * 0.5 + vec3(0.5);
|
||||
""".trimIndent()
|
||||
}
|
||||
}
|
||||
|
||||
drawer.vertexBuffer(vb, DrawPrimitive.TRIANGLES)
|
||||
drawer.stroke = ColorRGBa.WHITE
|
||||
drawer.strokeWeight = 1.0
|
||||
drawer.vertexBuffer(vb, DrawPrimitive.TRIANGLES)
|
||||
drawer.stroke = ColorRGBa.WHITE
|
||||
drawer.strokeWeight = 1.0
|
||||
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
vertexTransform = """
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
vertexTransform = """
|
||||
x_projectionMatrix[3][2] -= 0.001;
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
drawer.strokeWeight = 1.0
|
||||
drawer.paths(paths.mapIndexed { index, it ->
|
||||
it.sub(
|
||||
0.0, cos(seconds * 0.5 + index * 0.5) * 0.5 + 0.5
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
drawer.strokeWeight = 1.0
|
||||
drawer.paths(paths.mapIndexed { index, it ->
|
||||
it.sub(
|
||||
0.0, cos(seconds * 0.5 + index * 0.5) * 0.5 + 0.5
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user