Advertisement
ZornTaov

Untitled

Sep 21st, 2010
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. default
  2. {
  3.  
  4. //Decides if a point at a specific location is filled or not.
  5. //param x is the x coordinate of the point being checked
  6. //param y is the y coordinate of the point being checked
  7. //param width is the width of the Sierpinski Carpet being checked
  8. //param height is the height of the Sierpinski Carpet being checked
  9. //return 1 if it is to be filled or 0 if it is not
  10. integer isSierpinskiCarpetPixelFilled(integer x, integer y, integer width, integer height)
  11. {
  12. // base case 1 of 2
  13. if (x<1){
  14. return 0;
  15. }
  16.  
  17. //If the grid was split in 9 parts, what part(x2,y2) would x,y fit into?
  18. integer xTwo = x*3/width; // an integer from 0..2 inclusive
  19. integer yTwo = y*3/height; // an integer from 0..2 inclusive
  20.  
  21. // base case 2 of 2
  22. if (xTwo == 1 && yTwo == 1){ // if in the centre squaure, it should be filled.
  23. return 1;
  24. }
  25.  
  26. // general case
  27.  
  28. //offset x and y so it becomes bounded by 0..width/3 and 0..height/3
  29. return isSierpinskiCarpetPixelFilled(x-(xTwo*width/3), y-(yTwo*height/3), width/3, height/3);
  30. }
  31.  
  32.  
  33.  
  34. state_entry()
  35. {
  36. integer width = 30;
  37. integer height = 30;
  38. for (integer j=0; j<height; j++){
  39. string row = "";
  40. for (integer i=0;i<width;i++)
  41. {
  42. row += (string)isSierpinskiCarpetPixelFilled(i,j,width,height);
  43. }
  44. llSay(0, row);
  45. }
  46. }
  47. touch_start(integer total_number)
  48. {
  49.  
  50.  
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement