-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCellularAutomata.jl
76 lines (59 loc) · 1.39 KB
/
CellularAutomata.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
module CellularAutomata
import Base.show
include("1dim.jl")
include("2dim.jl")
export CellularAutomaton,
CA2d,
rule,
show
#Print CA to screen
function show(io::IO, ca::CellularAutomaton)
io2 = IOBuffer()
arr = ca.cells
h, w = size(arr)
print(io2, "$(w)x$(h) Cellular Automaton")
print(io2, "\n")
#TODO: print rule
for i = 1:h
print(io2,"\t")
for j = 1:w
if arr[i,j] == 0
print(io2," ")
elseif ca.k == 2 && arr[i,j] == 1
print(io2,"#")
elseif ca.k == 3 && arr[i,j] == 1
print(io2,"X")
elseif arr[i,j] == 2
print(io2, "#")
end
end
print(io2,"\n")
end
print(io, String(io2))
end
#Print CA to screen
function show(io::IO, ca::CA2d)
io2 = IOBuffer()
arr = ca.cells
h, w, gen = size(arr)
print(io2, "$(w)x$(h)x$(gen) Cellular Automaton")
print(io2, "\n")
#TODO: print rule
for g in 1:gen
for i = 1:h
print(io2,"\t")
for j = 1:w
if arr[i,j, g] == 0
print(io2," ")
elseif arr[i,j, g] == 1
print(io2, "#")
end
end
print(io2,"\n")
end
print(io2,"\n\n")
end
print(io, String(io2))
end
#end of module
end