While I was reading the excellent book by Kevin Suffern
"Ray tracing from the ground up",
I implemented a ray tracer in Java and wrote a DSL in Groovy, to describe scenes more easily and dynamically.
migrated the code from C++ to Java
made the code "more" object oriented
made the code thread-safe for parallel execution
wrote a DSL for easy scene creation and manipulation
The following image ...
... is defined by the following DSL:
There is a white plane, an orange sphere, some triangles, etc. grid is used to
store objects in a grid-like data structure to speed up look ups.
Behind the scenes the DSL is translated into Java calls.
A grid is used also in the following image:
I also implemented ambient occuclusion:
In this image there are three light sources in red, green and blue and the white ambient light. The DSL is:
Here an "instantiation" with translation and scaling is used.
One of the big advanges of using a Groovy DSL is, that it is interpreted and runtime and so you can
change the source and run it again without recompiling or restarting the program.
In the next example you can see the reflections for some geometric objects.