awacke1 commited on
Commit
0438bd7
·
verified ·
1 Parent(s): 81ffa58

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +82 -17
app.py CHANGED
@@ -1,16 +1,78 @@
1
  import streamlit as st
2
  import streamlit.components.v1 as components
3
  import random
4
- import string
5
  import time
6
  import os
7
 
8
  # Load the initial HTML5 app
9
- if not os.path.exists("aframe_app.html"):
10
- with open("aframe_app.html", "w") as f:
11
- f.write("<a-scene></a-scene>")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
- with open("aframe_app.html", "r") as f:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  initial_html = f.read()
15
 
16
  # Initialize session state
@@ -31,16 +93,25 @@ def add_player():
31
  while player_name in st.session_state.player_names:
32
  player_name = generate_player_name()
33
  st.session_state.player_names.append(player_name)
34
- player_html = f'<a-entity id="{player_name}" geometry="primitive: box" material="color: {random.choice(["red", "green", "blue", "yellow", "purple"])};"></a-entity>'
35
- st.session_state.html_content = st.session_state.html_content.replace("</a-scene>", player_html + "\n</a-scene>")
 
 
 
 
 
 
 
 
 
36
 
37
  # Streamlit app
38
  def main():
39
- st.set_page_config(page_title="3D House Exploration", layout="wide")
40
- st.title("3D House Exploration")
41
 
42
  # Add a new player button
43
- if st.button("Join Game", key="join_game"):
44
  add_player()
45
 
46
  # Display the HTML5 app
@@ -54,15 +125,9 @@ def main():
54
  if st.button("Save", key="save_button"):
55
  st.session_state.html_content = new_html
56
 
57
- # Refresh timer
58
  if st.button("Refresh", key="refresh_button"):
59
  st.experimental_rerun()
60
- else:
61
- refresh_timer = st.empty()
62
- for i in range(5, 0, -1):
63
- refresh_timer.text(f"Refreshing in {i} seconds...")
64
- time.sleep(1)
65
- st.experimental_rerun()
66
 
67
  if __name__ == "__main__":
68
  main()
 
1
  import streamlit as st
2
  import streamlit.components.v1 as components
3
  import random
 
4
  import time
5
  import os
6
 
7
  # Load the initial HTML5 app
8
+ if not os.path.exists("chofko_ecosystem.html"):
9
+ with open("chofko_ecosystem.html", "w") as f:
10
+ f.write('''
11
+ <!DOCTYPE html>
12
+ <html>
13
+ <head>
14
+ <meta charset="utf-8">
15
+ <title>Chofko's Diverse Ecosystem Simulator</title>
16
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/aframe/1.2.0/aframe.min.js"></script>
17
+ <style>
18
+ .controls {
19
+ position: absolute;
20
+ bottom: 20px;
21
+ left: 50%;
22
+ transform: translateX(-50%);
23
+ display: flex;
24
+ gap: 10px;
25
+ }
26
+ .controls button {
27
+ padding: 10px 20px;
28
+ font-size: 16px;
29
+ cursor: pointer;
30
+ }
31
+ #score {
32
+ position: absolute;
33
+ top: 20px;
34
+ left: 20px;
35
+ font-size: 24px;
36
+ color: white;
37
+ background-color: rgba(0,0,0,0.5);
38
+ padding: 10px;
39
+ border-radius: 5px;
40
+ }
41
+ </style>
42
+ </head>
43
+ <body>
44
+ <a-scene>
45
+ <a-assets>
46
+ <img id="sky" src="/api/placeholder/1024/512" alt="surrealist sky">
47
+ </a-assets>
48
 
49
+ <a-sky src="#sky"></a-sky>
50
+
51
+ <a-plane position="0 0 -4" rotation="-90 0 0" width="100" height="100" color="#7BC8A4"></a-plane>
52
+
53
+ <a-entity id="entities"></a-entity>
54
+
55
+ <a-entity id="camera" camera look-controls position="0 40 0" rotation="-90 0 0"></a-entity>
56
+ </a-scene>
57
+
58
+ <div id="score">Score: 0</div>
59
+
60
+ <div class="controls">
61
+ <button onmousedown="startMove('left')" onmouseup="stopMove('left')" ontouchstart="startMove('left')" ontouchend="stopMove('left')">Left</button>
62
+ <button onmousedown="startMove('right')" onmouseup="stopMove('right')" ontouchstart="startMove('right')" ontouchend="stopMove('right')">Right</button>
63
+ <button onmousedown="startMove('up')" onmouseup="stopMove('up')" ontouchstart="startMove('up')" ontouchend="stopMove('up')">Up</button>
64
+ <button onmousedown="startMove('down')" onmouseup="stopMove('down')" ontouchstart="startMove('down')" ontouchend="stopMove('down')">Down</button>
65
+ <button onclick="toggleSpeed()">Toggle Speed</button>
66
+ </div>
67
+
68
+ <script>
69
+ // ... (Include the entire JavaScript code from the original HTML file here)
70
+ </script>
71
+ </body>
72
+ </html>
73
+ ''')
74
+
75
+ with open("chofko_ecosystem.html", "r") as f:
76
  initial_html = f.read()
77
 
78
  # Initialize session state
 
93
  while player_name in st.session_state.player_names:
94
  player_name = generate_player_name()
95
  st.session_state.player_names.append(player_name)
96
+ player_html = f'''
97
+ new Entity(
98
+ {random.uniform(-50, 50)},
99
+ {random.uniform(-50, 50)},
100
+ false,
101
+ 'a-sphere',
102
+ '{random.choice(['male', 'female'])}',
103
+ 1
104
+ );
105
+ '''
106
+ st.session_state.html_content = st.session_state.html_content.replace("createEntities();", f"createEntities();\n {player_html}")
107
 
108
  # Streamlit app
109
  def main():
110
+ st.set_page_config(page_title="Chofko's Diverse Ecosystem Simulator", layout="wide")
111
+ st.title("Chofko's Diverse Ecosystem Simulator")
112
 
113
  # Add a new player button
114
+ if st.button("Add New Player", key="add_player"):
115
  add_player()
116
 
117
  # Display the HTML5 app
 
125
  if st.button("Save", key="save_button"):
126
  st.session_state.html_content = new_html
127
 
128
+ # Refresh button
129
  if st.button("Refresh", key="refresh_button"):
130
  st.experimental_rerun()
 
 
 
 
 
 
131
 
132
  if __name__ == "__main__":
133
  main()