Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +111 -20
src/streamlit_app.py
CHANGED
|
@@ -2,39 +2,130 @@ import altair as alt
|
|
| 2 |
import numpy as np
|
| 3 |
import pandas as pd
|
| 4 |
import streamlit as st
|
|
|
|
| 5 |
|
| 6 |
-
"""
|
| 7 |
-
# Welcome to Streamlit!
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
indices = np.linspace(0, 1, num_points)
|
| 20 |
-
theta = 2 * np.pi * num_turns * indices
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
x = radius * np.cos(theta)
|
| 24 |
y = radius * np.sin(theta)
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
df = pd.DataFrame({
|
| 27 |
"x": x,
|
| 28 |
"y": y,
|
|
|
|
|
|
|
| 29 |
"idx": indices,
|
| 30 |
-
"rand": np.random.
|
| 31 |
})
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
import pandas as pd
|
| 4 |
import streamlit as st
|
| 5 |
+
import random
|
| 6 |
|
| 7 |
+
st.set_page_config(page_title="β¨ B R A I N M E L T S P I R A L β¨", layout="wide")
|
|
|
|
| 8 |
|
| 9 |
+
st.markdown(
|
| 10 |
+
"""
|
| 11 |
+
# πͺοΈ HYPER-DEGENERATE SPIRAL OF CHAOS v2.0 πͺοΈ
|
| 12 |
+
**Warning:** May cause temporary loss of sanity, eye strain, and existential dread.
|
| 13 |
+
Turn your sound on if you're brave.
|
| 14 |
+
(jk there's no sound⦠yet)
|
| 15 |
+
""",
|
| 16 |
+
unsafe_allow_html=True
|
| 17 |
+
)
|
| 18 |
|
| 19 |
+
# βββ Controls ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 20 |
+
col1, col2, col3, col4 = st.columns(4)
|
| 21 |
|
| 22 |
+
with col1:
|
| 23 |
+
num_points = st.slider("Points (more = epilepsy)", 500, 80000, 15000, step=500)
|
| 24 |
+
with col2:
|
| 25 |
+
num_turns = st.slider("Turns (higher = portal to hell)", 5, 800, 69, step=1)
|
| 26 |
+
with col3:
|
| 27 |
+
chaos_factor = st.slider("Chaos juice", 0.0, 12.0, 3.8, step=0.1)
|
| 28 |
+
with col4:
|
| 29 |
+
color_mode = st.radio("Color insanity level", ["Psychotic rainbow", "Strobo-seizure", "Drunk lava lamp", "Cursed pastel goth"])
|
| 30 |
|
| 31 |
+
speed = st.slider("Animation speed (ms per frame)", 10, 600, 80, step=10)
|
| 32 |
+
trail_length = st.slider("Trail memory (0 = no mercy)", 0.0, 1.0, 0.92, step=0.01)
|
| 33 |
+
shake = st.checkbox("Enable camera epilepsy (shake)", True)
|
| 34 |
+
glitch = st.checkbox("Enable digital glitch corruption", True)
|
| 35 |
+
|
| 36 |
+
# βββ Generate base spiral ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 37 |
indices = np.linspace(0, 1, num_points)
|
| 38 |
+
theta = 2 * np.pi * num_turns * indices * (1 + np.random.uniform(-0.02, 0.02, num_points))
|
| 39 |
+
|
| 40 |
+
# radius goes from 0 β 1 β 0 β 1.5 β chaos
|
| 41 |
+
radius = indices ** 0.6
|
| 42 |
+
radius += chaos_factor * 0.4 * np.sin(indices * 40 + np.random.randn(num_points)*3)
|
| 43 |
+
radius *= 1 + 0.7 * np.sin(indices * 130)
|
| 44 |
|
| 45 |
x = radius * np.cos(theta)
|
| 46 |
y = radius * np.sin(theta)
|
| 47 |
|
| 48 |
+
# extra dimension of suffering
|
| 49 |
+
z_noise = np.random.randn(num_points) * chaos_factor * 2.5
|
| 50 |
+
size_noise = np.abs(np.random.randn(num_points)) ** 0.7 * 120 + 10
|
| 51 |
+
|
| 52 |
df = pd.DataFrame({
|
| 53 |
"x": x,
|
| 54 |
"y": y,
|
| 55 |
+
"z_noise": z_noise,
|
| 56 |
+
"size": size_noise,
|
| 57 |
"idx": indices,
|
| 58 |
+
"rand": np.random.uniform(-1,1,num_points),
|
| 59 |
})
|
| 60 |
|
| 61 |
+
# βββ Color madness βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 62 |
+
if color_mode == "Psychotic rainbow":
|
| 63 |
+
df["color"] = df["idx"] * 360
|
| 64 |
+
color_scale = alt.Scale(domain=[0,360], scheme="rainbow", clamp=True)
|
| 65 |
+
elif color_mode == "Strobo-seizure":
|
| 66 |
+
df["color"] = np.random.randint(0,360,num_points)
|
| 67 |
+
color_scale = alt.Scale(domain=[0,360], scheme="category20", clamp=True)
|
| 68 |
+
elif color_mode == "Drunk lava lamp":
|
| 69 |
+
df["color"] = np.sin(df["idx"]*30 + df["rand"]*10) * 180 + 180
|
| 70 |
+
color_scale = alt.Scale(scheme="turbo")
|
| 71 |
+
else: # cursed pastel goth
|
| 72 |
+
df["color"] = (df["idx"] * 90 + df["rand"]*180) % 360
|
| 73 |
+
color_scale = alt.Scale(scheme="pastel1")
|
| 74 |
+
|
| 75 |
+
# βββ The cursed chart ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 76 |
+
base = alt.Chart(df, height=780, width=780).transform_filter(
|
| 77 |
+
alt.datum.idx <= st.session_state.get("progress", 1.0)
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
points = base.mark_point(filled=True, opacity=0.9).encode(
|
| 81 |
+
x=alt.X("x", axis=None),
|
| 82 |
+
y=alt.Y("y", axis=None),
|
| 83 |
+
color=alt.Color("color", scale=color_scale, legend=None),
|
| 84 |
+
size=alt.Size("size", scale=alt.Scale(range=[0.5, 380]), legend=None),
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
+
if shake:
|
| 88 |
+
# fake camera shake via tiny random translate
|
| 89 |
+
shake_x = np.random.uniform(-1.5, 1.5) * chaos_factor
|
| 90 |
+
shake_y = np.random.uniform(-1.5, 1.5) * chaos_factor
|
| 91 |
+
points = points.transform_calculate(
|
| 92 |
+
x_shake=f"datum.x + {shake_x}",
|
| 93 |
+
y_shake=f"datum.y + {shake_y}"
|
| 94 |
+
).encode(x="x_shake:Q", y="y_shake:Q")
|
| 95 |
+
|
| 96 |
+
# very fake glitch effect
|
| 97 |
+
if glitch and random.random() < 0.18:
|
| 98 |
+
glitch_amount = random.uniform(0.03, 0.25)
|
| 99 |
+
points = points.transform_calculate(
|
| 100 |
+
x_glitch=f"datum.x + (random() < 0.4 ? (random()-0.5)*{glitch_amount*30} : 0)",
|
| 101 |
+
y_glitch=f"datum.y + (random() < 0.6 ? (random()-0.5)*{glitch_amount*40} : 0)"
|
| 102 |
+
).encode(x="x_glitch:Q", y="y_glitch:Q")
|
| 103 |
+
|
| 104 |
+
chart = points.properties(
|
| 105 |
+
title="YOU SHOULD NOT HAVE COME HERE"
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
# βββ Animation logic (fake progressive reveal) βββββββββββββββββββββββββββββββ
|
| 109 |
+
if "progress" not in st.session_state:
|
| 110 |
+
st.session_state.progress = 0.0
|
| 111 |
+
|
| 112 |
+
st.altair_chart(chart, use_container_width=True)
|
| 113 |
+
|
| 114 |
+
# auto-animate
|
| 115 |
+
if st.button("LAUNCH INTO THE VOID", type="primary"):
|
| 116 |
+
st.session_state.progress = 0.0
|
| 117 |
+
|
| 118 |
+
progress = st.session_state.progress
|
| 119 |
+
progress += 0.004 / (speed/100)
|
| 120 |
+
progress = min(1.0, progress)
|
| 121 |
+
st.session_state.progress = progress
|
| 122 |
+
|
| 123 |
+
# trail fade simulation (very fake)
|
| 124 |
+
st.markdown(
|
| 125 |
+
f'<div style="position:absolute; top:0; left:0; right:0; bottom:0; '
|
| 126 |
+
f'background:rgba(0,0,0,{1-trail_length}); pointer-events:none;"></div>',
|
| 127 |
+
unsafe_allow_html=True
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
st.markdown("---")
|
| 131 |
+
st.caption("Made with love, regret, and way too much numpy")
|