Advertisement
ridjis

SierpinskiArrowhead

Mar 26th, 2015
486
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  1. import java.awt.Graphics;
  2.  
  3. public class SierpinskiArrowhead extends FractalPainter {
  4.     private static final double ANGLE = Math.PI / 3.0;
  5.  
  6.     @Override
  7.     public void paint(Graphics g, int x, int y, int length, int order) {
  8.         turtle.reset(x, y);
  9.         int sign = 1;
  10.         sa(g, length, order, sign);
  11.     }
  12.    
  13.     public void sa(Graphics g, int length, int order, int sign) {
  14.         if (order == -1) {
  15.             turtle.move(g, length);
  16.         } else {
  17.             length /= 2;
  18.             order -= 1;
  19.            
  20.             turtle.turn(sign * ANGLE);
  21.             sa(g, length, order, -sign);
  22.             turtle.turn(-sign * ANGLE);
  23.             sa(g, length, order, sign);
  24.             turtle.turn(-sign * ANGLE);
  25.             sa(g, length, order, -sign);
  26.             turtle.turn(sign * ANGLE); 
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement