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 a fully cleaned, ASCII-only version of your script. === Perfect π β hereβs a fully cleaned, ASCII-only version of your script. No special characters, no long dashes, and no Unicode issues β 100% safe to save and run in any Windows editor. Copy-paste everything below into a new file named: π GoldenEllipseSpiralCubeSLIDER.py <syntaxhighlight lang="python"># -''- coding: utf-8 -''- """ Golden Ellipse Spiral Cube Visualization Clean ASCII-safe version (no special symbols) """ import numpy as np import matplotlib.pyplot as plt from matplotlib.widgets import Button, Slider from mpl_toolkits.mplot3d import Axes3D 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 # 1.618... # Great Pyramid angle (51.84 degrees) self.pyramid_angle = 51.84 # Cube vertices 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] ]) # Define cube faces 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] ] # Colors (RGBA) 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] ] # Geometric features self.spiral_points = self.create_circle_projection_spiral() self.circle_projection = self.create_circle_projection() self.golden_ellipse_points = self.create_golden_ellipse_projection() # View settings self.elev = 30 self.azim = 45 self.dragging = False self.prev_mouse = None # UI elements self.create_buttons() self.create_slider() self.setup_plot() self.setup_info_panel() self.connect_events() # ------------------------------------------------------- # Geometry creation # ------------------------------------------------------- def create_circle_projection_spiral(self): t = np.linspace(0, 2 * np.pi, 200) points = [] for angle in t: x = np.cos(angle) y = np.sin(angle) z = -1.0 + (angle / (2 '' np.pi)) '' 2.0 points.append([x, y, z]) return np.array(points) def create_circle_projection(self): return np.array([[x, y, 1.0] for x, y, _ in self.spiral_points]) def create_golden_ellipse_projection(self): t = np.linspace(0, 2 * np.pi, 100) major_axis = 1.0 minor_axis = major_axis / self.phi return np.array([ [major_axis '' np.cos(a), minor_axis '' np.sin(a), 1.0] for a in t ]) def calculate_perspective_ellipse(self, view_angle): t = np.linspace(0, 2 * np.pi, 100) theta = np.radians(view_angle) minor = np.cos(theta) return np.array([ [np.cos(a), minor * np.sin(a), 1.0] for a in t ]) # ------------------------------------------------------- # UI setup # ------------------------------------------------------- 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.button_reset = Button(self.ax_reset, "Default View") self.button_golden = Button(self.ax_golden, "Golden Ratio View") self.button_pyramid = Button(self.ax_pyramid, "Pyramid Angle 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) def create_slider(self): """Add slider to control elevation angle interactively.""" slider_ax = plt.axes([0.3, 0.08, 0.45, 0.03]) self.slider_elev = Slider( slider_ax, "Elevation (deg)", 0, 90, valinit=self.elev, valstep=0.5 ) self.slider_elev.on_changed(self.update_elevation) def update_elevation(self, val): """Called when slider value changes.""" self.elev = self.slider_elev.val self.ax.view_init(elev=self.elev, azim=self.azim) # Remove old red dashed ellipse for line in self.ax.lines[:]: if line.get_linestyle() == "--": line.remove() perspective_ellipse = self.calculate_perspective_ellipse(self.elev) self.ax.plot3D( perspective_ellipse[:, 0], perspective_ellipse[:, 1], perspective_ellipse[:, 2], color="red", linewidth=2, linestyle="--", alpha=0.8 ) self.fig.canvas.draw_idle() # ------------------------------------------------------- # Plot setup # ------------------------------------------------------- def setup_plot(self): self.ax.clear() # Cube faces 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") poly.set_linewidth = 0.5 self.ax.add_collection3d(poly) # Spiral s = self.spiral_points self.ax.plot3D(s[:, 0], s[:, 1], s[:, 2], color="black", lw=3, alpha=0.8) # Circle projection c = self.circle_projection self.ax.plot3D(c[:, 0], c[:, 1], c[:, 2], color="blue", lw=3, alpha=0.8) # Golden ellipse g = self.golden_ellipse_points self.ax.plot3D(g[:, 0], g[:, 1], g[:, 2], color="gold", lw=4, alpha=0.9) # Perspective ellipse p = self.calculate_perspective_ellipse(self.elev) self.ax.plot3D(p[:, 0], p[:, 1], p[:, 2], color="red", lw=2, ls="--", alpha=0.7) # 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 Phenomenon", fontsize=14, fontweight="bold") self.ax.view_init(elev=self.elev, azim=self.azim) self.ax.grid(True, alpha=0.2) self.fig.canvas.draw_idle() def setup_info_panel(self): self.ax_info.clear() self.ax_info.axis("off") minor_axis_length = 1 / self.phi pyramid_minor_axis = np.cos(np.radians(self.pyramid_angle)) pyramid_ratio = 1.0 / pyramid_minor_axis legend_text = ( "VISUAL ELEMENTS:\n\n" "Black: Spiral inside cube\n" "Blue: Perfect Circle (front)\n" "Gold: Golden Ellipse (phi=1.618)\n" "Red dashed: Perspective ellipse\n\n" "GOLDEN RATIO AND PYRAMID LINK:\n" f"Golden Ratio (phi) = {self.phi:.6f}\n" f"Pyramid Angle = {self.pyramid_angle} deg\n" f"Pyramid ratio = {pyramid_ratio:.6f}\n\n" "ELLIPSE PROPERTIES:\n" f"Major Axis = 1.000\n" f"Minor Axis = {minor_axis_length:.6f}\n" f"Ratio = 1.000 / {minor_axis_length:.3f} = {self.phi:.6f}\n\n" "CONTROLS:\n" "Left: Rotate\n" "Mouse wheel: Zoom\n" "Buttons: Preset views\n" "Slider: Change elevation angle" ) self.ax_info.text(0.05, 0.95, legend_text, transform=self.ax_info.transAxes, fontsize=9, va="top", fontfamily="monospace", bbox=dict(boxstyle="round,pad=1", facecolor="lightblue", alpha=0.8, edgecolor="darkblue")) self.fig.canvas.draw_idle() # ------------------------------------------------------- # Interaction # ------------------------------------------------------- def connect_events(self): self.fig.canvas.mpl_connect("button_press_event", self.on_press) self.fig.canvas.mpl_connect("button_release_event", self.on_release) self.fig.canvas.mpl_connect("motion_notify_event", self.on_motion) self.fig.canvas.mpl_connect("scroll_event", self.on_scroll) def on_press(self, event): if event.inaxes == self.ax: self.dragging = True self.prev_mouse = (event.x, event.y) def on_release(self, event): self.dragging = False self.prev_mouse = None def on_motion(self, event): if not self.dragging or event.inaxes != self.ax or self.prev_mouse is None: return dx = event.x - self.prev_mouse[0] dy = event.y - self.prev_mouse[1] self.azim += dx * 0.5 self.elev -= dy * 0.5 self.elev = np.clip(self.elev, -90, 90) self.ax.view_init(elev=self.elev, azim=self.azim) self.fig.canvas.draw_idle() self.prev_mouse = (event.x, event.y) def on_scroll(self, event): if event.inaxes != self.ax: return xlim = self.ax.get_xlim() ylim = self.ax.get_ylim() zlim = self.ax.get_zlim() xc, yc, zc = np.mean(xlim), np.mean(ylim), np.mean(zlim) zoom = 1.1 if event.step > 0 else 0.9 xr = (xlim[1] - xlim[0]) * zoom yr = (ylim[1] - ylim[0]) * zoom zr = (zlim[1] - zlim[0]) * zoom self.ax.set_xlim([xc - xr / 2, xc + xr / 2]) self.ax.set_ylim([yc - yr / 2, yc + yr / 2]) self.ax.set_zlim([zc - zr / 2, zc + zr / 2]) self.fig.canvas.draw_idle() # ------------------------------------------------------- # View presets # ------------------------------------------------------- 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 show(self): print("Golden Ellipse & Pyramid Connection") print("=" * 50) print("Angle 51.84 deg (Great Pyramid)") print("Golden ratio encoded in ancient architecture!") print("Controls: drag to rotate, wheel to zoom, slider to change angle") plt.show() if __name__ == "__main__": cube = GoldenEllipseSpiralCube() cube.show() </syntaxhighlight> β Now just save and run: <syntaxhighlight lang="bash">py GoldenEllipseSpiralCubeSLIDER.py </syntaxhighlight> Youβll get your full interactive visualization: * Left panel: 3D cube and geometry * Right panel: explanation text * Slider: adjusts elevation angle in real time * Buttons: preset views for Default, Golden, and Pyramid Would you like me to also make the info panel text update dynamically as you move the slider (so it displays the current angle and ellipse ratio live)?
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)