package com.flotow;import java.util.Scanner;import java.lang.Math.*;public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String shape; int r000; int r001; int r010; int r011; int r1; int runs = 0; int[] in = new int[1002]; for(int i = 0; i < in.length; i++){ if(i == 500){ in[i] = 1; }else{ in[i] = 0; } } System.out.println("Enter number of iterations."); System.out.println("----------------------------------"); int cycles = scan.nextInt(); int nums = 0; System.out.println("Choose the rule set. For the following cases\nEnter 1 if the rule should output a 1\nor Enter 0 if it should output 0."); System.out.println("011 -> "); r000 = scan.nextInt(); System.out.println("110 -> "); r001 = scan.nextInt(); System.out.println("10 -> "); r010 = scan.nextInt(); System.out.println("00 -> "); r1 = scan.nextInt();
System.out.println(""); System.out.println("What shape would you like to draw the fractal with?"); System.out.println(""); String wait = scan.nextLine(); shape = wait; String wait2 = scan.nextLine(); shape = wait2; System.out.println("Starting..."); System.out.println("----------------------------------"); while (true) { while (nums < cycles) { if(runs == 0) { Automata a = new Automata(in,r000,r001,r010,1,r1,shape); nums++; in = a.arrayOut(); } if(runs>0){ if(runs == 1){ RandomizeArray r = new RandomizeArray(); in = r.out(); } Automata b = new Automata(in,r000,r001,r010,1,r1,shape); in = b.arrayOut(); nums++; runs = 2; } } runs = 1; System.out.println("Go Again? ENTER 1 for yes or 0 for no."); int again = scan.nextInt(); if(again != 1){ break; } System.out.println("Enter number of iterations:"); System.out.println("----------------------------------"); cycles = scan.nextInt(); nums = 0; System.out.println("Choose the rule set. For the following cases\nEnter 1 if the rule should output a 1\nor Enter 0 if it should output 0."); System.out.println("011 -> "); r000 = scan.nextInt(); System.out.println("110 -> "); r001 = scan.nextInt(); System.out.println("10 -> "); r010 = scan.nextInt(); System.out.println("00 -> "); r1 = scan.nextInt(); System.out.println(""); System.out.println("What shape would you like to draw the fractal with?"); System.out.println(""); wait = scan.nextLine(); wait2 = scan.nextLine(); shape = wait2; System.out.println("Starting..."); System.out.println("----------------------------------"); } }}class Automata{ int[] X = new int[1002]; int[] newX = new int[1002]; int r000; int r001; int r010; int r011; int r1; public Automata(int[] X, int r000, int r001, int r010, int r011,int r1, String shape) { this.r000 = r000; this.r001 = r001; this.r010 = r010; this.r011 = r011; this.r1 = r1;
this.X = this.newX; CountCharacter c = new CountCharacter(shape); int spaces = c.stringCountOut(); String totalSpaces = "";
for(int j = 0; j < X.length-1; j++){// if(X[j]>99999 && X[j]<100000){// System.out.print(X[j]);// }else if(X[j]>99999 && X[j]<10000){// System.out.print(" "+X[j]);// }else if(X[j]>9999 && X[j]<100000){// System.out.print(" "+X[j]);// }else if(X[j]>999 && X[j]<10000){// System.out.print(" "+X[j]);// }else if(X[j]>99 && X[j]<1000){// System.out.print(" "+X[j]);// }else if(X[j]>9 && X[j]<100){// System.out.print(" "+X[j]);// }else if(X[j]>0 && X[j]<10){// System.out.print(" "+X[j]);// }else{// System.out.print(" "+0);// } if(X[j]%2==0){ System.out.print(" "); }else if(X[j]%3==0){ System.out.print("*"); }else if(X[j]%4==0){ System.out.print("-"); }else if(X[j]%5==0){ System.out.print("_"); }else if(X[j]%6==0){ System.out.print("="); }else if(X[j]%7==0){ System.out.print("+"); }else if(X[j]%8==0){ System.out.print("\\"); }else if(X[j]%9==0){ System.out.print("/"); }else if(X[j]%10==0){ System.out.print("`"); }else if(X[j]%11==0){ System.out.print("~"); }else if(X[j]%12==0){ System.out.print("!"); }else if(X[j]%13==0){ System.out.print("@"); }else if(X[j]%14==0){ System.out.print("#"); }else if(X[j]%15==0){ System.out.print("$"); }else if(X[j]%16==0){ System.out.print("%"); }else if(X[j]%17==0){ System.out.print("^"); }else if(X[j]%18==0){ System.out.print("&"); }else if(X[j]%19==0){ System.out.print("I"); }else{ System.out.print("v"); }
} for (int i = 0; i < X.length-1; i++) { if (i == 0) { if(X[i]>5000){ newX[i] = 0; } if(X[i]>X[1000]){ newX[i] = X[1000] + X[i] +3; }else if(X[i]<X[1000]){ newX[i] = X[1000] - X[i] +1; } else{ newX[i] = X[i] -1; } } else if (i >= 1 && i <= 999) { if(X[i]>5000){ newX[i] = 0; } if(X[i]>X[i-1]){ newX[i] = X[i-1] + X[i]+3; }else if(X[i]<X[i-1]){ newX[i] = X[i-1] - X[i] +1; } else{ newX[i] = X[i] -1; } } else if (i == 1000) { if(X[i]>5000){ newX[i] = 0; } if(X[i]>X[i-1]){ newX[i] = X[i] + X[0]+3; }else if(X[i]<X[0]){ newX[i] = X[0] - X[i] +1; } else{ newX[i] = X[i] -2; } } } for(int k = 0; k < X.length-1; k++){ this.X[k] = this.newX[k]; } System.out.println(""); } public int[] arrayOut(){ return this.X; }}class RandomizeArray{ int[] rando = new int[1002]; double randomNum = 0; public RandomizeArray(){ for(int i = 0; i < 1002; i++){ randomNum = Math.random(); if(randomNum>.96){ rando[i] = 1; }else if(randomNum>.99){ rando[i] = 2; }else{ rando[i] = 0; } } } public int[] out(){ return this.rando; }}class CountCharacter { String in; int count; public CountCharacter(String in) { this.count = 0; for (int i = 0; i < in.length(); i++) { this.count++; } } public int stringCountOut(){ return this.count; }}