Search this site
Embedded Files
Skip to main content
Skip to navigation
Imperfect Permutable Elementary Cellular Automata
Home
2
3
4
5
6
7
8
Contact
Imperfect Permutable Elementary Cellular Automata
Home
2
3
4
5
6
7
8
Contact
More
Home
2
3
4
5
6
7
8
Contact
2.5
2.5: Perfect Permutable 1-space Ternary Midwise ECA
If an output is 0: draw " "
If output is 1: draw "|"
If output is 2: draw "+"
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
R001;
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(
"0 -> "
);
r000 = scan.nextInt();
System.
out
.println(
"1 -> "
);
r001 = 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,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,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(
"0 -> "
);
r000 = scan.nextInt();
System.
out
.println(
"1 -> "
);
r001 = scan.nextInt();
System.
out
.println(
""
);
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
;
public
Automata(
int
[] X,
int
r000,
int
r001,String shape) {
this
.
r000
= r000;
this
.
r001
= r001;
this
.
X
=
this
.
newX
;
CountCharacter c =
new
CountCharacter(shape);
int
spaces = c.stringCountOut();
String totalSpaces =
""
;
for
(
int
s = 0; s < spaces; s++){
totalSpaces = totalSpaces+
" "
;
}
for
(
int
j = 0; j < X.
length
-1; j++){
if
(X[j]==0){
System.
out
.print(totalSpaces);
}
else
{
System.
out
.print(shape);
}
}
for
(
int
i = 0; i < X.
length
-1; i++) {
if
(i == 0) {
if
(X[i] == 0){
this
.
newX
[i] =
this
.
r000
;
}
else if
((X[i] == 1)) {
this
.
newX
[i] =
this
.
r001
;;
}
}
else if
(i >= 1 && i <= 998) {
if
(X[i] == 0){
this
.
newX
[i] =
this
.
r000
;
}
else if
((X[i] == 1)) {
this
.
newX
[i] =
this
.
r001
;
}
}
else if
(i == 999) {
if
(X[i] == 0){
this
.
newX
[i] =
this
.
r000
;
}
else if
((X[i] == 1)) {
this
.
newX
[i] =
this
.
r001
;
}
}
}
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
(i==500){
rando
[i] = 1;
}
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
;
}
}
Report abuse
Page details
Page updated
Report abuse