Advertisement
ZornTaov

Untitled

Sep 21st, 2010
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. integer isSierpinskiCarpetPixelFilled(integer x, integer y, integer width, integer height)
  2. {
  3. // base case 1 of 2
  4. if (x<1)
  5. {
  6. return 0;
  7. }
  8.  
  9. {
  10. //If the grid was split in 9 parts, what part(x2,y2) would x,y fit into?
  11. integer xTwo; // an integer from 0..2 inclusive
  12. xTwo = x*6/(width+3);
  13. integer yTwo; // an integer from 0..2 inclusive
  14. yTwo = y*6/(height+3);
  15.  
  16. // base case 2 of 2
  17. if (xTwo==1 && yTwo==1){ // if in the centre squaure, it should be filled.
  18. return 1;
  19. }
  20. // general case
  21. //offset x and y so it becomes bounded by 0..width/3 and 0..height/3
  22. //and prepares for recursive call
  23. x-=xTwo*width/3;
  24. y-=yTwo*height/3;
  25.  
  26. }
  27.  
  28. return isSierpinskiCarpetPixelFilled(x, y, width/3, height/3);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement