Demos: ensure 720px wide, reduce indentation

This commit is contained in:
Abe Pazos
2025-01-24 23:05:40 +01:00
parent ca8fbc1c0a
commit f84bf69713
31 changed files with 961 additions and 964 deletions

View File

@@ -11,15 +11,14 @@ 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 {
fun main() = application {
configure {
width = 1080
width = 720
height = 720
}
@@ -41,4 +40,3 @@ fun main() {
}
}
}
}

View File

@@ -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,10 +14,9 @@ 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 {
fun main() = application {
configure {
width = 1280
width = 720
height = 720
}
program {
@@ -34,4 +33,3 @@ fun main() {
}
}
}
}

View File

@@ -11,17 +11,15 @@ 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 = 1080
width = 720
height = 720
}
@@ -47,4 +45,3 @@ fun main() {
}
}
}
}

View File

@@ -3,8 +3,7 @@ import org.openrndr.color.ColorRGBa
import org.openrndr.extra.marchingsquares.findContours
import org.openrndr.math.Vector2
fun main() {
application {
fun main() = application {
configure {
width = 720
height = 720
@@ -20,4 +19,3 @@ fun main() {
}
}
}
}

View File

@@ -5,8 +5,7 @@ import org.openrndr.math.Vector2
import kotlin.math.PI
import kotlin.math.cos
fun main() {
application {
fun main() = application {
configure {
width = 720
height = 720
@@ -22,4 +21,3 @@ fun main() {
}
}
}
}

View File

@@ -6,8 +6,7 @@ import kotlin.math.PI
import kotlin.math.cos
import kotlin.math.sin
fun main() {
application {
fun main() = application {
configure {
width = 720
height = 720
@@ -21,9 +20,9 @@ fun main() {
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)
}
}
}
}

View File

@@ -7,11 +7,10 @@ import org.openrndr.math.Vector2
import kotlin.math.PI
import kotlin.math.cos
fun main() {
application {
fun main() = application {
configure {
width = 640
height = 480
width = 720
height = 540
}
program {
val image = loadImage("demo-data/images/image-001.png")
@@ -22,15 +21,16 @@ fun main() {
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
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)
}
}
}
}

View File

@@ -8,9 +8,10 @@ import org.openrndr.math.Vector2
import org.openrndr.math.Vector3
import org.openrndr.shape.Rectangle
fun main() {
application {
fun main() = application {
configure {
width = 720
height = 720
multisample = WindowMultisample.SampleCount(8)
}
program {
@@ -66,4 +67,3 @@ fun main() {
}
}
}
}

View File

@@ -9,9 +9,10 @@ import org.openrndr.extra.camera.Orbital
import org.openrndr.extra.meshgenerators.boxMesh
import org.openrndr.math.Vector3
fun main() {
application {
fun main() = application {
configure {
width = 720
height = 720
multisample = WindowMultisample.SampleCount(8)
}
program {
@@ -42,4 +43,3 @@ fun main() {
}
}
}
}

View File

@@ -9,11 +9,10 @@ import org.openrndr.extra.meshgenerators.buildTriangleMesh
import org.openrndr.extra.meshgenerators.sphere
import org.openrndr.math.Vector3
fun main() {
application {
fun main() = application {
configure {
width = 800
height = 800
width = 720
height = 720
multisample = WindowMultisample.SampleCount(8)
}
program {
@@ -43,4 +42,3 @@ fun main() {
}
}
}
}

View File

@@ -8,11 +8,10 @@ import org.openrndr.extra.meshgenerators.cylinder
import org.openrndr.extra.meshgenerators.hemisphere
import org.openrndr.math.Vector3
fun main() {
application {
fun main() = application {
configure {
width = 800
height = 800
width = 720
height = 720
multisample = WindowMultisample.SampleCount(8)
}
program {
@@ -64,4 +63,3 @@ fun main() {
}
}
}
}

View File

@@ -6,11 +6,10 @@ import org.openrndr.extra.camera.Orbital
import org.openrndr.extra.meshgenerators.*
import org.openrndr.math.Vector3
fun main() {
application {
fun main() = application {
configure {
width = 800
height = 800
width = 720
height = 720
multisample = WindowMultisample.SampleCount(8)
}
program {
@@ -31,17 +30,21 @@ fun main() {
for (r in 0 until ridges) {
isolated {
translate(0.0,
translate(
0.0,
ridgeLength / 4.0 + r * ridgeLength + 6.0,
0.0)
0.0
)
rotate(Vector3.UNIT_X, 270.0)
taperedCylinder(32, 1, 5.0, ridgeRadius, ridgeLength / 2.0, center = true)
}
isolated {
translate(0.0,
translate(
0.0,
ridgeLength / 4.0 + ridgeLength / 2.0 + r * ridgeLength + 6.0,
0.0)
0.0
)
rotate(Vector3.UNIT_X, 270.0)
taperedCylinder(32, 1, ridgeRadius, 5.0, ridgeLength / 2.0, center = true)
}
@@ -80,4 +83,3 @@ fun main() {
}
}
}
}

View File

@@ -7,11 +7,10 @@ import org.openrndr.extra.meshgenerators.*
import org.openrndr.math.Vector2
import org.openrndr.math.Vector3
fun main() {
application {
fun main() = application {
configure {
width = 800
height = 800
width = 720
height = 720
multisample = WindowMultisample.SampleCount(8)
}
program {
@@ -23,12 +22,14 @@ fun main() {
val sides = 12
isolated {
translate(0.0, 12.0, 0.0)
cap(sides, 5.0, listOf(
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))
Vector2(1.0, 0.0)
)
)
}
@@ -101,4 +102,3 @@ fun main() {
}
}
}
}

View File

@@ -11,11 +11,10 @@ import org.openrndr.extra.meshgenerators.twist
import org.openrndr.math.Vector3
import org.openrndr.shape.Circle
fun main() {
application {
fun main() = application {
configure {
width = 800
height = 800
width = 720
height = 720
multisample = WindowMultisample.SampleCount(8)
}
program {
@@ -45,4 +44,3 @@ fun main() {
}
}
}
}

View File

@@ -13,11 +13,10 @@ import org.openrndr.math.Vector3
* Interactive orbital camera.
*
*/
fun main() {
application {
fun main() = application {
configure {
width = 800
height = 800
width = 720
height = 720
multisample = WindowMultisample.SampleCount(8)
}
program {
@@ -59,4 +58,3 @@ fun main() {
}
}
}
}

View File

@@ -11,11 +11,10 @@ import org.openrndr.extra.shapes.splines.toPath3D
import org.openrndr.math.Vector3
import org.openrndr.shape.Circle
fun main() {
application {
fun main() = application {
configure {
width = 800
height = 800
width = 720
height = 720
multisample = WindowMultisample.SampleCount(8)
}
program {
@@ -64,4 +63,3 @@ fun main() {
}
}
}
}

View File

@@ -12,11 +12,10 @@ import org.openrndr.math.Vector3
import org.openrndr.shape.Circle
import org.openrndr.shape.Shape
fun main() {
application {
fun main() = application {
configure {
width = 800
height = 800
width = 720
height = 720
multisample = WindowMultisample.SampleCount(8)
}
program {
@@ -47,8 +46,6 @@ fun main() {
)
translate(2.0, 0.0, 0.0)
}
}
extend(Orbital()) {
@@ -68,4 +65,3 @@ fun main() {
}
}
}
}

View File

@@ -15,11 +15,10 @@ import org.openrndr.shape.Path3D
import kotlin.math.PI
import kotlin.math.exp
fun main() {
application {
fun main() = application {
configure {
width = 800
height = 800
width = 720
height = 720
multisample = WindowMultisample.SampleCount(8)
}
program {
@@ -73,9 +72,6 @@ fun main() {
rotate(Vector3.UNIT_Y, 180.0 / 1.0)
}
}
}
extend(Orbital())
@@ -89,8 +85,6 @@ fun main() {
drawer.rotate(Vector3.UNIT_X, seconds * 20.0)
drawer.vertexBuffer(spiral, DrawPrimitive.TRIANGLES)
}
}
}
}

View File

@@ -16,11 +16,10 @@ import org.openrndr.shape.Segment3D
* Extruded Bézier tubes grown on a morphing Bézier surface.
*
*/
fun main() {
application {
fun main() = application {
configure {
width = 800
height = 800
width = 720
height = 720
multisample = WindowMultisample.SampleCount(8)
}
program {
@@ -83,4 +82,3 @@ fun main() {
}
}
}
}

View File

@@ -18,11 +18,10 @@ import kotlin.math.cos
* Extruded Bézier tubes grown on a morphing Bézier surface.
*
*/
fun main() {
application {
fun main() = application {
configure {
width = 800
height = 800
width = 720
height = 720
multisample = WindowMultisample.SampleCount(8)
}
program {
@@ -86,4 +85,3 @@ fun main() {
}
}
}
}

View File

@@ -22,11 +22,10 @@ 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 {
fun main() = application {
configure {
width = 800
height = 800
width = 720
height = 720
multisample = WindowMultisample.SampleCount(8)
}
program {
@@ -90,7 +89,6 @@ fun main() {
}
}
}
}
val crossSection = Circle(Vector2.ZERO, 0.1).contour.transform(
transform { scale(5.0, 1.0, 1.0) }

View File

@@ -15,8 +15,7 @@ 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 {
fun main() = application {
configure {
width = 720
height = 720
@@ -53,4 +52,3 @@ fun main() {
}
}
}
}

View File

@@ -17,8 +17,7 @@ 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 {
fun main() = application {
configure {
width = 720
height = 720
@@ -84,4 +83,3 @@ fun main() {
}
}
}
}

View File

@@ -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()

View File

@@ -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)
}

View File

@@ -2,13 +2,17 @@ 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 {
fun main() = application {
configure {
width = 720
height = 540
}
program {
var time = 0.0
@@ -19,12 +23,17 @@ fun main() {
// 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 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
@@ -40,11 +49,13 @@ fun main() {
// 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
Polar(
time * (15.0 + it * 5),
250.0 * sin(time + it * 65)
).cartesian
}
// Use those 4 points to create a bezier curve
// Use those 4 points to create a zier curve
val c = contour {
moveTo(points.first())
curveTo(points[1], points[2], points.last())
@@ -52,12 +63,13 @@ fun main() {
// 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()
stroke = ColorHSLa(
time * 10.0, 0.8,
0.5 + 0.2 * sin(time * 3), 0.5
).toRGBa()
contour(c)
}
}
}
}
}
}

View File

@@ -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 {
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)
})
}
}
}

View File

@@ -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")

View File

@@ -5,6 +5,7 @@ import org.openrndr.extra.objloader.saveOBJ
fun main() = application {
configure {
width = 720
height = 100
}
program {

View File

@@ -6,6 +6,7 @@ import org.openrndr.extra.objloader.saveOBJ
fun main() = application {
configure {
width = 720
height = 100
}
program {

View File

@@ -16,8 +16,7 @@ import org.openrndr.shape.Path3D
import java.io.File
import kotlin.math.cos
fun main() {
application {
fun main() = application {
configure {
width = 720
height = 720
@@ -60,4 +59,3 @@ fun main() {
}
}
}
}