Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. /**
  2. * this method will split rectangle horizentally
  3. */
  4. public void split_Horizentally(Graphics g,int start,int end,int width,int height)
  5. {
  6. Random R = new Random();
  7. int Height_Split_Point = getRandomPoint(R);
  8. int left_width = Height_Split_Point * width;
  9. int right_width = width - left_width;
  10.  
  11. g.setColor(c);
  12. g.fillRect(start,end,left_width,height);
  13. g.fillRect(start + left_width,end,right_width,height);
  14. recursionRect(g,start,end,left_width,height);
  15. recursionRect(g,start + left_width,end,right_width,height);
  16. }
  17.  
  18. /**
  19. * this method will split rectangle vertically
  20. */
  21. public void split_Vertically(Graphics g,int start,int end,int width,int height)
  22. {
  23. Random R = new Random();
  24. int Width_Split_Point = getRandomPoint(R);
  25. int top_height = Width_Split_Point * height;
  26. int bottom_height = height - top_height;
  27.  
  28. g.setColor(c);
  29. g.fillRect(start,end,width,top_height);
  30. g.fillRect(start,end + top_height,width,bottom_height);
  31. recursionRect(g,start,end,width,top_height);
  32. recursionRect(g,start,end + top_height,width,bottom_height);
  33. }
  34.  
  35.  
  36. /**
  37. * this method will draw rectangles recursively
  38.  
  39. */
  40. public void recursionRect(Graphics g,int start,int end,int width,int height)
  41. {
  42. Random R = new Random();
  43. int Height_Split_Point = R.nextInt((MINIMUM_REGION_LENGTH - ((3/2)*width)) + (int)((3/2)*width));
  44. int Width_Split_Point = R.nextInt((MINIMUM_REGION_LENGTH - ((3/2)*height)) + (int)((3/2)*height));
  45.  
  46. if(width>WIDTH/2 && height>HEIGHT/2)
  47. {
  48. splitBoth(g,start,end,width,height);
  49. }
  50. else if(width>WIDTH/2)
  51. {
  52. split_Vertically(g,start,end,width,height);
  53. // it shows error ^ here.
  54. }
  55. else if(height>HEIGHT/2)
  56. {
  57. split_Horizentally(g,start,end,width,height);
  58. }
  59. else if(Height_Split_Point <width )
  60. {
  61. split_Vertically(g,start,end,width,height);
  62. }
  63. else if(Width_Split_Point<height)
  64. {
  65. split_Horizentally(g,start,end,width,height);
  66. }
  67. else
  68. {
  69. g.fillRect(start,end,width,height);
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement