FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Topics & Contributions
   Information Visualization
(Moderators: forkinsocket, REAS)
   Sinuous rills
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Sinuous rills  (Read 1161 times)
JohnByrne


Sinuous rills
« on: Jul 2nd, 2003, 6:35am »

This is a variation on sinuousrills_1.pde in my previous posting.
 
John.
 
// 'SinuousRills_2'
// Programmed in Proce55ing (www.proce55ing.net) by John Byrne (j.byrne@mackillop.acu.edu.au), 2003.
// A tile pattern of twin semi-circles was published in 1987 by Cyril Smith of MIT, as a variant of the  
// work of Sebastian Truchet, published in 1704. Search the Web with key-word 'truchet' for an explanation.
// The semi-circles are approximated in this program by contiguous pixels, using setpixel().
// The picture is based on algorithmic random orientation of each tile. The viewer can adjust the  
// dwell time of each picture in the final statement: delay().
// Use the option Sketch/Present for best viewing against a gray (102,102,102) background.
void setup()
{
  size(440,440);
}
 
void loop()
{
 
// create a silver/gray background, brightest at the centre
for(int i=0; i<(width); i++)  
{  
  for(int j=0; j<(height); j++)  
  {  
    color gy = color(200-0.5*sqrt(sq(i-width/2)+ sq(j-height/2)), 200-0.5*sqrt(sq(i-width/2)+ sq(j-height/2)), 200-0.5*sqrt(sq(i-width/2)+ sq(j-height/2)));  
    setPixel(i, j, gy);  
  }  
}  
// create black patterns from (40x40) tiles, each tile being 11 pixels square
// and each tile randomly rotated 90 deg or not.
for (int i=0; i<(width); i=i+11)  
{  
  for(int j=0; j<(height); j=j+11)  
  {  
    color bk = color(0,0,0);
    stroke(bk);
    float r=random(4);  
    if (r <= 2)
    {// Tile pattern
    setPixel(i+5,j,bk);
    setPixel(i+5,j+1,bk);
    setPixel(i+5,j+2,bk);
    setPixel(i+6,j+3,bk);
    setPixel(i+7,j+4,bk);
    setPixel(i+8,j+5,bk);
    setPixel(i+9,j+5,bk);
    setPixel(i+10,j+5,bk);
    
    setPixel(i,j+5,bk);
    setPixel(i+1,j+5,bk);
    setPixel(i+2,j+5,bk);
    setPixel(i+3,j+6,bk);
    setPixel(i+4,j+7,bk);
    setPixel(i+5,j+8,bk);
    setPixel(i+5,j+9,bk);
    setPixel(i+5,j+10,bk);
    }
    else
    {// Tile pattern rotated 90 deg.
    setPixel(i+5,j,bk);
    setPixel(i+5,j+1,bk);
    setPixel(i+5,j+2,bk);
    setPixel(i+4,j+3,bk);
    setPixel(i+3,j+4,bk);
    setPixel(i+2,j+5,bk);
    setPixel(i+1,j+5,bk);
    setPixel(i,j+5,bk);
    
    setPixel(i+10,j+5,bk);
    setPixel(i+9,j+5,bk);
    setPixel(i+8,j+5,bk);
    setPixel(i+7,j+6,bk);
    setPixel(i+6,j+7,bk);
    setPixel(i+5,j+8,bk);
    setPixel(i+5,j+9,bk);
    setPixel(i+5,j+10,bk);
    }  
  }  
}
// change black pixels to blue, except at the edge of the image, leave two black pixels.
color b = color(0,0,127);
for (int i=2; i<(width-2); i++)  
{  
  for(int j=2; j<(height-2); j++)  
  {
  color p=getPixel(i,j);  
  if (red(p) == 0 && green(p) == 0 && blue(p) == 0)  
  {
  setPixel(i,j,b);
  }  
 }
}  
 
// Test if a black pixel has a blue contiguous pixel; if so, change the blue pixel to black.
// Repeat the test from the newly black pixel until no more contiguous blue pixels are found.
// The result is that only closed paths not connected to the edges of the picture are blue.
// All paths connected to the edges of the picture are black.
color bl = color(0,0,0);  
for (int i=1; i< (width-1); i++)  
{  
  for(int j=1; j< (height-1); j++)  
  {
 
  color p= getPixel(i,j);
  if (red(p) == 0 && green(p) == 0 && blue(p) == 0)
   {
   int k=i; int m=j; int endflag=0;
   while (endflag==0)
    {
    int oldk=k; int oldm=m;
    color p1=getPixel(k,m-1);
    color p2=getPixel(k+1,m-1);
    color p3=getPixel(k+1,m);  
    color p4=getPixel(k+1,m+1);
    color p5=getPixel(k,m+1);
    color p6=getPixel(k-1,m+1);
    color p7=getPixel(k-1,m);
    color p8=getPixel(k-1,m-1);  
  
    if ( red(p1) == 0 && green(p1) == 0 && blue(p1) == 127 )  
      {
       k=k; m=m-1;    
      }
    if (red(p2) == 0 && green(p2) == 0 && blue(p2) == 127 )  
      {
       k=k+1; m=m-1;    
      }
    if (red(p3) == 0 && green(p3) == 0 && blue(p3) == 127)  
      {
       k=k+1; m=m;    
      }  
    if (red(p4) == 0 && green(p4) == 0 && blue(p4) == 127)        
      {
       k=k+1; m=m+1;    
      }
    if (red(p5) == 0 && green(p5) == 0 && blue(p5) == 127)  
      {
       k=k; m=m+1;  
      }
    if (red(p6) == 0 && green(p6) == 0 && blue(p6) == 127)  
      {
       k=k-1; m=m+1;    
      }
    if (red(p7) == 0 && green(p7) == 0 && blue(p7) == 127)  
      {
       k=k-1; m=m;    
      }
   if (red(p == 0 && green(p == 0 && blue(p == 127)  
      {
       k=k-1; m=m-1;    
      }
   if (k==oldk  && m==oldm) {endflag=1;}  
   setPixel(k,m,bl);
  
   }
  }
 }
}
 
// remove all black pixels
for(int i=0; i<(width); i++)  
{  
  for(int j=0; j<(height); j++)  
  {  
    color gy = color(102,102,102);  
    color p = getPixel(i,j);
    if (red(p) == 0 && green(p) == 0 && blue(p) == 0)
     {
     setPixel(i, j, gy);  
     }
  }  
}  
 
delay(5000); // holds the picture for a time (mS)
}
« Last Edit: Jul 15th, 2003, 12:52am by JohnByrne »  
Pages: 1 

« Previous topic | Next topic »