Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
freem
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Openai/68f40a7c-717c-8000-8af6-a222789ef1d8
(section)
Add languages
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Assistant: Got it ๐ โ hereโs your fully updated ASCII-safe program with a working live XYZ display. === Got it ๐ โ hereโs your fully updated ASCII-safe program with a working live XYZ display. This version runs on Windows without any UTF-8 issues and shows live XYZ coordinates that update as you move the mouse inside the cube. ===== <syntaxhighlight lang="python"># -''- coding: utf-8 -''- ===== import numpy as np import matplotlib.pyplot as plt from matplotlib.widgets import Button from mpl_toolkits.mplot3d.art3d import Poly3DCollection class GoldenEllipseSpiralCube: def __init__(self): self.fig = plt.figure(figsize=(16, 10)) # 3D view (left) self.ax = self.fig.add_subplot(121, projection='3d') # Info panel (right) self.ax_info = self.fig.add_subplot(122) self.ax_info.axis('off') # Constants self.phi = (1 + np.sqrt(5)) / 2 self.pyramid_angle = 51.84 # Great Pyramid angle in degrees # Cube geometry self.vertices = np.array([ [-1, -1, -1], [1, -1, -1], [1, 1, -1], [-1, 1, -1], [-1, -1, 1], [1, -1, 1], [1, 1, 1], [-1, 1, 1] ]) self.faces = [ [0, 1, 2, 3], [4, 5, 6, 7], [0, 1, 5, 4], [2, 3, 7, 6], [0, 3, 7, 4], [1, 2, 6, 5] ] self.face_colors = [ [1, 0, 0, 0.05], [0, 1, 0, 0.05], [0, 0, 1, 0.05], [1, 1, 0, 0.05], [1, 0, 1, 0.05], [0, 1, 1, 0.05] ] # Geometry setup self.spiral_points = self.create_spiral() self.sine_points = self.create_sine_wave() self.morph_t = 0.0 # Camera and state self.elev = 30 self.azim = 45 self.special_view = False # Live XYZ display box self.text_box = self.fig.text( 0.83, 0.03, "", fontsize=10, color="white", bbox=dict(facecolor="black", alpha=0.6, boxstyle="round,pad=0.3") ) self.create_buttons() self.setup_plot() self.setup_info_panel() self.connect_events() # ---------- Geometry ---------- def create_spiral(self): t = np.linspace(0, 2 * np.pi, 300) x = np.cos(t) y = np.sin(t) z = -1 + 2 '' (t / (2 '' np.pi)) return np.column_stack((x, y, z)) def create_sine_wave(self): t = np.linspace(0, 2 * np.pi, 300) x = np.cos(t) y = np.sin(t) * 0.5 z = -1 + 2 '' (t / (2 '' np.pi)) return np.column_stack((x, y, z)) def morph_points(self, t): t_smooth = 3 * t**2 - 2 * t**3 return (1 - t_smooth) '' self.spiral_points + t_smooth '' self.sine_points # ---------- UI ---------- def create_buttons(self): self.ax_reset = plt.axes([0.3, 0.02, 0.12, 0.04]) self.ax_golden = plt.axes([0.43, 0.02, 0.15, 0.04]) self.ax_pyramid = plt.axes([0.59, 0.02, 0.15, 0.04]) self.ax_morph = plt.axes([0.75, 0.02, 0.15, 0.04]) self.ax_special = plt.axes([0.1, 0.02, 0.15, 0.04]) self.button_reset = Button(self.ax_reset, 'Default View') self.button_golden = Button(self.ax_golden, 'Golden View') self.button_pyramid = Button(self.ax_pyramid, 'Pyramid View') self.button_morph = Button(self.ax_morph, 'Toggle Morph') self.button_special = Button(self.ax_special, 'Special View') self.button_reset.on_clicked(self.reset_view) self.button_golden.on_clicked(self.reset_to_golden_view) self.button_pyramid.on_clicked(self.reset_to_pyramid_view) self.button_morph.on_clicked(self.toggle_morph) self.button_special.on_clicked(self.toggle_special_view) # ---------- Plot ---------- def setup_plot(self): self.ax.clear() # Draw cube for i, face in enumerate(self.faces): vertices = self.vertices[face] poly = Poly3DCollection([vertices], alpha=0.03) poly.set_facecolor(self.face_colors[i]) poly.set_edgecolor('gray') self.ax.add_collection3d(poly) # Morph line points = self.morph_points(self.morph_t) self.ax.plot3D(points[:, 0], points[:, 1], points[:, 2], color='black', linewidth=3, alpha=0.9) # Update XYZ for last point self.update_xyz_display(points[-1]) # Axes self.ax.set_xlim([-1.5, 1.5]) self.ax.set_ylim([-1.5, 1.5]) self.ax.set_zlim([-1.5, 1.5]) self.ax.set_xlabel('X Axis', fontweight='bold') self.ax.set_ylabel('Y Axis', fontweight='bold') self.ax.set_zlabel('Z Axis', fontweight='bold') self.ax.set_title('Golden Ellipse Spiral Cube', fontsize=14, fontweight='bold') self.ax.view_init(elev=self.elev, azim=self.azim) self.fig.canvas.draw_idle() def setup_info_panel(self): self.ax_info.clear() self.ax_info.axis('off') text = ( "CONTROLS:\n\n" "Black line: Spiral/Sine morph\n" "Cube: Spatial reference\n\n" "Buttons:\n" " - Default / Golden / Pyramid views\n" " - Toggle Morph: Spiral <-> Sine\n" " - Special View: Cinematic camera\n\n" "Use mouse drag to rotate, wheel to zoom.\n" "XYZ coordinates update live under the cursor." ) self.ax_info.text(0.05, 0.95, text, transform=self.ax_info.transAxes, fontsize=9, verticalalignment='top', fontfamily='monospace', bbox=dict(boxstyle="round,pad=1", facecolor='lightblue', alpha=0.8, edgecolor='darkblue')) self.fig.canvas.draw_idle() # ---------- Display ---------- def update_xyz_display(self, point): x, y, z = point self.text_box.set_text(f"X: {x:+.2f}\nY: {y:+.2f}\nZ: {z:+.2f}") self.fig.canvas.draw_idle() # ---------- Events ---------- def connect_events(self): self.fig.canvas.mpl_connect('scroll_event', self.on_scroll) self.fig.canvas.mpl_connect('motion_notify_event', self.on_motion) def on_scroll(self, event): if event.inaxes == self.ax: xlim = self.ax.get_xlim() ylim = self.ax.get_ylim() zlim = self.ax.get_zlim() zoom_factor = 1.1 if event.step > 0 else 0.9 self.ax.set_xlim([v * zoom_factor for v in xlim]) self.ax.set_ylim([v * zoom_factor for v in ylim]) self.ax.set_zlim([v * zoom_factor for v in zlim]) self.fig.canvas.draw_idle() def on_motion(self, event): """Update XYZ display live as mouse moves inside the 3D axes.""" if event.inaxes != self.ax or event.xdata is None or event.ydata is None: return x, y = event.xdata, event.ydata z = 0.0 # Approximation plane self.update_xyz_display((x, y, z)) # ---------- Buttons ---------- def reset_view(self, event=None): self.elev = 30 self.azim = 45 self.setup_plot() def reset_to_golden_view(self, event=None): self.elev = 52 self.azim = 45 self.setup_plot() def reset_to_pyramid_view(self, event=None): self.elev = self.pyramid_angle self.azim = 45 self.setup_plot() def toggle_morph(self, event=None): target = 1.0 if self.morph_t < 0.5 else 0.0 steps = 50 for i in range(steps + 1): t = i / steps self.morph_t = (1 - t) '' self.morph_t + t '' target self.setup_plot() plt.pause(0.01) def toggle_special_view(self, event=None): target_elev = 75 if not self.special_view else 30 target_azim = 120 if not self.special_view else 45 steps = 40 for i in range(steps + 1): t = 3 * (i / steps) ** 2 - 2 * (i / steps) ** 3 self.elev = (1 - t) '' self.elev + t '' target_elev self.azim = (1 - t) '' self.azim + t '' target_azim self.ax.view_init(elev=self.elev, azim=self.azim) self.fig.canvas.draw_idle() plt.pause(0.01) self.special_view = not self.special_view # ---------- Run ---------- def show(self): print("Golden Ellipse Spiral Cube running...") plt.show() if __name__ == "__main__": cube = GoldenEllipseSpiralCube() cube.show() </syntaxhighlight> โ Features * No UTF-8 issues (all ASCII). * Cube + spiral โ sine morph with easing. * Cinematic โspecialโ camera toggle. * Info panel on right. * Live XYZ coordinate readout under your mouse. Run it with: <syntaxhighlight lang="bash">py GoldenEllipseSpiralCubeSLIDER_SINE_MORPH_SAFE_XYZ_LIVE_ASCII.py </syntaxhighlight> Would you like the XYZ display to follow the actual 3D intersection with the cube walls (so it shows true coordinates in space, not just approximate xโy plane)?
Summary:
Please note that all contributions to freem are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 (see
Freem:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)