FAQ
 
 
Cover  \ Exhibition  \ Learning  \ Reference  \ Download  \ Discourse   
    Examples \ Tutorials \ Courses & Workshops
 
   
 
 
Examples for Processing (BETA) version 91+. If you have a previous version, use the examples included with your software. If you see any errors or have comments, please let us know.



Array 2D
by REAS <http://reas.com>

Demonstrates the syntax for creating a two-dimensional (2D) array. Values in a 2D array are accessed through two index values. 2D arrays are useful for storing images. In this example, each dot is colored in relation to its distance from the center of the image.

Created 09 December 2002

   
// Array 2D 
// by REAS <http://reas.com> 

float[][] distances; 
float maxDistance; 
 
size(200, 200); 
background(0); 
maxDistance = dist(width/2, height/2, width, height); 
distances = new float[width][height]; 
for(int i=0; i<height; i++) { 
  for(int j=0; j<width; j++) { 
    float dist = dist(width/2, height/2, j, i); 
    distances[j][i] = dist/maxDistance * 255; 
  } 
} 
 
for(int i=0; i<height; i+=2) { 
  for(int j=0; j<width; j+=2) { 
    stroke(distances[j][i]); 
    point(j, i); 
  } 
} 
 
 
 
 







   
  Processing is an open project initiated by Ben Fry and Casey Reas  
  © Info