Advertisement
gdog2u

TreeGen

May 11th, 2014
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1.             //t = tree char, b = trunk char, s = trunk size
  2.     public static String printTree(char t, char b, int s){
  3.         String out = "";
  4.         int test = s - s + 1;
  5.         for(int i = 0; i <= s/2; i++){ //this part generates the "leaves." I think this part is mostly fine.
  6.             for(int k = 0; k < (Math.ceil(s/2)+1)-(i+1); k++){
  7.                 out += " ";
  8.             }
  9.             for(int j = 0; j < test; j++){
  10.                 out += t;
  11.             }
  12.             test+=2;
  13.             out += "\n";
  14.         }
  15.         //if the size is even
  16.         if(s%2==0){
  17.              //following line purely for testing various numbers
  18.             System.out.println(s + "\n" + (int)(s*0.25)+"\n"+ Math.ceil((s*0.25)%2) + "\n" + s*0.1);
  19.             if(Math.ceil((s*0.25)%2) == 0){
  20.                 for(int i = 0; i < (s*0.25); i++){
  21.                     out+= " ";
  22.                 }
  23.                 for(int i = 0; i <= (s/2); i++){
  24.                     out+= b;
  25.                 }
  26.             }else{
  27.                 for(int i = 0; i < (int)(s*0.25)-((s*0.1)-1); i++){
  28.                     out+= " ";
  29.                 }
  30.                 for(int i = 0; i <= (s/2)+(s*0.1); i++){
  31.                     out+= b;
  32.                 }
  33.             }
  34.         }else{
  35.             for(int i = 0; i < (test*0.25)-2; i++){
  36.                 out+= " ";
  37.             }
  38.             for(int i = 0; i <= test/2; i++){
  39.                 out+= b;
  40.             }
  41.         }
  42.         return out;
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement