Update app.py
Browse files
app.py
CHANGED
|
@@ -26,11 +26,11 @@ def bubble_sort(arr, animate=False):
|
|
| 26 |
return arr, steps
|
| 27 |
|
| 28 |
# Function to animate the sorting process
|
| 29 |
-
def animate_sorting(
|
| 30 |
fig, ax = plt.subplots()
|
| 31 |
ax.set_title("Bubble Sort Animation")
|
| 32 |
bar_width = 0.5
|
| 33 |
-
rects = ax.bar(range(len(
|
| 34 |
|
| 35 |
def update(step):
|
| 36 |
for rect, height in zip(rects, steps[step]):
|
|
@@ -63,7 +63,6 @@ if sidebar_option == "Introductory Tutorial":
|
|
| 63 |
image = Image.open("1.png") # Path to your image file
|
| 64 |
st.image(image, width=200) # You can adjust the width as needed
|
| 65 |
|
| 66 |
-
# Add the Bubble Sort Simulator button
|
| 67 |
# Add the Bubble Sort Simulator button
|
| 68 |
if st.button("Bubble Sort Simulator"):
|
| 69 |
st.title("Bubble Sort with Animation")
|
|
@@ -77,7 +76,7 @@ if sidebar_option == "Introductory Tutorial":
|
|
| 77 |
|
| 78 |
# Ask the user if they want an animation
|
| 79 |
animate_option = st.radio("Do you want to see the animation?", options=["Yes", "No"], key="animate_radio")
|
| 80 |
-
|
| 81 |
# Perform bubble sort and get the steps for animation
|
| 82 |
animate = animate_option == "Yes"
|
| 83 |
sorted_array, steps = bubble_sort(arr, animate)
|
|
@@ -87,7 +86,7 @@ if sidebar_option == "Introductory Tutorial":
|
|
| 87 |
|
| 88 |
# Show animation if required
|
| 89 |
if animate:
|
| 90 |
-
animate_sorting(
|
| 91 |
|
| 92 |
# Add content descriptions
|
| 93 |
descriptions = [
|
|
|
|
| 26 |
return arr, steps
|
| 27 |
|
| 28 |
# Function to animate the sorting process
|
| 29 |
+
def animate_sorting(steps):
|
| 30 |
fig, ax = plt.subplots()
|
| 31 |
ax.set_title("Bubble Sort Animation")
|
| 32 |
bar_width = 0.5
|
| 33 |
+
rects = ax.bar(range(len(steps[0])), steps[0], width=bar_width)
|
| 34 |
|
| 35 |
def update(step):
|
| 36 |
for rect, height in zip(rects, steps[step]):
|
|
|
|
| 63 |
image = Image.open("1.png") # Path to your image file
|
| 64 |
st.image(image, width=200) # You can adjust the width as needed
|
| 65 |
|
|
|
|
| 66 |
# Add the Bubble Sort Simulator button
|
| 67 |
if st.button("Bubble Sort Simulator"):
|
| 68 |
st.title("Bubble Sort with Animation")
|
|
|
|
| 76 |
|
| 77 |
# Ask the user if they want an animation
|
| 78 |
animate_option = st.radio("Do you want to see the animation?", options=["Yes", "No"], key="animate_radio")
|
| 79 |
+
|
| 80 |
# Perform bubble sort and get the steps for animation
|
| 81 |
animate = animate_option == "Yes"
|
| 82 |
sorted_array, steps = bubble_sort(arr, animate)
|
|
|
|
| 86 |
|
| 87 |
# Show animation if required
|
| 88 |
if animate:
|
| 89 |
+
animate_sorting(steps)
|
| 90 |
|
| 91 |
# Add content descriptions
|
| 92 |
descriptions = [
|