0% found this document useful (0 votes)
5 views2 pages

New

The document contains a Python script that utilizes libraries like Matplotlib and Pygame to create a 3D visualization of cubes based on data loaded from an Excel file. It includes functions for initializing music, creating a graphical user interface, and handling user interactions. The script sets up a 3D plot, displays information about selected cubes, and manages window events for closing the application.

Uploaded by

hinoxgame
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

New

The document contains a Python script that utilizes libraries like Matplotlib and Pygame to create a 3D visualization of cubes based on data loaded from an Excel file. It includes functions for initializing music, creating a graphical user interface, and handling user interactions. The script sets up a 3D plot, displays information about selected cubes, and manages window events for closing the application.

Uploaded by

hinoxgame
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import matplotlib.

pyplot as plt
import pygame
import math

from load_data import load_data


from create_cubes import create_cubes
from create_gui import create_gui
from update_info_table import update_info_table
from draw_stage import draw_stage
from on_key import on_key

def start_music(file_path):
"""Play background music."""
try:
pygame.mixer.init()
pygame.mixer.music.load(file_path)
pygame.mixer.music.play(-1)
except Exception as e:
print(f"Error playing music: {e}")

def main():
file_path = "cube.xlsx"
data = load_data(file_path)
x_dim, y_dim = 12, 13
spacing = 0.2
type_monolith = "II"
total_cubes = len(data)
z_dim = math.ceil(total_cubes / (x_dim * y_dim))
cubes_dict = create_cubes(x_dim, y_dim, z_dim, total_cubes, spacing,
type_monolith)

fig = plt.figure(figsize=(6, 6))


ax1 = fig.add_subplot(121, projection='3d')
ax2 = fig.add_subplot(122)
ax1.set_facecolor('darkgray') # Industrial look
ax2.set_facecolor('#333') # Dark background for information display
ax1.set_position([0.0, 0.0, 1, 1])
ax1.view_init(elev=37, azim=37)

window, tree = create_gui(fig, type_monolith)

selected_cube = [0, 0, 0]

fig.canvas.mpl_connect(
'key_press_event',
lambda event: on_key(
event, selected_cube, x_dim, y_dim, z_dim, cubes_dict, ax1, ax2, data,
tree
)
)
draw_stage(ax1, 'cyan', selected_cube, spacing, x_dim, y_dim, z_dim,
cubes_dict)
update_info_table(selected_cube, ax2, x_dim, y_dim, data, tree)

start_music("brasil.mp3")
# Define what happens when the window is closed
def on_close():
pygame.mixer.music.stop() # Stop the music
window.destroy() # Destroy the Tkinter window

# Bind the close event to the on_close function


window.protocol("WM_DELETE_WINDOW", on_close)
window.bind("<Escape>", lambda event: on_close())

window.mainloop()

if __name__ == "__main__":
main()

You might also like