Kaushal Agrawal 13-9-65

by kaushal @ 9:59 pm 23 January 2012

//Number of rows and coloums in the patterns;
int pRow = 10; 
int pCol = 8;
int[][] pattern = new int[pRow][pCol];
int numXPoints,numYPoints;
PVector[][] gridPoints;
int initX, initY, aWidth, aHeight;
 
void setup(){
  size(600,650);
  background(255);
  smooth();
  numXPoints = pCol+1;
  numYPoints = pRow+1;
  initX = 50; initY = 50; aWidth=500; aHeight=500;
  gridPoints = new PVector[numYPoints][numXPoints];
  noFill();
  rect(initX,initY,aWidth,aHeight);  
 
   //Initialization
  gridPoints[0][0]=new PVector(initX,initY);
  int cellWidth = aWidth/pCol;
  int cellHeight= aHeight/pRow;
 
  //Determining the location of the points for the first row
  for(int j=1;j<numXPoints-1;j++)
    gridPoints[0][j]=new PVector(gridPoints[0][j-1].x+random(cellWidth-(cellWidth/2),cellWidth+(cellWidth/2)),gridPoints[0][j-1].y);
  gridPoints[0][numXPoints-1]=new PVector(initX+aWidth, initY);
 
  //Getting the location of points for the entire Art
  for(int i=1;i<numYPoints;i++){
    if(i==(numYPoints-1))
      gridPoints[i][0]=new PVector(gridPoints[i-1][0].x,initY+aHeight);
    else
      gridPoints[i][0]=new PVector(gridPoints[i-1][0].x,gridPoints[i-1][0].y+random(cellHeight-(cellHeight/4),cellHeight+(cellHeight/4)));
    for(int j=1;j<numXPoints;j++){
 
      int deviation = (int)random(-10,10);
      gridPoints[i][j]=new PVector();
      gridPoints[i][j].x=gridPoints[i-1][j].x;
      if(i==(numYPoints-1))
        gridPoints[i][j].y=gridPoints[i][j-1].y;
      else
        gridPoints[i][j].y=gridPoints[i][j-1].y+deviation;
      line(gridPoints[i][j-1].x,gridPoints[i][j-1].y,gridPoints[i][j].x,gridPoints[i][j].y);
    }
  }
 
  for(int i=0;i<pRow;i++){
    for(int j=0;j<pCol;j++){
      pattern[i][j]=(int)random(0,3);
    }
  }
  noLoop(); 
}
 
 
void draw(){
  for(int m=0;m<pCol;m++){
    int k = 0;
    while(k<pRow){
      int choice = pattern[k][m];
      //LINES
      if(choice == 1){
        int numLines = (int)random(6,17);
        int temp=k;
        for(int l=0;l<numLines;l++){
          float x = random(gridPoints[k+1][m].x, gridPoints[k+1][m+1].x);
          int z;
          for(z=k;z<pRow;z++){
            if(pattern[z][m]==1){
              int i = z+1;
              int j = m+1;
 
              float m1 = (gridPoints[i-1][j].y - gridPoints[i-1][j-1].y)/(gridPoints[i-1][j].x - gridPoints[i-1][j-1].x);
              float m2 = (gridPoints[i][j].y - gridPoints[i][j-1].y)/(gridPoints[i][j].x - gridPoints[i][j-1].x);
              float y2 = m2*(x-gridPoints[i][j].x)+gridPoints[i][j].y;
              float y1 = m1*(x-gridPoints[i-1][j].x)+gridPoints[i-1][j].y;
              line(x,y1,x,y2);
            }
            else{
              temp = z;
              break;
            }
          }
          temp=z;
        }
        k=temp;
      }
 
      //TRIANGLES
      else if(choice == 2){
        int numTriangles = (int)random(5,13);
        for(int l=0;l0){
            float x = random(gridPoints[i-1][j-1].x, gridPoints[i-1][j].x);
            float y = m1*(x-gridPoints[i-1][j].x)+gridPoints[i-1][j].y;
            float x1 = random(gridPoints[i][j-1].x, gridPoints[i][j].x);
            float y1 = m2*(x1-gridPoints[i][j].x)+gridPoints[i][j].y;
            line(x,y,x1,y1);
            float x2 = random(gridPoints[i][j-1].x, gridPoints[i][j].x);
            float y2 = m2*(x2-gridPoints[i][j].x)+gridPoints[i][j].y;
            line(x,y,x2,y2);
          }
 
          //Triangles start from bottom to top
          else{
            float x =  random(gridPoints[i][j-1].x, gridPoints[i][j].x);
            float y = m2*(x-gridPoints[i][j].x)+gridPoints[i][j].y;
            float x1= random(gridPoints[i-1][j-1].x, gridPoints[i-1][j].x);
            float y1 = m1*(x1-gridPoints[i-1][j].x)+gridPoints[i-1][j].y;
            line(x,y,x1,y1);
            float x2= random(gridPoints[i-1][j-1].x, gridPoints[i-1][j].x);
            float y2 = m1*(x2-gridPoints[i-1][j].x)+gridPoints[i-1][j].y;
            line(x,y,x2,y2);
          }
        } 
        k++;
      }
 
      //BLANK
      else
        k++;
    }
  }
 
  //Draw Circles
  int numCircles = (int)random(8,10);
  for(int l=0;l<numCircles;l++){
    float rad = random(5,70);
    float xc = random(initX+rad,(initX+aWidth-rad));
    float yc = random(initY+rad,(initY+aHeight-rad));
    ellipse(xc, yc, rad, rad);  
  }
}

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
(c) 2023 Interactive Art and Computational Design, Spring 2012 | powered by WordPress with Barecity