array-example

Processing Day 7: Arrays

Today I started to watch the tutorials on arrays. I am sort of understanding them at this point, though I don’t think that I could write them on my own yet. I do understand their value, however, and am beginning to understand why Processing is excellent for data visualization because it enables you to draw things that would take FOREVER in Illustrator (or would be downright impossible.) In this particular example (which is from the lynda.com tutorial “Interactive Data Visualization with Processing” by Barton Paulson, an array is written with a loop that draws a line between 1000 random coordinates in an area.

This particular example really helped me to understand the great potential Processing has, especially because there are so few lines of code for such a complex drawing. It took only a few minutes to create. Could you imagine trying to draw this with Illustrator?!?

array-example

And here is the code used to create that drawing:

size(600,200);
background(255);
smooth();
stroke(#339933, 50);

int n = 1000;
float[] xTop = new float[n];
float[] xBottom = new float[n];

//make a loop to fill those in
for(int i = 0; i < n; i++) {
   xTop[i] = random(0, 600); 
 xBottom[i] = random(0, 600); 
 line(xTop[i], 0, xBottom[i], 200);

}