Skip to content

Commit

Permalink
02_01
Browse files Browse the repository at this point in the history
  • Loading branch information
villares committed Feb 2, 2025
1 parent 79bb837 commit db35d36
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
Binary file added 2025/sketch_2025_02_01/sketch_2025_02_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 67 additions & 0 deletions 2025/sketch_2025_02_01/sketch_2025_02_01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import py5
import numpy as np

noise_increment = 0.003

def setup():
global mesh_x, mesh_y, rgba_map, rgbb_map
py5.size(500, 500)
py5.color_mode(py5.HSB)
csa = [#py5.color(255) if i % 8 else
py5.color(i % 255, 200, 200)
for i in range(512)]


rgba_map = colors_to_colorarray(csa)

mesh_x, mesh_y = np.meshgrid(
np.arange(0, py5.width * noise_increment, noise_increment),
np.arange(0, py5.height * noise_increment, noise_increment)
)

def draw():
global sa, npa
py5.rect(0, 0, 500, 500)
osna = py5.os_noise(mesh_x + py5.mouse_x * noise_increment,
mesh_y + py5.mouse_y * noise_increment,
py5.frame_count * noise_increment)

color_indices = py5.remap(osna, -1, 1, 0, len(osna) - 1).astype(np.uint8)
npa = rgba_map[color_indices]
sa = sort_columns(npa)
py5.set_np_pixels(sa, bands="RGBA")
py5.window_title(str(round(py5.get_frame_rate(), 1)))


def colors_to_colorarray(color_list):
return np.dstack((
[c >> 16 & 0xFF for c in color_list],
[c >> 8 & 0xFF for c in color_list],
[c & 0xFF for c in color_list],
[0 if c == 255 else 255 for c in color_list], # note 255 is not a color...
))[0] # it serves as a sentinel value for

def sort_pixels_lexicographic(image_array):
global sorted_structured
# same as reshape (height*width, 4)
flat_image = image_array.reshape(-1, 4)
dtype = [('R', int), ('G', int), ('B', int), ('A', int)]
structured = np.array([tuple(row) for row in flat_image], dtype=dtype)
sorted_structured = np.sort(structured, order=['R', 'G', 'B', 'A'])
sorted_flat = np.array([tuple(pixel) for pixel in sorted_structured])
return sorted_structured.reshape(image_array.shape)


def sort_columns(image_array):
#image_array = np.asarray(image_array, dtype=np.uint8)
rows, cols, _ = image_array.shape
dtype = [('R', np.uint8), ('G', np.uint8), ('B', np.uint8), ('A', np.uint8)]
structured = np.array([tuple(p) for p in image_array.reshape(-1, 4)], dtype=dtype)
sorted_structured = np.sort(structured.reshape(rows, cols), axis=0)
return np.stack([sorted_structured[f] for f in ['R', 'G', 'B', 'A']], axis=-1)


def key_pressed():
py5.save_frame('out###.png')

py5.run_sketch(block=False)
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_02_01

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

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

Another #PixelSorting experiment I didn't heve the energy to try yesterday, also from an earlier #OSNoise sketch idea + #NumPy.

---

### sketch_2025_01_31
Expand Down

0 comments on commit db35d36

Please sign in to comment.