Tuesday, 28 April 2009

Chunk 37 Outline

Next step to apply abstraction and functional approach to drawing lines with special properties.

Characteristics of line: start, end points and path between. Anything can happen along line as random or other factors are applied to it.

Underlying path across a grid of pixels and problems drawing it: Bresenham's algorithm.

Abstracting error-value checking to a closure - simple implementation, optimization.

Writing a function to draw a line between any two points, any width with a colour gradient along its length: needs end points of lines normal to conceptual underlying line.

Writing another closure to return maximum-width end-points of lines at points along underlying length. Problem: filling in missing pixels between adjacent lines due to jagged profile when they offset along underlying line.

Program draws colour gradient lines.

Applying similar closure approach to diverse grids: circular and random spaced grid using array.

PROGRAM 3D grid and thistle-down blob drawn with colour grad lines, moves along its length.

Mostly code: say 48 hours work, 2 weeks max. Time to post code on blogger????

Thursday, 9 April 2009

In Search of Processings Lost

As you may have noticed, Processing programs that use random() and/or noise() and do not set the seed for these functions before they are called, create a different output for each run. The run that gets the superb effect is lost forever but setting seeds always gets the same old effect as the last time. To retain random creation and the capability of recreating a successful run it would nice if the value of seeds could be read at the beginning of a run and stored for future reference. Unfortunately this is not possible - the underlying Java Random class sets seed randomly from its () constructor and does not include a method for retrieving a value that can be used with setSeed().

A workaround is to generate a value for seed using a similar procedure to Random's, record it, and then pass it to a seed setter:

void setup() {
long seed = 8682522807148013L + System.nanoTime();

output: 8702777365341749

If this run turns out to be the great one change setup() to

void setup() {
// long seed = 8682522807148013L + System.nanoTime();
// System.out.println(seed);

identical graphic output is recreated. Otherwise, just continue with the original setup() version and hope for the best. The same seed generation method is appropriate for noiseSeed(). The seed calculation shown will avoid holes in the total sequence of values returned by nextLong() - if such exist and affect the 48 bit seed used by Random that is.