The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

tarundurga (1) [Avatar] Offline
#1
Hi... I was wondering if I could get some help with this.

This regards the code in 3.2 Iterative Variance, the introduction to creating noise. While I can see how the 'step' bit works, I can't figure out the italized part of the code. Why do lastx and lasty need to be -999? And why are we putting a conditional if on lastx > - 999?

size(500, 100);
background(255);
strokeWeight(5);
smooth();

stroke(20, 50, 70);
line(20, 50,480, 50);

stroke(20, 50, 70, 50);

int step = 10;
float lastx = -999;
float lasty = -999;
float y = 50;
int border = 20;
int bordery = 10;
for (int x = border; x<=width-border; x+=step) {
y = bordery +random(height - 2*bordery);
if(lastx >-999) {
line(x, y, lastx, lasty);
}
lastx = x;
lasty = y;
}
RainerWerner (1) [Avatar] Offline
#2
Re: 3.2 Iterative Variance Code Query
I had the same question