Algorithmic Image Generator

MAT299 - Independent Study, advised by George Legrady

Introduction

The project's goal was to implement a visualization and experimentation tool for 2D trigonometric functions, which can be used to produce animated image sequences and export three-dimensional data. In addition, it was to use a compatible mathematical syntax with Macromedia Director for use in prototyping interactive media installations. By allowing the user to dynamically modify mathematical expressions and preview the results, it bypasses the tedious process of having to stop, modify source code, and recompile/restart an application in order to view changes, which speeds workflow and promotes experimentation.

User interface

Figure 1 - User interface (click to enlarge)

Features

For example, using the project's software, the function:
f(x,y,z) = y/cos(sin(sin(y*y+x)/(y/pi*y)-(z/0.875))*x/cos(log(pi-z)*z))
was developed and exported to the following formats:

Image (PNG format)
XML (XML-encoded JavaBean)
MathML
3D (STL format)

allowing it to be used in a wide variety of applications. Further examples can be seen below.

Animation Examples

(requires quicktime 6)

f=sin(x*x+y*y+z*z)
zoneplate.mov
(2MB)
A complicated mix of 3 functions (H+S+B)
bacteria.mp4 (1.9MB)
f=cos(z*y)/(z+sin(x-cos(z/y-y))-(tan(z)+sin(z+x)))
turtle.mp4 (2.5MB)
A complicated mix of 3 functions (Y+Ca+Cb)
recede.mp4 (1.1MB)
f=z+(cos(atan(x+y,y/z-x)+(y+x/z)+z)/y-abs(cos(z*x/y)*sin(x+y+z)+y))+y
sailing.mp4 (0.7MB)
f=max(1+cos(abs(z)+sqrt(z-x))+x,1/y)-abs(tan(sqrt(pi*pi)-z+log(y/x))-z-z)-tan(cos(z-y)*x*cos(z+sin(z-z*x)))
inca.mp4 (2.8MB)

3d Output Examples

Figure 2 - 2D and 3D representations of cos((cos(y)-sin(x)/pi)*sqrt(y+abs(y-(x)+pi))*pi)/2+1/2

Figure 3 - 2D and 3D representations of sin((sin(x))*(sin(y)*2*pi))/2+1/2

 

 

Figure 4 - 2D and 3D representations of sin(x+sin(x))*sin(y+sin(y))/2+1/2

 

Figure 5 - 2D and 3D representations of sin(x*sin(x)/y*cos(y)*x*sin(2*y))/3

 

other examples

Figure 6 - MathML export viewed in popular equation editor

Implementation Notes

This project was implemented in the Java programming language, with a Director-based portion implemented using the Lingo scripting language.

The Director-compatible syntax was implemented using the JeksParser library, which is an extensible framework for parsing and computing mathematical expressions.

One difficulty encountered was that it was impossible to easily predict the possible range of values an inputted function might produce. This caused problems when attempting to map a function's numeric values to appropriate color values, and would frequently result in all black or all white images. To alleviate this, alternate out-of-bounds color behaviors were implemented. In addition to a standard limiting behavior (f < min, f = min; f > max, f = max), out-of-bounds values can alternately be reflected (even cycle, f=|value%(max-min)|+2min; odd cycle, f=max-|value%(max-min)|+min), or wrapped (f =|value%(max-min)|+min). (See figure 7 below).

Figure 7 - Out-of-bounds coloring behavior (limit, reflect, and wrap)

References and Links

eTeks Jeks parser
Macromedia Director