Copyright (c) 2018 Lirimy
Released under the MIT license
https://opensource.org/licenses/MIT
using Images
using Colors
# Pascal's Triangle
N = 180
u = zeros(Int, N, N)
u[1, 1] = 1
# upper-left half
for i in 2:N # scan diagonally
# boundary
u[i, 1] = u[i-1, 1]
u[1, i] = u[1, i-1]
for j in 2:i-1
u[j, i-j+1] = mod(u[j-1, i-j+1] + u[j, i-j], 2) # XOR
end
end
# lower-right half
for i in 2:N
for j in i:N
u[j, N+i-j] = mod(u[j-1, N+i-j] + u[j, N+i-j-1], 2) # XOR
end
end
img = Gray.(u)
#save("sier-pascal.png", img)
# Cellular automata (Rule 90)
N = 360
M = Int(N/2)
u = zeros(Int, M, N)
u[1, Int(N/2)] = 1 # sierpinski triangle
#u[1, :] .= rand(0:1, N) # random init
for i in 2:M
u[i, 1] = mod(u[i-1, N] + u[i-1, 2], 2)
u[i, N] = mod(u[i-1, N-1] + u[i-1, 1], 2)
for j in 2:N-1
u[i, j] = mod(u[i-1, j-1] + u[i-1, j+1], 2)
end
end
img = Gray.(u)
#save("sier-rule90.png", img)