aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/phenax
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2026-08-30 22:41:25 +0530
committerAkshay Nair <phenax5@gmail.com>2026-08-30 22:41:28 +0530
commitfecebfd39809f862e098805219b15c50588bb81a (patch)
treef600ad9667ab4d087113fad0f6898d61ade97cfc /src/main/kotlin/phenax
parent326474823ca31ad8ae424dd1d991c0330f2b3db4 (diff)
downloadart-playground-openrndr-fecebfd39809f862e098805219b15c50588bb81a.tar.gz
art-playground-openrndr-fecebfd39809f862e098805219b15c50588bb81a.zip
Development setup + toggling recording
Diffstat (limited to 'src/main/kotlin/phenax')
-rw-r--r--src/main/kotlin/phenax/extensions/HeadlessRecording.kt53
-rw-r--r--src/main/kotlin/phenax/utils/program.kt9
2 files changed, 62 insertions, 0 deletions
diff --git a/src/main/kotlin/phenax/extensions/HeadlessRecording.kt b/src/main/kotlin/phenax/extensions/HeadlessRecording.kt
new file mode 100644
index 0000000..78cde2c
--- /dev/null
+++ b/src/main/kotlin/phenax/extensions/HeadlessRecording.kt
@@ -0,0 +1,53 @@
+package phenax.extensions
+
+import org.openrndr.*
+import org.openrndr.draw.*
+import org.openrndr.ffmpeg.VideoWriter
+import phenax.utils.recordDuration
+
+class HeadlessRecorder : Extension {
+ override var enabled: Boolean = true
+
+ var videoTarget: RenderTarget? = null
+ var videoWriter: VideoWriter? = null
+ var maxFrameCount: Int? = null
+
+ override fun setup(program: Program) {
+ val width = program.application.configuration.width
+ val height = program.application.configuration.height
+ program.width = width
+ program.height = height
+ videoWriter =
+ VideoWriter().apply {
+ frameRate = 60
+ size(width, height)
+ output("video/${program.name}.mp4")
+ start()
+ }
+ videoTarget =
+ renderTarget(width, height) {
+ colorBuffer()
+ depthBuffer()
+ }
+ maxFrameCount = recordDuration()
+ program.clock = { program.frameCount / (videoWriter?.frameRate?.toDouble() ?: 0.0) }
+ }
+
+ override fun beforeDraw(drawer: Drawer, program: Program) {
+ videoTarget?.bind()
+ program.backgroundColor?.let { drawer.clear(it) }
+ }
+
+ override fun afterDraw(drawer: Drawer, program: Program) {
+ val target = videoTarget ?: return
+ val writer = videoWriter ?: return
+
+ target.unbind()
+ writer.frame(target.colorBuffer(0))
+
+ if (program.frameCount >= (maxFrameCount ?: 60 * 10)) {
+ writer.stop()
+ program.application.exit()
+ }
+ }
+}
diff --git a/src/main/kotlin/phenax/utils/program.kt b/src/main/kotlin/phenax/utils/program.kt
new file mode 100644
index 0000000..2d3e04b
--- /dev/null
+++ b/src/main/kotlin/phenax/utils/program.kt
@@ -0,0 +1,9 @@
+package phenax.utils
+
+fun recordDuration(durationSeconds: Int) {
+ System.setProperty("phenax.record.frameCount", (60 * durationSeconds).toString())
+}
+
+fun recordDuration(): Int? = System.getProperty("phenax.record.frameCount")?.toIntOrNull()
+
+fun recordingEnabled(): Boolean = System.getenv("RECORD") != null