here2share

# tk_img_combos_test.py

Sep 3rd, 2025
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.32 KB | None | 0 0
  1. # tk_img_combos_test.py
  2.  
  3. import tkinter as tk
  4. import itertools
  5. from collections import deque
  6.  
  7. width, height = 600, 600
  8. grid_size = 12
  9. cell_width = width // grid_size
  10. cell_height = height // grid_size
  11.  
  12. root = tk.Tk()
  13. root.title("# tk_img_combos_test.py")
  14. root.geometry('+0+0')
  15. canvas = tk.Canvas(root, width=width, height=height)
  16. canvas.pack()
  17. root.update()
  18.  
  19. colors_cache = []
  20.  
  21. def init_colors():
  22.     colors = []
  23.     step = 255 // grid_size
  24.     for r in range(0, 256, step):
  25.         for g in range(0, 256, step):
  26.             b = (r + g) % 256
  27.             color = "#{:02x}{:02x}{:02x}".format(r, g, b)
  28.             colors.append(color)
  29.             if len(colors) == grid_size * grid_size:
  30.                 break
  31.         if len(colors) == grid_size * grid_size:
  32.             break
  33.  
  34.     for i in range(grid_size):
  35.         row = []
  36.         for j in range(grid_size):
  37.             row.append(colors[i * grid_size + j])
  38.         colors_cache.append(row)
  39.  
  40.     for i in range(grid_size):
  41.         for j in range(grid_size):
  42.             draw_grid(i, j)
  43.  
  44. def draw_grid(i, j):
  45.     x0 = i * cell_width
  46.     y0 = j * cell_height
  47.     x1 = x0 + cell_width
  48.     y1 = y0 + cell_height
  49.     canvas.create_rectangle(x0, y0, x1, y1, fill=colors_cache[i][j], outline="black")
  50.  
  51. def update_grid_with_permutation(perm, count):
  52.     canvas.delete("all")
  53.     for i in range(grid_size):
  54.         for j in range(grid_size):
  55.             colors_cache[i][j] = perm[i * grid_size + j]
  56.             draw_grid(i, j)
  57.     canvas.create_text(
  58.         width // 2, height // 2,
  59.         text=f"Permutation Count: {count}",
  60.         font=("Arial", 30, "italic"),
  61.         fill="blue")
  62.     root.update()
  63.  
  64. def rotate_flat_list(flat, steps=1):
  65.     dq = deque(flat)
  66.     dq.rotate(steps)
  67.     return list(dq)
  68.  
  69. def run_sampled_rotated_permutations(flat, sample_step, total_frames):
  70.     for count in range(total_frames):
  71.         flat = rotate_flat_list(flat, count)
  72.         sample_index = count
  73.         flat = next(itertools.islice(itertools.permutations(flat), sample_index, sample_index + 1))
  74.         update_grid_with_permutation(flat, count + 1)
  75.         root.after(1)
  76.  
  77. init_colors()
  78. original_flat = list(sum(colors_cache, []))
  79. sample_step = 3
  80. total_frames = 1000000000
  81. run_sampled_rotated_permutations(original_flat, sample_step, total_frames)
  82. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment