Advertisement
here2share

# tk_3D_flat_animation.py

Apr 23rd, 2023
901
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. # tk_3D_flat_animation.py
  2.  
  3. import math
  4. from tkinter import *
  5.  
  6. fov = 250
  7.  
  8. root = Tk()
  9.  
  10. ww = 600
  11. hh = 600
  12.  
  13. w = Canvas(root,width=ww,height=hh)
  14. w.pack()
  15.  
  16. class pixel:
  17.     def __init__(self,x,y,z):
  18.         self.x = x
  19.         self.y = y
  20.         self.z = z
  21.  
  22.  
  23. pixels = []
  24.  
  25. for x in range(-400,400,25):
  26.     for z in range(-250,250,25):
  27.         pixels.append(pixel(x,40,z))
  28.  
  29. size = 1
  30. def engine():
  31.     w.delete("all")
  32.  
  33.     for pix in pixels:
  34.         scale = fov/(max(1, fov+pix.z))
  35.  
  36.         x2d = pix.x * scale + ww / 2
  37.         y2d = pix.y * scale + hh / 2
  38.  
  39.         w.create_oval(x2d-size,y2d-size,x2d+size,y2d+size)
  40.  
  41.         pix.z -= 2
  42.  
  43.         if pix.z < -fov:
  44.             pix.z += 2*fov
  45.  
  46.     root.after(1,engine)
  47.  
  48. engine()
  49.  
  50. mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement