MahvishNagda-13-9-65

by mahvish @ 7:53 pm 23 January 2012





 
boolean getProbTrue(float prob){
  if (random(0, 1) <= prob)
    return true; 
  else 
    return false; 
}
 
int getYatX(int x0, int y0, int x1, int y1, int x){
  return y0 + (((x-x0)*(y1-y0))/(x1-x0)); 
}
 
void setup(){
  size(500, 500); 
}
 
void draw(){
 
  // set up for each frame
  background(255); 
  strokeWeight(1); 
  stroke(0); 
 
  // border
  line(0, 0, 0, height); 
  line(width-1, 0, width-1, height); 
  line(0, 0, width, 0); 
  line(0, height-1, width, height-1);  
 
  float loRange = 0.8; 
  float hiRange = 1.2; 
 
  int[] Xs = new int[9];       // stores the X coordinates for grid
  int[][] Ys = new int[9][9];  // stores the Y coordinates for grid
 
  int[][] fills = new int[9][9]; 
 
  int avXi = width/(Xs.length-1);    // average for each X segment
  int avYi = height/(Ys.length-1);   // average for each Y segment
 
  // get the random X coordinates
  Xs[0] = 0; 
  Xs[Xs.length-1] = width; 
  for(int i=1; i < Xs.length-1; i++){
      Xs[i] = Xs[i-1] + (int) random(loRange*avXi, hiRange*avXi); 
  }
 
  // get the random start Y coordinates
  for(int i=0; i < Ys.length; i++){
    int interval = (int) random(loRange*avYi, hiRange*avYi); 
    if(i==0) 
      Ys[i][0] = interval; 
    else
      Ys[i][0] = Ys[i-1][0] + interval; 
  }
 
  // get all other coordinates
  for(int i=0; i < Ys.length; i++){
    for(int j=1; j < Ys[i].length; j++){
      Ys[i][j] = Ys[i][j-1] + (int) random((loRange-1)*avYi, (1-loRange)*avYi); 
    }
  }
 
  // now let's plot these
  for(int i=0; i < Ys.length; i++){
    for(int j=1; j < Ys[i].length; j++){
      line(Xs[j-1], Ys[i][j-1], Xs[j], Ys[i][j]); 
    }
  }
 
  // choose segment fills
  for(int i=0; i < fills.length; i++){
    for(int j=0; j = 1 && fills[i-1][j] != 1 && 
		fills[i-1][j] != 3 && getProbTrue(0.05)){
          fills[i][j] = 2; 
        } 
        // crossed lines filling 1 segment
        else if(getProbTrue(0.35)){
          fills[i][j] = 3; 
        }
      }
 
    }
  }
 
  // lets add vertical lines   
  for(int i=0; i < Ys.length; i++){
    for(int j=1; j  0 && fills[i][j] == 2){
        numSegments = 2; 
      }
 
      if(numSegments > 0){
 
        // how many lines are we drawing 
        int numLines = (int) random(3, 15);
        if( fills[i][j] == 3) // just many more crossed lines 
           numLines *= 2; 
 
        for (int k=0; k  numSegments-1){ 
            Yks = getYatX( Xs[j-1], Ys[i-numSegments][j-1], 
				Xs[j], Ys[i-numSegments][j], Xk ); 
          }
 
          if(i < Ys.length){
            Yke = getYatX( Xs[j-1], Ys[i][j-1], Xs[j], Ys[i][j], Xe ); 
          }
 
          line(Xk, Yks, Xe, Yke);         
        }
      }
    }
  }
 
  // draw circles 
  for(int i=0; i < random(6,10); i++){
    int randX = (int) random(4, width); 
    int randY = (int) random(4, height); 
 
    int minofCorner = min(randX, randY); 
    minofCorner = min(minofCorner, width - randX); 
    minofCorner = min(minofCorner, height - randY); 
 
    int randRadius = (int) random(4, min(minofCorner, 80)); 
 
    noFill(); 
 
    ellipse(randX, randY, randRadius, randRadius); 
  }
 
  delay(1000); 
 
  if (keyPressed == true) {
    saveFrame("line-####.tif"); 
  }
}

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