summaryrefslogtreecommitdiff
path: root/1d_automata.py
diff options
context:
space:
mode:
authorNiclas Dobbertin <niclas.dobbertin@mailbox.org>2026-07-14 23:18:59 +0200
committerNiclas Dobbertin <niclas.dobbertin@mailbox.org>2026-07-14 23:18:59 +0200
commit0d707d4ffb2727584791260cf0ad0cdc36b3ee03 (patch)
treed22cf2f4732eca0213b6e33b2f3fd3765ff59544 /1d_automata.py
some automata
Diffstat (limited to '1d_automata.py')
-rw-r--r--1d_automata.py132
1 files changed, 132 insertions, 0 deletions
diff --git a/1d_automata.py b/1d_automata.py
new file mode 100644
index 0000000..699faa9
--- /dev/null
+++ b/1d_automata.py
@@ -0,0 +1,132 @@
+#!/usr/bin/env python3
+
+import numpy as np
+import matplotlib.pyplot as plt
+import random
+
+print("hello")
+
+# field = np.array([[0,1,1,0], [1,0,0,1], [0,0,0,0], [0,0,0,0]])
+
+
+def timestep(rule, field):
+ # if rule == "conway":
+ # for i in range(4):
+ # for j in range(4):
+ pass
+
+
+# print(field)
+# field = timestep("conway", field)
+#
+def rule30(field):
+ result = field.copy()
+ for i in range(len(field)-2):
+ x = [field[i], field[i+1], field[i+2]]
+
+ if x == [1,1,1]:
+ result[i+1] = 0
+ if x == [1,1,0]:
+ result[i+1] = 0
+ if x == [1,0,1]:
+ result[i+1] = 0
+ if x == [1,0,0]:
+ result[i+1] = 1
+ if x == [0,1,1]:
+ result[i+1] = 1
+ if x == [0,1,0]:
+ result[i+1] = 1
+ if x == [0,0,1]:
+ result[i+1] = 1
+ if x == [0,0,0]:
+ result[i+1] = 0
+ return result
+
+def rule184(field):
+ result = field.copy()
+ for i in range(len(field)-2):
+ x = [field[i], field[i+1], field[i+2]]
+
+ if x == [1,1,1]:
+ result[i+1] = 1
+ if x == [1,1,0]:
+ result[i+1] = 0
+ if x == [1,0,1]:
+ result[i+1] = 1
+ if x == [1,0,0]:
+ result[i+1] = 1
+ if x == [0,1,1]:
+ result[i+1] = 1
+ if x == [0,1,0]:
+ result[i+1] = 0
+ if x == [0,0,1]:
+ result[i+1] = 0
+ if x == [0,0,0]:
+ result[i+1] = 0
+ return result
+
+def rule110(field):
+ result = field.copy()
+ for i in range(len(field)-2):
+ x = [field[i], field[i+1], field[i+2]]
+
+ if x == [1,1,1]:
+ result[i+1] = 0
+ if x == [1,1,0]:
+ result[i+1] = 1
+ if x == [1,0,1]:
+ result[i+1] = 1
+ if x == [1,0,0]:
+ result[i+1] = 0
+ if x == [0,1,1]:
+ result[i+1] = 1
+ if x == [0,1,0]:
+ result[i+1] = 1
+ if x == [0,0,1]:
+ result[i+1] = 1
+ if x == [0,0,0]:
+ result[i+1] = 0
+ return result
+
+def ruletest(field):
+ result = field.copy()
+ for i in range(len(field)-2):
+ x = [field[i], field[i+1], field[i+2]]
+
+ if x == [1,1,1]:
+ result[i+1] = 0
+ if x == [1,1,0]:
+ result[i+1] = 0
+ if x == [1,0,1]:
+ result[i+1] = 0
+ if x == [1,0,0]:
+ result[i+1] = 1
+ if x == [0,1,1]:
+ result[i+1] = 0
+ if x == [0,1,0]:
+ result[i+1] = 0
+ if x == [0,0,1]:
+ result[i+1] = 1
+ if x == [0,0,0]:
+ result[i+1] = 0
+ return result
+
+field = [0] * 1000
+# field[500] = 1
+for i, _ in enumerate(field):
+ field[i] = random.choice([0, 1])
+# print(field)
+# exit(0)
+# print(field)
+# print(rule30(field))
+total_time = 1000
+history = []
+for t in range(total_time):
+ if t > 0:
+ field = ruletest(field)
+ # print(field)
+ history.append(field)
+
+plt.figure(figsize=(10,6))
+plt.imshow(np.array(history), cmap='hot')
+plt.show()