/* Copyright 1996 Matthew Freedman and University of Washington mattf@cac.washington.edu This program may be freely used, modified, or redistributed for any non-commercial purpose as long as credit is given. This file contains the NinaParams class for encapsulating everything Nina needs to know to draw a figure. */ import java.awt.*; import java.util.*; /* This class contains all the parameters a Nina Figure needs in order to draw itself, divided into line parameters, delay parameters, and color parameters. It has the following variables which can be set or read from the outside: Color related variables -- boolean ran_colors: Should number of colors be picked randomly? int max_colors: If yes, maximum number of colors possible. int num_colors: Actual number of colors to use. boolean ran_palette Should the specific colors be picked randomly? Color[] palette[16]: The specific colors to be used. Only the first num_colors are used in any figure. Color bg_color: Background color. Line related variables -- boolean ran_lines: Should number of lines be picked randomly? int max_lines: If yes, maximum number of lines possible. int num_lines: Actual number of lines to use. boolean ran_a_pulse:Should the A Pulse be picked randomly? int a_pulse: Actual value of A Pulse. boolean ran_b_pulse:Should the B Pulse be picked randomly? int b_pulse: Actual value of B Pulse. Delay related variables -- boolean show_lines: Should the line-drawing be shown? int ldelay: If yes, the delay in milliseconds between lines. boolean auto_draw: Should new figures be generated constantly? int fdelay: If yes, the delay in seconds between figures. NinaParams has the following methods callable from the outside: NinaParams(): A simple constructor. NinaParams(int seed): A constructor, with a seed for the random number generator. void setup(): Randomize all currently randomizable variables. void setupColors(): Randomize the color-related ones. setupLines(): Randomize the line-related ones. */ class NinaParams{ final int MAX_MAX_COLORS = 16; final int DFLT_MAX_COLORS = 4; final int DFLT_MAX_LINES = 2000; final int DFLT_LINE_DELAY = 5; final int DFLT_FIG_DELAY = 5; /* Outsiders might want to access any of the following. Stylistically, it would probably be better have access methods to get and change each of these variables, but I did not bother. */ /* Color */ public int max_colors, num_colors; public boolean ran_colors, ran_palette; public Color[] palette = new Color[MAX_MAX_COLORS]; public Color bg_color; /* Line */ public int max_lines, num_lines; public boolean ran_lines, ran_a_pulse, ran_b_pulse; public int a_pulse, b_pulse; /* Delay */ public int ldelay, fdelay; public boolean show_lines, auto_draw; private Random randy = new Random(); private ColorRandomizer crandy = new ColorRandomizer(); /* A constructor method does nothing but allocate the instance variables into defaults. Caller might want to change some afterwards */ NinaParams() { doInit(); } /* A constructor method that sets a seed for the random number generator */ NinaParams(int seed) { doInit(); randy.setSeed(randy.nextLong() + (long) seed); crandy.setSeed(seed); } /* A method to put in values for all parameters that supposed to be randomized. If a caller has set any parameters not to be randomized, they are responsible for making sure all values are set. */ public void setup() { setupColors(); setupLines(); } /* Setup just the colors */ public void setupColors() { int i; if (max_colors > MAX_MAX_COLORS) max_colors = MAX_MAX_COLORS; if (ran_colors) num_colors = getRan(1, max_colors); if (ran_palette) { /* Always fill the whole palette */ for (i = 0; i < MAX_MAX_COLORS; i++) { palette[i] = crandy.getOne(bg_color == Color.white); } } } /* Setup just the lines */ public void setupLines() { int i; if (ran_lines) num_lines = getRan(3, max_lines); if (ran_a_pulse) a_pulse = getRan(1, num_lines); if (ran_b_pulse) b_pulse = getRan(1, num_lines); } /* Initialize the variables */ protected void doInit() { max_colors = DFLT_MAX_COLORS; ran_colors = ran_palette = true; max_lines = DFLT_MAX_LINES; ran_lines = ran_a_pulse = ran_b_pulse = true; ldelay = DFLT_LINE_DELAY; fdelay = DFLT_FIG_DELAY; show_lines = true; auto_draw = false; bg_color = Color.black; } /* Return a random int between min and max */ protected int getRan(int min, int max) { return (Math.abs(randy.nextInt()) % (max - min + 1) + min); } }