Friday, December 04, 2009

GroundSkyLines

/**
 * Draw some lines like MC Escher would have...
 * by Evan Rakob AKA PixelPusher 
* // http://pixelist.info
 **/
 
 // the initial spacing between lines, in pixels
 float spacing = 1f;
 
 // line width in pixels (from middle of line)
 int lineWidth = 1;
 
 // the multiplier for the spacing of successive lines
 float spaceMult = 1.001f;
 
 boolean mouseDown = false;
 int[] startMouse = new int[2];
 int[] lastMouse = new int[2];
 
 
 void setup()
 {
     size(360, 240);
     background(0);
     strokeWeight(lineWidth);

     spacing = 1f;
  
  lineWidth = 1;
  
  spaceMult = 1.001f;
  
  mouseDown = false;
  startMouse = new int[2];
  lastMouse = new int[2];

     startMouse[0] = -1;
     startMouse[1] = -1;
 }
 
 
 void draw()
 {
   background(0);
   if (mouseDown)
   {
       if (lastMouse[1] != mouseY)
       {
         spaceMult += (startMouse[1]-mouseY)*0.001;
         spaceMult = max(spaceMult, 1.001);

         lastMouse[1] = mouseY;
       }
       else
       {
         startMouse[1] = mouseY;
       }

   }
   
   
   int ctr=0;  // counter var
   float space = spacing;
   
   //first draw white bg below
   fill(255);
   noStroke();
   rect(0, 0, width, height*0.5);
   
   // draw black lines from center to top
   
   ctr = int(height*0.5-space);
   
   strokeWeight(lineWidth);
   stroke(0);
   
   while (ctr > 0)
   {
     line(0, ctr, width, ctr);
     ctr -= int(2*space);
     space *= spaceMult;
   }
   
   // draw white lines from center to bottom
   
   stroke(255);
   space = spacing;
   ctr = int(height*0.5-space);
   
   while (ctr < height)
   {
     line(0, ctr, width, ctr);
     ctr += int(2*space);
     space *= spaceMult;
   }
 }
 
 
void mousePressed() 
{
   startMouse[0] = mouseX;  
   startMouse[1] = mouseY;
   lastMouse[0] = startMouse[0];
   lastMouse[1] = startMouse[1];
   mouseDown = true;
}

void mouseReleased() 
{
   mouseDown = false;
}

info info

submitted by: evanraskob
views: 857
Inspired by M. C. Eschers prints, this was a common (I think) was of representing the perspective of the sky and ground receding into infinity using simple horizontal lines. Drag up and down on the sketch to change the line spacings.

Tags: line, art, pixelpusher, interactive

comments comment

loading loading...

 

Add a comment: