Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Programma: ottaedro_rotazione.py
- Descrizione:
- Questo script Python calcola e genera le coordinate dei vertici di un ottaedro regolare,
- applicando una rotazione nello spazio (3D) attorno agli assi X, Y.
- Per ogni passo della rotazione, vengono proiettate le coordinate 3D su un piano 2D
- e convertite in coordinate schermo compatibili con la modalità bitmap del Commodore 64.
- Il risultato finale è un insieme di frame precalcolati contenenti le coordinate
- dei vertici, pronte per essere utilizzate direttamente nel programma Assembly
- sul C64.
- Requisiti:
- - Python 3.x
- - Nessuna libreria esterna (usa solo moduli standard)
- Autore: Kimono (Felice Nardella)
- Data: marzo 2025
- Utilizzo:
- Eseguire questo script per generare i dati dei frame.
- Il dati risultanti possono essere inclusi nel programma in Assembly.
- """
- import math
- # Centro dello schermo
- CENTER_X = 160
- CENTER_Y = 100
- def generate_octahedron_vertices():
- coords = [
- [ 1, 0, 0], # 0
- [-1, 0, 0], # 1
- [ 0, 1, 0], # 2
- [ 0, -1, 0], # 3
- [ 0, 0, 1], # 4
- [ 0, 0, -1] # 5
- ]
- # Scala per la visualizzazione
- scale = 50
- return [[x * scale, y * scale, z * scale] for x, y, z in coords]
- def generate_octahedron_lines():
- return [
- [0, 2], [0, 3], [0, 4], [0, 5],
- [1, 2], [1, 3], [1, 4], [1, 5],
- [2, 4], [2, 5], [3, 4], [3, 5]
- ]
- def rotate_x(point, angle):
- """ Ruota un punto attorno all'asse X """
- y = point[1] * math.cos(angle) - point[2] * math.sin(angle)
- z = point[1] * math.sin(angle) + point[2] * math.cos(angle)
- return [point[0], y, z]
- def rotate_y(point, angle):
- """ Ruota un punto attorno all'asse Y """
- x = point[0] * math.cos(angle) + point[2] * math.sin(angle)
- z = -point[0] * math.sin(angle) + point[2] * math.cos(angle)
- return [x, point[1], z]
- def project_point(point):
- """ Semplice proiezione prospettica """
- scale = 200 / (200 + point[2])
- x = point[0] * scale + CENTER_X
- y = point[1] * scale + CENTER_Y
- return [int(x), int(y)]
- def generate_frames(num_frames=15):
- frames = []
- vertices = generate_octahedron_vertices()
- lines = generate_octahedron_lines()
- for frame in range(num_frames):
- # Calcola due angoli di rotazione diversi
- angle_x = (frame * 2 * math.pi) / num_frames
- angle_y = (frame * 2 * math.pi) / (num_frames * 2) # Ruota più lentamente su Y
- # Ruota prima su X e poi su Y
- rotated_vertices = [rotate_x(v, angle_x) for v in vertices]
- rotated_vertices = [rotate_y(v, angle_y) for v in rotated_vertices]
- # Proietta i vertici ruotati
- projected_vertices = [project_point(v) for v in rotated_vertices]
- # Genera le linee per questo frame
- frame_lines = []
- for line in lines:
- start = projected_vertices[line[0]]
- end = projected_vertices[line[1]]
- frame_lines.append([start[0], start[1], end[0], end[1]])
- frames.append(frame_lines)
- return frames
- # Genera i dati in formato C64
- frames = generate_frames()
- # Stampa i dati in formato assembly
- print("; Coordinate precalcolate per i frame dell'ottaedro")
- print("\nFRAMES")
- for frame_num, frame in enumerate(frames):
- print(f"\n; Frame {frame_num}")
- for line in frame:
- print(f" .byte {line[0]}, {line[1]}, {line[2]}, {line[3]}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement