Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_img_combos_test.py
- import tkinter as tk
- import itertools
- from collections import deque
- width, height = 600, 600
- grid_size = 12
- cell_width = width // grid_size
- cell_height = height // grid_size
- root = tk.Tk()
- root.title("# tk_img_combos_test.py")
- root.geometry('+0+0')
- canvas = tk.Canvas(root, width=width, height=height)
- canvas.pack()
- root.update()
- colors_cache = []
- def init_colors():
- colors = []
- step = 255 // grid_size
- for r in range(0, 256, step):
- for g in range(0, 256, step):
- b = (r + g) % 256
- color = "#{:02x}{:02x}{:02x}".format(r, g, b)
- colors.append(color)
- if len(colors) == grid_size * grid_size:
- break
- if len(colors) == grid_size * grid_size:
- break
- for i in range(grid_size):
- row = []
- for j in range(grid_size):
- row.append(colors[i * grid_size + j])
- colors_cache.append(row)
- for i in range(grid_size):
- for j in range(grid_size):
- draw_grid(i, j)
- def draw_grid(i, j):
- x0 = i * cell_width
- y0 = j * cell_height
- x1 = x0 + cell_width
- y1 = y0 + cell_height
- canvas.create_rectangle(x0, y0, x1, y1, fill=colors_cache[i][j], outline="black")
- def update_grid_with_permutation(perm, count):
- canvas.delete("all")
- for i in range(grid_size):
- for j in range(grid_size):
- colors_cache[i][j] = perm[i * grid_size + j]
- draw_grid(i, j)
- canvas.create_text(
- width // 2, height // 2,
- text=f"Permutation Count: {count}",
- font=("Arial", 30, "italic"),
- fill="blue")
- root.update()
- def rotate_flat_list(flat, steps=1):
- dq = deque(flat)
- dq.rotate(steps)
- return list(dq)
- def run_sampled_rotated_permutations(flat, sample_step, total_frames):
- for count in range(total_frames):
- flat = rotate_flat_list(flat, count)
- sample_index = count
- flat = next(itertools.islice(itertools.permutations(flat), sample_index, sample_index + 1))
- update_grid_with_permutation(flat, count + 1)
- root.after(1)
- init_colors()
- original_flat = list(sum(colors_cache, []))
- sample_step = 3
- total_frames = 1000000000
- run_sampled_rotated_permutations(original_flat, sample_step, total_frames)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment