Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_3D_procedural_slither.py
- import tkinter as tk
- import math
- import random
- ww = 600
- hh = 600
- cx, cy = ww//2, hh//2
- direction = [0, 0, 0, 0] # initial direction
- degrees = math.radians(359.9999999999)
- print(degrees)
- root = tk.Tk()
- root.title("tk_3D_procedural_slither")
- root.geometry("%dx%d+10+10"%(ww,hh))
- canvas = tk.Canvas(root, bg='white', width=ww, height=hh)
- canvas.pack()
- points = []
- angles = [angle*0.0002 for angle in range(100, 401)]
- angles += [-angle*0.0002 for angle in range(100, 401)]
- def movement():
- x = int(cx + math.cos(direction[0]) * (math.cos(direction[1]) * (cx - 350)))
- y = int(cy + math.sin(direction[2]) * (math.sin(direction[3]) * (cy - 250)))
- return (x, y)
- rgb = [i for i in range(0, 256, 5)]
- colors = ['#{:02x}{:02x}{:02x}'.format(r,g,b) for r in rgb for g in rgb for b in rgb][40:-40]
- random.shuffle(colors)
- p = []
- i = 0
- points.append(movement())
- scale = 1.01
- # Zoom into the center of the screen
- while True:
- try:
- canvas.delete(p.pop(-160))
- except:
- 0
- points.append(movement())
- points = points[-2:]
- angles.extend([angles.pop(0), angles.pop(101), angles.pop(57), angles.pop(21)])
- angles.insert(11, angles.pop(99))
- direction = [angles[-i] + direction[i] for i in (0, 1, 2, 3)] # update the direction
- canvas.scale('all', cx, cy, scale, scale)
- for item in canvas.find_all():
- width = canvas.itemcget(item, 'width')
- new_width = float(width) * 1.01
- canvas.itemconfig(item, width=new_width)
- color = colors.pop(0)
- p += [canvas.create_line(points, smooth=True, fill=color, width=3, capstyle='round')]
- canvas.lower(p[-1])
- colors.insert(-(10-int(i%10)), color)
- i += scale
- i %= 999999999999
- canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement