Friday, July 9, 2010

Invader Fractal


Invader Fractal in Mel version 1 Still some squares being left out, but all in all looking good. version 2 Complete, but need to add more size variations version 4 variation 1 Rewrote most of the space filling portion, and added frames etc. variation 2 variation 3 Based on Jared Tarbells Invader Fractal. except done in maya melscript. Below is the space filling portion of the script, using a main grid of 100x50 squares, we go through each one($j), if $j is white, j++, if not, search a random sized area for white squares, if a white square exists, we search random sized area - 1 for white squares and so on until random size = 1 and it must be black due to the first condition. If the random sized area have no white squares, we call the invader_plane()(not shown), which makes the invader plane at that area, and color that particular area white on the main_grid and continue(j++). There are two for loops within the main loop, L loop for going horizontal, which are increments of 50, and the K loop going vertical, which are increments of 1.
------------------------------------------------------------------------------------------------
global proc main_method() {
 undoInfo -state off;
 global int $i;
 int $j, $k, $l, $ex;
 float $vtxPos[];
 string $xyz[];

 for($j = 0; $j < 5000; $j++) {

  print("START----------------------------------------\n");
  $ex = 0;
  select -cl;
  //int $j = 6;
  int $random_size = rand(1,11);
  hilite main_grid;
  for($l = ($random_size - 1) * 50; $l  >= 0; $l = $l - 50){
   string $bah[0] = `listSets -o main_grid.f[$j]`;
   $xyz[0] = $bah[0];
   if ($xyz[0] == "whiteShaderSG") {
  //  print("stopped immediately!!\n");
    $ex = 1;
    continue;
   }   
   for ($k = $random_size - 1; $k >= 0; $k = $k - 1) {
    select -add ("main_grid.f[" + ($j+$k+$l) + "]"); 
    print("K LOOP  ");
    print("main_grid.f[" + ($j+$k+$l) + "]\n" + "$j=" + $j + " $k=" + $k + " $l=" + $l/50 + " size=" + $random_size + "\n");   
    string $bah[0] = `listSets -o main_grid.f[($j + $k + $l)]`;
    if($bah[0] == "whiteShaderSG") {
  //   print("coord " + "random_size="  + $random_size + " k=" + $k + " l/50=" + ($l/50) + "\n"); //coordinate for white square
     int $dif;
     if($k > ($l/50)) {
      print("k larger");
      int $dif;
      for($dif = 0;$dif <= ($random_size - $l/50); $dif++) {
  //     print("dif=" + $dif + " random_size=" + $random_size + " k=" + $k + "\n");
       select -d ("main_grid.f[" + ($j+$k+$l+($dif*50)) + ":" + ($j+$k+$l+$random_size+($dif*50)) + "]");
      }
      for($dif = 0;$dif <= ($random_size - $k); $dif++) {
  //     print("dif=" + $dif + " random_size=" + $random_size + " k=" + $k + "\n");
       select -d ("main_grid.f[" + ($j + ($random_size - $dif) * 50) + ":" + ($j + $random_size + ($random_size - $dif) * 50) + "]");
      }
      $random_size = $k;
     }
     else if($k < ($l/50)) {
      print("l larger");
      $k = 0;
      select -cl;
      $random_size = $l/50;
     }
     else {
      select -cl;
      print("K is equal to L\n\n");
      $random_size = $k;
      $k = 0;
      break;
     }
    }
   }
  print(`ls -sl`);
  print("L LOOP   ");
  print("main_grid.f[" + ($j+$k+$l) + "]\n" + "$j=" + $j + " $k=" + $k + " $l=" + $l/50 + " size=" + $random_size + "\n\n");   
  } 
 if ($ex == 1) {
  continue;
 }
 hilite main_grid;
 sets -e -forceElement whiteShaderSG;
 print(`ls -sl`);           
 polyChipOff -ch 0 -kft 1 -dup 1 -off 0 `ls -sl`;
 polySeparate -ch 0 -n temp main_gridShape;  
 CenterPivot;
 move -r (($random_size/2)*(-1)) ($random_size/2) ($random_size/2) temp1.scalePivot temp1.rotatePivot;     
 select temp temp1;   
 parent -w;   
 select -r main_grid;
 doDelete;
 rename "temp" "main_grid";
 float $vtxPos[3] = `xform -q -ws -t temp1.vtx[0]`;
 select -r temp1;
 doDelete;
 invader_plane;
 ls -sl;
 move -r $vtxPos[0] ($vtxPos[1]+1) $vtxPos[2];
 scale -r ($random_size) ($random_size) ($random_size);
 $i++;
 }
}

------------------------------------------------------------------------------------------------

0 comments:

Post a Comment