I received some feedback on my earlier versions of the walking lines in the form of a trackback from Alex.
The feedback was part of a practice peer review, but he went into some detail on how i could fix up my current code so that the lines follow on from each other and how to reduce the load on the CPU per cycle with the same effect. The advice is greatly appreciated.
View the new version online here.
The changes and source code are after the jump.
Originally I had:
float x = random(width);
float y = random(height);
float x2 = random(width);
float y2 = random(height);void setup()
{
size(400, 400);
strokeWeight(10);
smooth();
background(100);
frameRate(12);
}
void draw()
{
x += int(random(width*2)-width);
y += int(random(height*2)-height);
x2 += int(random(width*2)-width);
y2 += int(random(height*2)-height);
stroke(random(255));
line(x, y, x2, y2);
}
Now I have:
float x = random(width);
float y = random(height);
float x2 = 0;
float y2 = 0;
float tempx = 0;
float tempy = 0;
void setup()
{
size(400, 400);
strokeWeight(10);
smooth();
background(100);
frameRate(12);
}
void draw()
{
x2 = random(-width, width);
y2 = random(-height, height);
stroke(random(255));
line(x, y, x2, y2);
x = x2;
y = y2;
}
The main changes are assigning the results of the random set of coordinates to the original coordinates with:
x = x2; y = y2;
These variables (x, y) were assigned 0 values initially and this is then replaced by the new coordinates at the end of every draw() cycle.
The other main change is the reduced load on the CPU with:
x2 = random(-width, width); y2 = random(-height, height);
This is in place of:
x2 += int(random(width*2)-width); y2 += int(random(height*2)-height);
Thats about it, ideally I should fix the colour changes as well so that they aren’t sharp changes with each line, but a gradual fade from one to another. I’ll see how I go experimenting with that and throw it up here as well when I get a chance.
Tags: Java, Lines, Processing, walking lines

