import streamlit as st
import plotly.graph_objs as go
import numpy as np
# Function to generate circle coordinates
def generate_circle(radius, z, num_points=100):
theta = np.linspace(0, 2 * np.pi, num_points)
x = radius * np.cos(theta)
y = radius * np.sin(theta)
z = np.full_like(theta, z)
return x, y, z
# Function to generate lettuce coordinates (irregular shape)
def generate_lettuce(radius, z, num_points=100):
theta = np.linspace(0, 2 * np.pi, num_points)
r = radius + 0.2 * np.sin(6 * theta) # Adding some wave-like irregularities
x = r * np.cos(theta)
y = r * np.sin(theta)
z = np.full_like(theta, z)
return x, y, z
# Function to generate data for a realistic 3D hamburger with multiple layers
def generate_hamburger(num_patties):
layers = []
# Bottom bun
x, y, z = generate_circle(5, 0)
layers.append((x, y, z, 'goldenrod', 'Bottom Bun'))
current_height = 0.3
for _ in range(num_patties):
# Patty
x, y, z = generate_circle(5, current_height)
layers.append((x, y, z, 'saddlebrown', 'Patty'))
current_height += 0.2
# Lettuce
x, y, z = generate_lettuce(5, current_height)
layers.append((x, y, z, 'green', 'Lettuce'))
current_height += 0.1
# Tomato
x, y, z = generate_circle(5, current_height)
layers.append((x, y, z, 'tomato', 'Tomato'))
current_height += 0.1
# Top bun
x, y, z = generate_circle(5, current_height)
layers.append((x, y, z, 'goldenrod', 'Top Bun'))
return layers
# Generate the plotly figure
def create_figure(num_patties):
fig = go.Figure()
layers = generate_hamburger(num_patties)
for x, y, z, color, name in layers:
fig.add_trace(go.Scatter3d(x=x, y=y, z=z, mode='lines', line=dict(color=color, width=10), name=name))
fig.update_layout(
title='Realistic 3D Hamburger',
scene=dict(
xaxis=dict(title='X-axis'),
yaxis=dict(title='Y-axis'),
zaxis=dict(title='Z-axis')
),
scene_aspectmode='data'
)
return fig
# Streamlit app layout
st.title("3D Hamburger Builder")
num_patties = st.slider("Select number of patties:", min_value=1, max_value=5, value=2)
st.plotly_chart(create_figure(num_patties))