To easily create large format static generative art and export/print it, I wrote a small library in javascript (THIS is a small example of what it looks like). Because I need more speed for some things, I want to convert the library to a faster programming language. Kotlin with OpenRNDR seems like a fantastic candidate to me. Precision is very important and here lies my first problem with openrndr. Here’s the problem:
import org.openrndr.KEY_ESCAPE
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.isolatedWithTarget
import org.openrndr.draw.renderTarget
import org.openrndr.extra.color.presets.LIGHT_GRAY
import org.openrndr.extra.olive.oliveProgram
import org.openrndr.shape.Circle
import org.openrndr.shape.LineSegment
import org.openrndr.shape.Rectangle
import java.io.File
fun main() = application {
configure {
width = 1181
height = 1181
hideWindowDecorations = false
}
oliveProgram {
val rt = renderTarget(width, height, 10.0) {
colorBuffer()
}
val rect = Rectangle(0.0, 0.0, width.toDouble(), height.toDouble())
keyboard.keyDown.listen {
when {
it.key == KEY_ESCAPE -> {
application.exit()
}
it.key == 'E'.code -> {
val exportRT = renderTarget(width * 10, height * 10) {
colorBuffer()
}
drawer.isolatedWithTarget(exportRT) {
drawer.image(rt.colorBuffer(0))
}
exportRT.colorBuffer(0).saveToFile(File("image.png"))
exportRT.detachColorAttachments()
exportRT.destroy()
println("Artwork Exported.")
}
}
}
drawer.isolatedWithTarget(rt) {
val bg = Rectangle(0.0, 0.0, width * 1.0, height * 1.0)
drawer.fill = ColorRGBa.LIGHT_GRAY
drawer.stroke = null
drawer.rectangle(bg)
val circ = Circle(
width * 0.5,
height * 0.5,
width * 0.4
)
drawer.fill = ColorRGBa.BLACK
drawer.stroke = null
drawer.circle(circ)
val line0 = LineSegment(
width * 0.5 - width * 0.4,
height * 0.5,
width * 0.5 + width * 0.4,
height * 0.5,
)
drawer.stroke = ColorRGBa.fromHex("#c0f7ff")
drawer.strokeWeight = width * 0.05
drawer.lineSegment(line0);
}
extend {
drawer.clear(ColorRGBa.WHITE)
drawer.image(rt.colorBuffer(0), rect, rect)
}
}
}
This program draws a thick line and a clrcle. I expect the diameter of the circle having the same width/length as the thick line, but it is not the case. This is more noticeable when exporting (pressing ‘E’) the image and zoom in the exported result.
What am i doing wrong, or is it just a precision error ?
- rounding the numbers brings no solution
- the exported image, printed @ 300ppi should be 1000mm by 1000mm and then the error is (for me) very noticeable.