Advertisement
ZornTaov

carpet

Sep 21st, 2010
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Decides if a point at a specific location is filled or not.
  2. list carpet;
  3. //param x is the x coordinate of the point being checked
  4. //param y is the y coordinate of the point being checked
  5. //param width is the width of the Sierpinski Carpet being checked
  6. //param height is the height of the Sierpinski Carpet being checked
  7. //return 1 if it is to be filled or 0 if it is not
  8.  
  9. isSierpinskiCarpetPixelFilled(integer x,integer y,integer width,integer height)
  10. {
  11.     // base case 1 of 2
  12.     if (x<1)
  13.     {
  14.         carpet += "0";
  15.     }
  16.  
  17. {
  18.     //If the grid was split in 9 parts, what part(x2,y2) would x,y fit into?
  19.     integer xTwo; // an integer from 0..2 inclusive
  20.     xTwo = x*6/(width+3);
  21.     integer yTwo; // an integer from 0..2 inclusive
  22.     yTwo = y*6/(height+3);
  23.  
  24.     // base case 2 of 2
  25.     if (xTwo==1 && yTwo==1) // if in the centre squaure, it should be filled.
  26.         carpet += "1";
  27.  
  28.     // general case
  29.     //offset x and y so it becomes bounded by 0..width/3 and 0..height/3
  30.     //and prepares for recursive call
  31.     x-=xTwo*width/3;
  32.     y-=yTwo*height/3;
  33.    
  34. }
  35.  
  36.  
  37. }
  38.  
  39. // www.lsleditor.org  by Alphons van der Heijden (SL: Alphons Jano)
  40. default
  41. {
  42.     state_entry()
  43.     {
  44.         llSay(0, "Hello, Avatar!");
  45.     }
  46.     touch_start(integer total_number)
  47.     {
  48.         integer i;//loop 1
  49.         integer j;//loop 2
  50.         integer x;
  51.         integer y;
  52.         integer width = 3;
  53.         integer height = 3;
  54.         for (i=0;i<width;i++)
  55.         {
  56.  
  57.             isSierpinskiCarpetPixelFilled(x,y,i/3,j/3);
  58.             x++;
  59.             if(i == width)
  60.             {}//gonna do a double loop here instead of it being recursive
  61.  
  62.         }
  63.         llSay(0, llList2String(carpet,0));
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement