Skip to content

Commit

Permalink
11
Browse files Browse the repository at this point in the history
  • Loading branch information
villares committed Jan 12, 2025
1 parent 7f3e9b4 commit 46c1019
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
Binary file added 2025/sketch_2025_01_11/sketch_2025_01_11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 66 additions & 0 deletions 2025/sketch_2025_01_11/sketch_2025_01_11.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Wolfram's cellular automata + some color
# Inspired by something made by Carlos @vamoss a long time ago.

from random import choice
import numpy as np
import py5

rows = cols = 100
scale_factor = 8

def setup():
py5.size(800, 800)
py5.no_smooth()
py5.stroke_cap(py5.PROJECT)
py5.stroke_weight(scale_factor)
start()

def start():
global matrix, gen, ruleset
matrix = np.zeros((cols, rows), dtype=int)
matrix[cols // 2, 0] = 1 # Starts with "1" in the middle of the first line
matrix[:, 0] = [choice((0, 1)) for _ in range(cols)]
gen = 0
#ruleset = [choice((0, 1)) for _ in range(8)]
ruleset = np.array(list(reversed([1, 0, 1, 0, 0, 1, 1, 0])))
print(ruleset)

def predraw_update():
new_gen()
py5.window_title(f'{py5.get_frame_rate():0.1f}')

def draw():
py5.background(200)
offset = gen % rows
for i in range(cols):
for j in range(rows):
y = j - offset
if y <= 0:
y = rows + y
if matrix[i, j] == 1: # Se a célula i, está viva/ativa/1
left = matrix[(i + cols - 1) % cols, j - 1]
centre = matrix[i, j - 1]
right = matrix[(i + 1) % cols, j - 1]
c = py5.color(55 + left * 100, 55 + centre * 100, 55 + right * 100)
py5.stroke(c)
else:
py5.stroke(200)
py5.point(i * scale_factor , (y - 1) * scale_factor)


def new_gen():
global gen
current_row = matrix[:, gen % rows]
left = np.roll(current_row, 1)
right = np.roll(current_row, -1)
rule_idx = (left << 2) + (current_row << 1) + right
matrix[:, (gen + 1) % rows] = ruleset[rule_idx]
gen += 1

def key_pressed():
if py5.key == ' ':
start()
else:
py5.save_frame(f'{str(ruleset)}-###.png')

py5.run_sketch()
10 changes: 10 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ If you appreciate what I have been doing, you may also support my artistic work,
2025 \| [<b>2024</b>](2024.md) \| [<b>2023</b>](2023.md) \| [<b>2022</b>](2022.md) \| [<b>2021</b>](2021.md) \| [<b>2020</b>](2020.md) \| [<b>2019</b>](2019.md) \| [<b>2018</b>](2018.md)


---

### sketch_2025_01_11

![sketch_2025_01_11](https://raw.githubusercontent.com/villares/sketch-a-day/main/2025/sketch_2025_01_11/sketch_2025_01_11.png)

[sketch_2025_01_11](https://github.com/villares/sketch-a-day/tree/main/2025/sketch_2025_01_11) [[py5](https://py5coding.org/)]

#Wolfram #genuary2025 #genuary11 I wanted to optimize with NumPy but couldn't do much, the drawing part needs more work...

---

### sketch_2025_01_10
Expand Down

0 comments on commit 46c1019

Please sign in to comment.