Skip to content
2 changes: 1 addition & 1 deletion .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
style = "blue"
style = "sciml"
whitespace_in_kwargs = false
always_use_return = true
margin = 92
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
fail-fast: false
matrix:
version:
- 'lts'
- '1'
os:
- ubuntu-latest
Expand All @@ -23,8 +24,8 @@ jobs:
arch:
- x64
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
Expand All @@ -48,8 +49,8 @@ jobs:
name: Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: '1'
- run: |
Expand All @@ -66,3 +67,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
GKSwstype: "100"
30 changes: 2 additions & 28 deletions .github/workflows/FormatCheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,7 @@ on:

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
julia-version: [1]
julia-arch: [x86]
os: [ubuntu-latest]
runs-on: ubuntu-latest
steps:
- uses: julia-actions/setup-julia@latest
with:
version: ${{ matrix.julia-version }}

- uses: actions/checkout@v4
- name: Install JuliaFormatter and format
# This will use the latest version by default but you can set the version like so:
#
# julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="0.13.0"))'
run: |
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter"))'
julia -e 'using JuliaFormatter; format(".", verbose=true)'
- name: Format check
run: |
julia -e '
out = Cmd(`git diff --name-only`) |> read |> String
if out == ""
exit(0)
else
@error "Some files have not been formatted !!!"
write(stdout, out)
exit(1)
end'
- uses: fredrikekre/runic-action@v1
16 changes: 13 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
name = "CellularAutomata"
uuid = "878138dc-5b27-11ea-1a71-cb95d38d6b29"
authors = ["Francesco Martinuzzi"]
version = "0.0.6"
version = "0.1.0"

[deps]
ConcreteStructs = "2569d6c7-a4a2-43d3-a901-331e8e4be471"

[compat]
JET = "0.9.18"
Aqua = "0.8"
ConcreteStructs = "0.2"
ForwardDiff = "0.10, 1"
JET = "0.9.18, 0.10, 0.11"
Random = "1.10"
SafeTestsets = "0.1"
Test = "1.10"
julia = "1.10"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "SafeTestsets", "Random", "Aqua", "JET"]
test = ["Test", "SafeTestsets", "Random", "Aqua", "ForwardDiff", "JET"]
101 changes: 50 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

| **Documentation** | **Build Status** | **Julia** | **Testing** | **DOI** |
|:-----------------:|:----------------:|:---------:|:-----------:|:-------:|
| [![docs][docs-img]][docs-url] | [![CI][ci-img]][ci-url] [![codecov][cc-img]][cc-url] | [![Julia][julia-img]][julia-url] [![Code Style: Blue][style-img]][style-url] | [![Aqua QA][aqua-img]][aqua-url] [![JET][jet-img]][jet-url] | [![DOI][doi-img]][doi-url]
| [![docs][docs-img]][docs-url] | [![CI][ci-img]][ci-url] [![codecov][cc-img]][cc-url] | [![Julia][julia-img]][julia-url] [![SciML Code Style][style-img]][style-url] | [![Aqua QA][aqua-img]][aqua-url] [![JET][jet-img]][jet-url] | [![DOI][doi-img]][doi-url]

[docs-img]: https://img.shields.io/badge/docs-stable-blue.svg
[docs-url]: [https://awesome-spectral-indices.github.io/SpectralIndices.jl/dev/](https://martinuzzifrancesco.github.io/CellularAutomata.jl/dev/)
[docs-url]: https://martinuzzifrancesco.github.io/CellularAutomata.jl/dev/

[ci-img]: https://github.com/MartinuzziFrancesco/CellularAutomata.jl/actions/workflows/CI.yml/badge.svg
[ci-url]: https://github.com/MartinuzziFrancesco/CellularAutomata.jl/actions/workflows/CI.yml
Expand All @@ -20,8 +20,8 @@
[julia-img]: https://img.shields.io/badge/julia-v1.10+-blue.svg
[julia-url]: https://julialang.org/

[style-img]: https://img.shields.io/badge/code%20style-blue-4495d1.svg
[style-url]: https://github.com/invenia/BlueStyle
[style-img]: https://img.shields.io/static/v1?label=code%20style&message=SciML&color=9558b2&labelColor=389826
[style-url]: https://github.com/SciML/SciMLStyle

[aqua-img]: https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg
[aqua-url]: https://github.com/JuliaTesting/Aqua.jl
Expand Down Expand Up @@ -49,21 +49,21 @@ julia> using Pkg
julia> Pkg.add("CellularAutomata")
```
or, on the REPL:

```julia_repl
julia> ] # actually press closed square brackets
julia> ] # actually press closed square brackets
pkg> add CellularAutomata
```

## Discrete Cellular Automata
The package offers creation of all the cellular automata described in A New Kind of Science by Wolfram, and the rules for the creation are labelled as in the book.
We will recreate some of the examples that can be found in the [wolfram atlas](http://atlas.wolfram.com/TOC/TOC_200.html) both for elementary and totalistic cellular automata.
We will recreate some of the examples that can be found in the [wolfram atlas](https://atlas.wolfram.com/TOC/TOC_200.html) both for elementary and totalistic cellular automata.

### Elementary Cellular Automata

Elementary Cellular Automata (ECA) have a radius of one and can be in only two possible states. Here we show a couple of examples:

[Rule 18](http://atlas.wolfram.com/01/01/18/)
[Rule 18](https://atlas.wolfram.com/01/01/18/)

```julia
using CellularAutomata, Plots
Expand All @@ -79,16 +79,16 @@ rule = 18

