Advertisement
Guest User

Untitled

a guest
Mar 1st, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.51 KB | None | 0 0
  1. import sk.upjs.jpaz2.JPAZUtilities;
  2. import sk.upjs.jpaz2.Turtle;
  3. import sk.upjs.paz.calltree.CallTree;
  4.  
  5. public class fraktalka extends Turtle {
  6.  
  7.     public void hexagonAmmann(int u, double d) {
  8.         double psi = Math.sqrt((Math.sqrt(5) - 1) / 2);
  9.  
  10.         if (u > 0) {
  11.             vykresliSomarinu(d, psi);
  12.             velkaRekurzia(u-1, d, psi, 2);
  13.             this.turn(90);
  14.             this.step(d * Math.pow(psi, 4));
  15.             this.step(d * Math.pow(psi, 2));
  16.             this.turn(90);
  17.         malaRekurzia(u-3, d, psi, 3);
  18.            
  19.         }
  20.  
  21.     }
  22.  
  23.     public void velkaRekurzia(int u, double d, double p, int mocnina) {
  24.         if (u > 0) {
  25.             vykresliMensiuSomarinu(d, p, mocnina);
  26.            
  27.             velkaRekurzia(u-1, d, p, mocnina+1);
  28.             if(u > 1){
  29.                 this.turn(90);
  30.             }
  31.             this.step(d * Math.pow(p, mocnina-1));
  32.            
  33.             this.malaRekurzia(u-3, d, p, mocnina+2);
  34.         }
  35.     }
  36.    
  37.     public void malaRekurzia(int u, double d, double p, int mocnina) {
  38.         JPAZUtilities.delay(1500);
  39.         if (u > 0) {
  40.             this.turn(90);
  41.             if(u==1){
  42.                 this.turn(-90);
  43.             }
  44.             vykresliEsteMensiuSomarinu(d, p, mocnina);
  45.             malaRekurzia(u-1, d, p, mocnina+1);
  46.             JPAZUtilities.delay(1500);
  47.            
  48.             this.turn(90);
  49.             this.step(d*Math.pow(p, mocnina+2));
  50.             this.step(d*Math.pow(p, mocnina+4));
  51.             this.turn(90);
  52.             this.velkaRekurzia(u-2, d, p, mocnina+2);
  53.         }
  54.     }
  55.  
  56.     // vykresli jeden kokot a vrati sa na zaciatok
  57.     private void vykresliSomarinu(double a, double p) {
  58.         this.step(a * Math.pow(p, 4));
  59.         this.step(a * Math.pow(p, 2));
  60.         this.turn(90);
  61.         this.step(a * Math.pow(p, 3));
  62.         this.turn(90);
  63.         this.step(a * Math.pow(p, 4));
  64.         this.turn(-90);
  65.         this.step(a * Math.pow(p, 5));
  66.         this.turn(90);
  67.         this.step(a * Math.pow(p, 2));
  68.         this.turn(90);
  69.         this.step(a * p);
  70.         this.turn(90);
  71.     }
  72.    
  73.     private void vykresliMensiuSomarinu(double a, double p, int m) {
  74.  
  75.         this.step(a * Math.pow(p, m+2));
  76.         this.turn(90);
  77.         this.step(a * Math.pow(p, m+3));
  78.         this.turn(-90);
  79.         this.step(a * Math.pow(p, m+4));
  80.         this.turn(90);
  81.         this.step(a * Math.pow(p, m+5));
  82.         this.step(a * Math.pow(p, m+3));
  83.         this.turn(90);
  84.         this.step(a * Math.pow(p, m));
  85.         this.turn(90);
  86.     }
  87.    
  88.     private void vykresliEsteMensiuSomarinu(double a, double p, int m){
  89.         this.step(a * Math.pow(p, m));
  90.         this.turn(90);
  91.         this.step(a * Math.pow(p, m+1));
  92.         this.turn(90);
  93.         this.step(a * Math.pow(p, m+2));
  94.         this.turn(90);
  95.         this.step(a * Math.pow(p, m+5));
  96.         this.turn(-90);
  97.         this.step(a * Math.pow(p, m+4));
  98.         this.turn(90);
  99.         this.step(a * Math.pow(p, m+3));
  100.         this.turn(90);
  101.         this.step(a * Math.pow(p, m));
  102.         this.turn(90);
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement