My first Processing sketch

I am starting learning Processing http://processing.org/
a language for visual synthesis programming

this is my first sketch, it’s a set of rectangles changing colour linearly in gray scale.

int complete_size = 400;
int rects = 8;
float probability = 2; // from 0 to 100

int iteration = 0;
boolean increase = true;

int[ ][ ] rectvals = new int[rects][rects];

void setup()
{
  size(complete_size,complete_size);
  background(0);
}

void draw()
{
  int rectsize = complete_size / rects;
  for(int i =0; i < rects; i++)
  {
    for(int j =0; j < rects; j++)
    {
      fill(cycleVals(iteration,i,j));
      rect(i*rectsize,j*rectsize,rectsize,rectsize);
    }
  }

  if(increase)
    iteration++;
  else
    iteration--;

  if(iteration >=255)
      increase = false;
  if(iteration <=0)
    increase = true;
}

int cycleVals(int iteration, int i,int j)
{
  if(random(100) < probability)
   rectvals[i][j] = (int)(random(255));

  return 255-abs(iteration-rectvals[i][j]);
}  

void mousePressed()
{
   iteration =0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s