Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_rgb_interpolation_frosted.py
- import tkinter as tk
- import random
- ww = 400
- hh = 400
- canvas = tk.Canvas(width=ww, height=hh)
- canvas.pack()
- sq = 10
- sq2 = sq // 2
- rad = 1 / 11
- ddd = [0]
- def rgb():
- return [random.randint(128, 255) for i in range(3)]
- def interpolate():
- canvas.update()
- def dist(x = sq / 2, y = sq / 2):
- return round(((i - x) ** 2 + (j - y) ** 2) ** 0.5 * rad, 2)
- # Initialize the grid with the corner values
- def quad():
- r = cubic(0)
- g = cubic(1)
- b = cubic(2)
- color = f"#{r:02x}{g:02x}{b:02x}"
- x2,y2 = x+3,y+3
- canvas.create_rectangle(x2+i, y2+j, x2+i, y2+j, fill=color, outline="")
- def cubic(k):
- return min(255, max(0, int(t[k] * d + cc[k] * (1 - d)) + random.randint(-30, 30)))
- for y in range(0, hh, sq):
- for x in range(0, ww, sq):
- x2, y2 = x + sq, y + sq
- c1 = grid[x, y]
- c2 = grid[x + sq, y]
- c3 = grid[x, y + sq]
- c4 = grid[x + sq, y + sq]
- cc = [int((c1[k] + c2[k] + c3[k] + c4[k]) / 4) for k in (0,1,2)]
- for j in range(0, sq2):
- for i in range(0, sq2):
- t = c1
- d = dist()
- quad()
- for j in range(0, sq2):
- for i in range(sq2, sq):
- t = c2
- d = dist()
- quad()
- for j in range(sq2, sq):
- for i in range(0, sq2):
- t = c3
- d = dist()
- quad()
- for j in range(sq2, sq):
- for i in range(sq2, sq):
- t = c4
- d = dist()
- quad()
- canvas.update()
- while 1:
- grid = {}
- for x in range(0,(ww+sq+1),sq):
- for y in range(0,(hh+sq+1),sq):
- grid[x,y] = rgb()
- interpolate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement