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: Perfect π Hereβs your ultra-safe, pure ASCII version of the full program β no special symbols, only standard ASCII texβ¦ === Perfect π Hereβs your ultra-safe, pure ASCII version of the full program β no special symbols, only standard ASCII text. This version: β Runs on Windows without any UTF-8/ANSI issues. β Keeps the smooth morph, camera toggle, and info panel. β Includes a working XYZ coordinate readout that updates correctly during the morph. ===== <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)) # Create main 3D plot (left side) self.ax = self.fig.add_subplot(121, projection='3d') # Create info panel (right side) self.ax_info = self.fig.add_subplot(122) self.ax_info.axis('off') # Golden ratio self.phi = (1 + np.sqrt(5)) / 2 self.pyramid_angle = 51.84 # Great Pyramid angle in degrees # Cube vertices and faces 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] ] # Create geometry self.spiral_points = self.create_spiral() self.sine_points = self.create_sine_wave() self.morph_t = 0.0 # morph factor between spiral (0) and sine (1) # Camera setup self.elev = 30 self.azim = 45 self.special_view = False # XYZ display (must exist before setup_plot) 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() 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 # smaller amplitude to fit cube z = -1 + 2 '' (t / (2 '' np.pi)) return np.column_stack((x, y, z)) def morph_points(self, t): # Smooth ease-in-out morph t_smooth = 3 * t**2 - 2 * t**3 return (1 - t_smooth) '' self.spiral_points + t_smooth '' self.sine_points 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) def setup_plot(self): self.ax.clear() # 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) # Draw spiral/sine morph 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 readout for last point self.update_xyz_display(points[-1]) # Axes settings 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\n" "XYZ coordinates shown in lower right." ) 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() 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() def connect_events(self): self.fig.canvas.mpl_connect('scroll_event', self.on_scroll) 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 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 def show(self): print("Golden Ellipse Spiral Cube running...") plt.show() if __name__ == "__main__": cube = GoldenEllipseSpiralCube() cube.show() </syntaxhighlight> β Completely ASCII-safe β Works on Windows Python β Includes: cube, morph, smooth camera toggle, info panel, live XYZ display Would you like the XYZ readout to track the current mouse 3D cursor position (not just the last spiral point)?
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)