ca = CellularAutomaton(DCA(rule), starting_val, generations)

heatmap(ca.evolution,
yflip=true,
heatmap(evolution_history(ca),
yflip=true,
c=cgrad([:white, :black]),
legend = :none,
axis=false,
ticks=false)
```
![dca18](https://user-images.githubusercontent.com/10376688/75625854-4a816b00-5bc2-11ea-8337-9132553cd38b.png)

[Rule 30](http://atlas.wolfram.com/01/01/30/)
[Rule 30](https://atlas.wolfram.com/01/01/30/)

```julia
using CellularAutomata, Plots
Expand All @@ -104,8 +104,8 @@ rule = 30

ca = CellularAutomaton(DCA(rule), starting_val, generations)

heatmap(ca.evolution,
yflip=true,
heatmap(evolution_history(ca),
yflip=true,
c=cgrad([:white, :black]),
legend = :none,
axis=false,
Expand All @@ -128,13 +128,13 @@ ncells = 111
starting_val = zeros(ncells)
starting_val[Int(floor(ncells/2)+1)] = 2

rule = 7110222193934
rule = 7110222193934

ca = CellularAutomaton(DCA(rule,states=states,radius=radius),
ca = CellularAutomaton(DCA(rule,states=states,radius=radius),
starting_val, generations)

heatmap(ca.evolution,
yflip=true,
heatmap(evolution_history(ca),
yflip=true,
c=cgrad([:white, :black]),
legend = :none,
axis=false,
Expand All @@ -157,13 +157,13 @@ ncells = 111
starting_val = zeros(ncells)
starting_val[Int(floor(ncells/2)+1)] = 1

rule = 1388968789
rule = 1388968789

ca = CellularAutomaton(DCA(rule,states=states,radius=radius),
ca = CellularAutomaton(DCA(rule,states=states,radius=radius),
starting_val, generations)

heatmap(ca.evolution,
yflip=true,
heatmap(evolution_history(ca),
yflip=true,
c=cgrad([:white, :black]),
legend = :none,
axis=false,
Expand All @@ -187,13 +187,13 @@ ncells = 111
starting_val = zeros(ncells)
starting_val[Int(floor(ncells/2)+1)] = 2

rule = 914752986721674989234787899872473589234512347899
rule = 914752986721674989234787899872473589234512347899

ca = CellularAutomaton(DCA(rule,states=states,radius=radius),
ca = CellularAutomaton(DCA(rule,states=states,radius=radius),
starting_val, generations)

heatmap(ca.evolution,
yflip=true,
heatmap(evolution_history(ca),
yflip=true,
c=cgrad([:white, :black]),
legend = :none,
axis=false,
Expand All @@ -215,13 +215,13 @@ ncells = 111
starting_val = zeros(ncells)
starting_val[Int(floor(ncells/2)+1)] = 1

rule = 1235
rule = 1235

ca = CellularAutomaton(DCA(rule,states=states,radius=radius),
ca = CellularAutomaton(DCA(rule,states=states,radius=radius),
starting_val, generations)

heatmap(ca.evolution,
yflip=true,
heatmap(evolution_history(ca),
yflip=true,
c=cgrad([:white, :black]),
legend = :none,
axis=false,
Expand All @@ -235,7 +235,7 @@ heatmap(ca.evolution,

Totalistic Cellular Automata takes the sum of the neighborhood to calculate the value of the next step.

[Rule 1635](http://atlas.wolfram.com/01/02/1635/)
[Rule 1635](https://atlas.wolfram.com/01/02/1635/)

```julia
using CellularAutomata, Plots
Expand All @@ -249,19 +249,19 @@ starting_val[Int(floor(ncells/2)+1)] = 1

rule = 1635

ca = CellularAutomaton(TCA(rule, states=states),
ca = CellularAutomaton(TCA(rule, states=states),
starting_val, generations)

heatmap(ca.evolution,
yflip=true,
heatmap(evolution_history(ca),
yflip=true,
c=cgrad([:white, :black]),
legend = :none,
axis=false,
ticks=false)
```
![dca1635](https://user-images.githubusercontent.com/10376688/75628258-7eb35680-5bd7-11ea-81c5-b95b25f1369d.png)

[Rule 107398](http://atlas.wolfram.com/01/03/107398/)
[Rule 107398](https://atlas.wolfram.com/01/03/107398/)

```julia
using CellularAutomata, Plots
Expand All @@ -275,11 +275,11 @@ starting_val[Int(floor(ncells/2)+1)] = 1

rule = 107398

ca = CellularAutomaton(TCA(rule, states=states),
ca = CellularAutomaton(TCA(rule, states=states),
starting_val, generations)

heatmap(ca.evolution,
yflip=true,
heatmap(evolution_history(ca),
yflip=true,
c=cgrad([:white, :black]),
legend = :none,
axis=false,
Expand All @@ -290,7 +290,7 @@ heatmap(ca.evolution,

Here are some results for a bigger radius, using a radius of 2 as an example.

[Rule 53](http://atlas.wolfram.com/01/06/Rules/53/index.html#01_06_9_53)
[Rule 53](https://atlas.wolfram.com/01/06/Rules/53/index.html#01_06_9_53)

```julia
using CellularAutomata, Plots
Expand All @@ -304,11 +304,11 @@ starting_val[Int(floor(ncells/2)+1)] = 1

rule = 53

ca = CellularAutomaton(TCA(rule, radius=radius),
ca = CellularAutomaton(TCA(rule, radius=radius),
starting_val, generations)

heatmap(ca.evolution,
yflip=true,
heatmap(evolution_history(ca),
yflip=true,
c=cgrad([:white, :black]),
legend = :none,
axis=false,
Expand All @@ -335,8 +335,8 @@ rule = 0.025

ca = CellularAutomaton(CCA(rule), starting_val, generations)

heatmap(ca.evolution,
yflip=true,
heatmap(evolution_history(ca),
yflip=true,
c=cgrad([:white, :black]),
legend = :none,
axis=false,
Expand All @@ -359,11 +359,11 @@ starting_val[Int(floor(ncells/2)+1)] = 1.0

rule = 0.2

ca = CellularAutomaton(CCA(rule, radius=radius),
ca = CellularAutomaton(CCA(rule, radius=radius),
starting_val, generations)

heatmap(ca.evolution,
yflip=true,
heatmap(evolution_history(ca),
yflip=true,
c=cgrad([:white, :black]),
legend = :none,
axis=false,
Expand All @@ -374,7 +374,7 @@ heatmap(ca.evolution,

## Game of Life

This package can also reproduce Conway's Game of Life, and any variation based on it. The ```Life()``` function takes in a tuple containing the number of neighbors that will gave birth to a new cell, or that will make an existing cell survive. (For example in the Conways's Life the tuple (3, (2,3)) indicates having 3 live neighbors will give birth to an otherwise dead cell, and having either 2 or 3 lie neighbors will make an alive cell continue living.) The implementation follows the [Golly](http://golly.sourceforge.net/Help/changes.html) notation.
This package can also reproduce Conway's Game of Life, and any variation based on it. The ```Life()``` function takes in a tuple containing the number of neighbors that will gave birth to a new cell, or that will make an existing cell survive. (For example in the Conways's Life the tuple (3, (2,3)) indicates having 3 live neighbors will give birth to an otherwise dead cell, and having either 2 or 3 lie neighbors will make an alive cell continue living.) The implementation follows the [Golly](https://golly.sourceforge.net/Help/changes.html) notation.

This script reproduces the famous glider:

Expand All @@ -390,16 +390,15 @@ gens = 100
space_gliding = CellularAutomaton(Life((3, (2,3))), space, gens)

anim = @animate for i = 1:gens
heatmap(space_gliding.evolution[:,:,i],
yflip=true,
heatmap(evolution_history(space_gliding)[:, :, i],
yflip=true,
c=cgrad([:white, :black]),
legend = :none,
size=(1080,1080),
axis=false,
ticks=false)
end

gif(anim, "glider.gif", fps = 15)
```
![glider](https://user-images.githubusercontent.com/10376688/137601901-97940211-f6e7-4ab1-9eee-325165000fd4.gif)

4 changes: 4 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
CellularAutomata = "878138dc-5b27-11ea-1a71-cb95d38d6b29"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"

[compat]
Documenter = "1.17"
Plots = "1.41"
Loading
Loading