Advertisement
felixnardella

3D Octahedron Coordinates for C64

Apr 29th, 2025
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.47 KB | Source Code | 0 0
  1. """
  2. Programma: ottaedro_rotazione.py
  3.  
  4. Descrizione:
  5. Questo script Python calcola e genera le coordinate dei vertici di un ottaedro regolare,
  6. applicando una rotazione nello spazio (3D) attorno agli assi X, Y.
  7. Per ogni passo della rotazione, vengono proiettate le coordinate 3D su un piano 2D
  8. e convertite in coordinate schermo compatibili con la modalità bitmap del Commodore 64.
  9.  
  10. Il risultato finale è un insieme di frame precalcolati contenenti le coordinate
  11. dei vertici, pronte per essere utilizzate direttamente nel programma Assembly
  12. sul C64.
  13.  
  14. Requisiti:
  15. - Python 3.x
  16. - Nessuna libreria esterna (usa solo moduli standard)
  17.  
  18. Autore: Kimono (Felice Nardella)
  19. Data: marzo 2025
  20.  
  21. Utilizzo:
  22. Eseguire questo script per generare i dati dei frame.
  23. Il dati risultanti possono essere inclusi nel programma in Assembly.
  24.  
  25. """
  26. import math
  27.  
  28. # Centro dello schermo
  29. CENTER_X = 160
  30. CENTER_Y = 100
  31.  
  32. def generate_octahedron_vertices():
  33.     coords = [
  34.         [ 1,  0,  0],  # 0
  35.         [-1,  0,  0],  # 1
  36.         [ 0,  1,  0],  # 2
  37.         [ 0, -1,  0],  # 3
  38.         [ 0,  0,  1],  # 4
  39.         [ 0,  0, -1]   # 5
  40.     ]
  41.    
  42.     # Scala per la visualizzazione
  43.     scale = 50
  44.     return [[x * scale, y * scale, z * scale] for x, y, z in coords]
  45.  
  46. def generate_octahedron_lines():
  47.     return [
  48.         [0, 2], [0, 3], [0, 4], [0, 5],
  49.         [1, 2], [1, 3], [1, 4], [1, 5],
  50.         [2, 4], [2, 5], [3, 4], [3, 5]
  51.     ]
  52.  
  53. def rotate_x(point, angle):
  54.     """ Ruota un punto attorno all'asse X """
  55.     y = point[1] * math.cos(angle) - point[2] * math.sin(angle)
  56.     z = point[1] * math.sin(angle) + point[2] * math.cos(angle)
  57.     return [point[0], y, z]
  58.  
  59. def rotate_y(point, angle):
  60.     """ Ruota un punto attorno all'asse Y """
  61.     x = point[0] * math.cos(angle) + point[2] * math.sin(angle)
  62.     z = -point[0] * math.sin(angle) + point[2] * math.cos(angle)
  63.     return [x, point[1], z]
  64.  
  65. def project_point(point):
  66.     """ Semplice proiezione prospettica """
  67.     scale = 200 / (200 + point[2])
  68.     x = point[0] * scale + CENTER_X
  69.     y = point[1] * scale + CENTER_Y
  70.     return [int(x), int(y)]
  71.  
  72. def generate_frames(num_frames=15):
  73.     frames = []
  74.     vertices = generate_octahedron_vertices()
  75.     lines = generate_octahedron_lines()
  76.    
  77.     for frame in range(num_frames):
  78.         # Calcola due angoli di rotazione diversi
  79.         angle_x = (frame * 2 * math.pi) / num_frames
  80.         angle_y = (frame * 2 * math.pi) / (num_frames * 2)  # Ruota più lentamente su Y
  81.        
  82.         # Ruota prima su X e poi su Y
  83.         rotated_vertices = [rotate_x(v, angle_x) for v in vertices]
  84.         rotated_vertices = [rotate_y(v, angle_y) for v in rotated_vertices]
  85.        
  86.         # Proietta i vertici ruotati
  87.         projected_vertices = [project_point(v) for v in rotated_vertices]
  88.        
  89.         # Genera le linee per questo frame
  90.         frame_lines = []
  91.         for line in lines:
  92.             start = projected_vertices[line[0]]
  93.             end = projected_vertices[line[1]]
  94.             frame_lines.append([start[0], start[1], end[0], end[1]])
  95.            
  96.         frames.append(frame_lines)
  97.    
  98.     return frames
  99.  
  100. # Genera i dati in formato C64
  101. frames = generate_frames()
  102.  
  103. # Stampa i dati in formato assembly
  104. print("; Coordinate precalcolate per i frame dell'ottaedro")
  105. print("\nFRAMES")
  106.  
  107. for frame_num, frame in enumerate(frames):
  108.     print(f"\n; Frame {frame_num}")
  109.     for line in frame:
  110.         print(f"    .byte {line[0]}, {line[1]}, {line[2]}, {line[3]}")
  111.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement