here2share

# tk_Isometric_Rotating_Wire_Cube.py

Jun 28th, 2026
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.43 KB | None | 0 0
  1. # tk_Isometric_Rotating_Wire_Cube.py
  2.  
  3. import tkinter as tk
  4. import math
  5.  
  6. WIDTH, HEIGHT = 300, 300
  7.  
  8. CUBE_VERTICES = [
  9.     [-50, -50, -50], [50, -50, -50], [50, 50, -50], [-50, 50, -50],
  10.     [-50, -50,  50], [50, -50,  50], [50, 50,  50], [-50, 50,  50]
  11. ]
  12.  
  13. CUBE_EDGES = [
  14.     (0,1), (1,2), (2,3), (3,0),
  15.     (4,5), (5,6), (6,7), (7,4),
  16.     (0,4), (1,5), (2,6), (3,7)
  17. ]
  18.  
  19. root = tk.Tk()
  20. root.title("tk_Isometric_Rotating_Wire_CubeCube")
  21. root.resizable(False, False)
  22.  
  23. canvas = tk.Canvas(root, width=WIDTH, height=HEIGHT, bg="#111116", highlightthickness=0)
  24. canvas.pack()
  25.  
  26. rotation_angle = 0.0
  27.  
  28. while True:
  29.     canvas.delete("all")
  30.    
  31.     rotation_angle += 0.005
  32.     cos_a = math.cos(rotation_angle)
  33.     sin_a = math.sin(rotation_angle)
  34.  
  35.     active_points = []
  36.     for pt in CUBE_VERTICES:
  37.         x, y, z = pt
  38.         new_x = x * cos_a + y * (sin_a * sin_a) + z * (-cos_a * sin_a)
  39.         new_y = y * cos_a + z * sin_a
  40.         new_z = x * sin_a + y * (-sin_a * cos_a) + z * (cos_a * cos_a)
  41.         active_points.append([new_x, new_y, new_z])
  42.  
  43.     projected_points = []
  44.     for pt in active_points:
  45.         screen_x = 160 + pt[0]
  46.         screen_y = 160 + pt[1]
  47.         projected_points.append((screen_x, screen_y))
  48.  
  49.     for edge in CUBE_EDGES:
  50.         p1 = projected_points[edge[0]]
  51.         p2 = projected_points[edge[1]]
  52.         canvas.create_line(p1[0], p1[1], p2[0], p2[1], fill="#00FFCC", width=2)
  53.  
  54.     root.update()
Advertisement
Add Comment
Please, Sign In to add comment