NINANINA Source Code

NINA generates incredibly beautiful figures with a remarkably simple algorithm:

num_lines = some integer
a_pulse = some integer less than num_lines
b_pulse = some integer less than num_lines
for (count = 0; count < num_lines; count++) {
  cur_x = cos((-2*PI*a_pulse*count)/num_lines) +
          cos((-2*PI*b_pulse*count)/num_lines);
  cur_y = sin((-2*PI*a_pulse*count)/num_lines) +
          sin((-2*PI*b_pulse*count)/num_lines);
  draw line from (prev_x, prev_y) to (cur_x, cur_y)
  prev_x = cur_x; prev_y = cur_y;
}

On this page are links to each of the .java files that comprise NINA, along with a general explanation of what classes are in each file, and how those classes are used. For more detailed explanations, such as specific methods and variables that are available, follow the links, and read the header comments for the files. Feel free to send me questions/comments about the code.

Nina.java
Nina is the heart of NINA, a subclass of Canvas that draws pretty pictures. By NINA I mean the whole shebang, including the interface. Nina just means this core object.
NinaParams.java
A crucial class that encapsulates all the parameters necessary for Nina to draw a figure.
ColorRandomizer.java
A small class, used for picking random colors. It has some slight optimizations for selecting better looking colors depending on whether the figure background is black or white.
MiniNina.java
A tiny sample applet that demonstrates how easily you can re-use just the above three pieces, and embed a Nina anywhere you like. Detailed information on how to embed MiniNina applets on your own web pages is available. Embedded MiniNina applets look like this:
NinaController.java
A trivial interface definition, which an object that controls a Nina may want to implement.
NinaShell.java
You may have noticed that the NINA pages each contain five separate applets, placed in separate cells of a table. I mostly did this because it looks cool, and was not much harder. This file is the applet wrapper for the Nina object. It is the only piece that knows whether we are running in a floating window or inlined.
ControllerController.java
This is the applet that contains the three buttons. It has overall control over NINA, and handles the communications between the individual parameter controllers and the Nina object.
GenericController.java
A small, but important class which is never actually instantiated. However the next three items are subclassed off of it.
LineControllers.java
The applet that holds Conrollers for Number of Lines, A Pulse and B Pulse.
DelayControllers.java
The applet that holds Controllers for Show Animation and Auto Draw.
ColorControllers.java
The applet that holds Controllers for Number of Colors and Palette.
Controller.java
A class hierarchy that builds individual Controller objects.
ColorFrame.java
The classes that define the interactive color-chooser.