Advertisement
Guest User

Pythagoras

a guest
Jun 24th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1.     public static void drawRotatedRect(Graphics2D g, Vector pos, Vector up, int a, int height) {
  2.         Vector upRot = up.rotated(Math.PI / 2);
  3.  
  4.         Vector p1 = pos.added(up.scaled(a/2)).added(upRot.scaled(a/2));
  5.         Vector p2 = pos.added(up.scaled(a/2)).added(upRot.scaled(-a/2));
  6.         Vector p3 = pos.added(up.scaled(-a/2).added(upRot.scaled(a/2)));
  7.         Vector p4 = pos.added(up.scaled(-a/2).added(upRot.scaled(-a/2)));
  8.  
  9.         g.setColor(new Color(255 - a + 1, 0, a - 1));
  10.         g.fillPolygon(new int[]{(int)p1.x, (int)p2.x, (int)p4.x, (int)p3.x}, new int[]{height - (int)p1.y, height - (int)p2.y, height - (int)p4.y, height - (int)p3.y}, 4);
  11.     }
  12.  
  13.     public static void drawSegment(Graphics2D g, Vector pos, Vector up, int a, int height) {
  14.         drawRotatedRect(g, pos, up, a, height);
  15.  
  16.         if (a < 3) {
  17.             return;
  18.         } else {
  19.             Vector up1 = up.rotated(Math.PI / 4);
  20.             Vector up2 = up.rotated(- Math.PI / 4);
  21.             Vector pos1 = pos.added(up1.scaled(a / 2));
  22.             Vector pos2 = pos.added(up2.scaled(a / 2));
  23.             a = (int) ((double) a / Math.sqrt(2));
  24.             drawSegment(g, pos1, up1, a, height);
  25.             drawSegment(g, pos2, up2, a, height);
  26.         }
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement