File size: 1,541 Bytes
d8e137c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import streamlit as st
import json
import os

# --- Paths ---
COMMENTS_FILE = "data/comments.json"
os.makedirs("data", exist_ok=True)

# --- Load existing comments ---
if os.path.exists(COMMENTS_FILE):
    with open(COMMENTS_FILE, "r") as f:
        comments = json.load(f)
else:
    comments = []

# --- Shader Editor ---
st.subheader("Shader Editor")
default_shader = """// Fresh GLSL shader example
#ifdef GL_ES
precision mediump float;
#endif

uniform float iTime;      
uniform vec2 iResolution; 

void main() {
    vec2 uv = gl_FragCoord.xy / iResolution.xy;
    vec3 color = 0.5 + 0.5 * cos(iTime + uv.xyx * 3.0);
    gl_FragColor = vec4(color, 1.0);
}
"""
shader_code = st.text_area("Edit shader code", default_shader, height=300)

# --- Comments Section ---
st.subheader("Comments")
if comments:
    for c in comments:
        st.write(f"**{c['name']}**: {c['content']}")
else:
    st.write("_No comments yet_")

# --- Add a new comment ---
with st.form("comment_form", clear_on_submit=True):
    user_name = st.text_input("Your name", "")
    user_content = st.text_area("Content", height=80)
    submitted = st.form_submit_button("Submit")

    if submitted and user_content.strip():
        new_comment = {
            "name": user_name or "Anonymous",
            "content": user_content
        }
        comments.append(new_comment)
        with open(COMMENTS_FILE, "w") as f:
            json.dump(comments, f, indent=2)
        st.success("Saved!")
        st.experimental_rerun()  # refresh to show new comment immediately