Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_Isometric_Rotating_Wire_Cube.py
- import tkinter as tk
- import math
- WIDTH, HEIGHT = 300, 300
- CUBE_VERTICES = [
- [-50, -50, -50], [50, -50, -50], [50, 50, -50], [-50, 50, -50],
- [-50, -50, 50], [50, -50, 50], [50, 50, 50], [-50, 50, 50]
- ]
- CUBE_EDGES = [
- (0,1), (1,2), (2,3), (3,0),
- (4,5), (5,6), (6,7), (7,4),
- (0,4), (1,5), (2,6), (3,7)
- ]
- root = tk.Tk()
- root.title("tk_Isometric_Rotating_Wire_CubeCube")
- root.resizable(False, False)
- canvas = tk.Canvas(root, width=WIDTH, height=HEIGHT, bg="#111116", highlightthickness=0)
- canvas.pack()
- rotation_angle = 0.0
- while True:
- canvas.delete("all")
- rotation_angle += 0.005
- cos_a = math.cos(rotation_angle)
- sin_a = math.sin(rotation_angle)
- active_points = []
- for pt in CUBE_VERTICES:
- x, y, z = pt
- new_x = x * cos_a + y * (sin_a * sin_a) + z * (-cos_a * sin_a)
- new_y = y * cos_a + z * sin_a
- new_z = x * sin_a + y * (-sin_a * cos_a) + z * (cos_a * cos_a)
- active_points.append([new_x, new_y, new_z])
- projected_points = []
- for pt in active_points:
- screen_x = 160 + pt[0]
- screen_y = 160 + pt[1]
- projected_points.append((screen_x, screen_y))
- for edge in CUBE_EDGES:
- p1 = projected_points[edge[0]]
- p2 = projected_points[edge[1]]
- canvas.create_line(p1[0], p1[1], p2[0], p2[1], fill="#00FFCC", width=2)
- root.update()
Advertisement
Add Comment
Please, Sign In to add comment