Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_Circular_Spiral_Fractal_Animation.py
- import tkinter as tk
- import math
- WIDTH, HEIGHT = 300, 300
- root = tk.Tk()
- root.title("Circular Spiral Fractal Animation")
- canvas = tk.Canvas(root, width=WIDTH, height=HEIGHT, bg='black')
- canvas.pack()
- rainbow = []
- def z(r, g, b):
- rainbow.append(f'#{r:02x}{g:02x}{b:02x}')
- r, g, b = 255, 0, 0
- for g in range(256):
- z(r, g, b)
- for r in range(254, -1, -1):
- z(r, g, b)
- for b in range(256):
- z(r, g, b)
- for g in range(254, -1, -1):
- z(r, g, b)
- for r in range(256):
- z(r, g, b)
- for b in range(254, -1, -1):
- z(r, g, b)
- Lcolors = len(rainbow)
- steps = (WIDTH/5) * (HEIGHT/5)
- incr = 100 / steps
- def circular_spiral_coords(width, height, step):
- cx, cy = width // 2, height // 2
- coords = []
- max_radius = math.sqrt(width**2 + height**2)
- num_points = int(max_radius / step * 360)
- a = 0.1
- b = 0.1
- for i in range(num_points):
- angle = a * i
- radius = b * angle
- x = (cx + radius * math.cos(angle)) // step * step
- y = (cy + radius * math.sin(angle)) // step * step
- if 0 <= x <= width and 0 <= y <= height:
- if (x, y) not in coords:
- coords.append((x, y))
- return coords
- spiral_order = circular_spiral_coords(WIDTH, HEIGHT, 5)
- pixels = {}
- i = 0
- for x, y in spiral_order:
- j = 50 + (i * incr)
- pixels[x, y] = [j, j]
- i += 1
- while 1:
- canvas.delete("all")
- for x, y in spiral_order:
- i, j = pixels[x, y]
- j = (i + j) % Lcolors
- pixels[x, y] = [i, j]
- color = rainbow[int(j)]
- canvas.create_rectangle(x, y, x+5, y+5, fill=color, outline='')
- canvas.update()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment