Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,9 @@
|
|
1 |
import streamlit as st
|
2 |
import numpy as np
|
|
|
3 |
|
4 |
# Helper functions for number theory-based emoji placement
|
|
|
5 |
def is_prime(n):
|
6 |
if n <= 1:
|
7 |
return False
|
@@ -14,17 +16,19 @@ def fib_sequence(n):
|
|
14 |
fib_seq = [0, 1]
|
15 |
while fib_seq[-1] + fib_seq[-2] <= n:
|
16 |
fib_seq.append(fib_seq[-1] + fib_seq[-2])
|
17 |
-
return fib_seq[2:]
|
18 |
|
19 |
# Expanded set of emojis for landscape elements
|
|
|
20 |
emoji_set = ["π²", "π³", "π", "π²", "πΏ", "π", "π ", "π°", "πΌ", "π€οΈ", "π", "ποΈ", "π", "πΎ", "ποΈ", "ποΈ", "π", "π€οΈ", "π£οΈ", "ποΈ", "π", "β°οΈ", "π§±", "π΅", "π", "πΌ", "π»", "πΊ", "π‘", "πΊοΈ", "π
", "π", "ποΈ", "ποΈ", "π»", "ποΈ", "ποΈ", "π―", "ποΈ", "π", "π", "π", "ποΈ"]
|
21 |
|
22 |
# Locations and emoji grid maps initialization
|
|
|
23 |
def initialize_locations(size):
|
24 |
"""Initialize different locations with unique emoji grids."""
|
25 |
# Placeholder for location initialization logic
|
26 |
# Randomly fill grids with emojis from emoji_set for each location
|
27 |
-
np.random.seed(42)
|
28 |
locations = {
|
29 |
'forest edge': np.random.choice(emoji_set, (size, size)),
|
30 |
'deep forest': np.random.choice(emoji_set, (size, size)),
|
@@ -35,53 +39,60 @@ def initialize_locations(size):
|
|
35 |
return locations
|
36 |
|
37 |
# Directions for movement
|
|
|
38 |
directions = {"North": (-1, 0), "South": (1, 0), "West": (0, -1), "East": (0, 1)}
|
39 |
|
40 |
# Movement and emoji map update functions
|
41 |
-
|
|
|
42 |
"""Shift emojis in the specified direction with wrap-around for the current location."""
|
43 |
-
dx, dy = directions[direction]
|
44 |
locations[current_location] = np.roll(locations[current_location], shift=(dx, dy), axis=(0, 1))
|
45 |
return locations
|
46 |
|
47 |
# Streamlit application setup
|
|
|
48 |
def main():
|
49 |
st.title("Explore the Emoji World")
|
50 |
-
|
51 |
size = st.sidebar.slider("Grid Size", 5, 40, 10)
|
|
|
52 |
|
53 |
if 'locations' not in st.session_state:
|
54 |
st.session_state.locations = initialize_locations(size)
|
55 |
else:
|
56 |
st.session_state.locations = initialize_locations(size)
|
57 |
|
58 |
-
|
|
|
59 |
|
|
|
60 |
emoji_map = st.session_state.locations[current_location]
|
61 |
map_str = "\n".join(["".join(row) for row in emoji_map])
|
62 |
st.text(map_str)
|
63 |
|
64 |
col1, col2, col3 = st.columns(3)
|
|
|
65 |
with col1:
|
66 |
if st.button("West"):
|
67 |
-
direction = "West"
|
|
|
68 |
with col2:
|
69 |
if st.button("North"):
|
70 |
-
direction = "North"
|
71 |
if st.button("Stop"):
|
72 |
-
direction = "None"
|
73 |
if st.button("South"):
|
74 |
-
direction = "South"
|
|
|
75 |
with col3:
|
76 |
if st.button("East"):
|
77 |
-
direction = "East"
|
78 |
-
|
79 |
-
if
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
st.experimental_rerun()
|
85 |
|
86 |
if __name__ == "__main__":
|
87 |
main()
|
|
|
1 |
import streamlit as st
|
2 |
import numpy as np
|
3 |
+
import time
|
4 |
|
5 |
# Helper functions for number theory-based emoji placement
|
6 |
+
|
7 |
def is_prime(n):
|
8 |
if n <= 1:
|
9 |
return False
|
|
|
16 |
fib_seq = [0, 1]
|
17 |
while fib_seq[-1] + fib_seq[-2] <= n:
|
18 |
fib_seq.append(fib_seq[-1] + fib_seq[-2])
|
19 |
+
return fib_seq[2:] # Exclude first two numbers for this use case
|
20 |
|
21 |
# Expanded set of emojis for landscape elements
|
22 |
+
|
23 |
emoji_set = ["π²", "π³", "π", "π²", "πΏ", "π", "π ", "π°", "πΌ", "π€οΈ", "π", "ποΈ", "π", "πΎ", "ποΈ", "ποΈ", "π", "π€οΈ", "π£οΈ", "ποΈ", "π", "β°οΈ", "π§±", "π΅", "π", "πΌ", "π»", "πΊ", "π‘", "πΊοΈ", "π
", "π", "ποΈ", "ποΈ", "π»", "ποΈ", "ποΈ", "π―", "ποΈ", "π", "π", "π", "ποΈ"]
|
24 |
|
25 |
# Locations and emoji grid maps initialization
|
26 |
+
|
27 |
def initialize_locations(size):
|
28 |
"""Initialize different locations with unique emoji grids."""
|
29 |
# Placeholder for location initialization logic
|
30 |
# Randomly fill grids with emojis from emoji_set for each location
|
31 |
+
np.random.seed(42) # Optional: for reproducible emoji distributions
|
32 |
locations = {
|
33 |
'forest edge': np.random.choice(emoji_set, (size, size)),
|
34 |
'deep forest': np.random.choice(emoji_set, (size, size)),
|
|
|
39 |
return locations
|
40 |
|
41 |
# Directions for movement
|
42 |
+
|
43 |
directions = {"North": (-1, 0), "South": (1, 0), "West": (0, -1), "East": (0, 1)}
|
44 |
|
45 |
# Movement and emoji map update functions
|
46 |
+
|
47 |
+
def move_emojis(locations, current_location, direction, velocity):
|
48 |
"""Shift emojis in the specified direction with wrap-around for the current location."""
|
49 |
+
dx, dy = [coord * velocity for coord in directions[direction]]
|
50 |
locations[current_location] = np.roll(locations[current_location], shift=(dx, dy), axis=(0, 1))
|
51 |
return locations
|
52 |
|
53 |
# Streamlit application setup
|
54 |
+
|
55 |
def main():
|
56 |
st.title("Explore the Emoji World")
|
|
|
57 |
size = st.sidebar.slider("Grid Size", 5, 40, 10)
|
58 |
+
velocity = st.sidebar.slider("Velocity (emojis/sec)", 1, 10, 1)
|
59 |
|
60 |
if 'locations' not in st.session_state:
|
61 |
st.session_state.locations = initialize_locations(size)
|
62 |
else:
|
63 |
st.session_state.locations = initialize_locations(size)
|
64 |
|
65 |
+
if 'direction' not in st.session_state:
|
66 |
+
st.session_state.direction = "None"
|
67 |
|
68 |
+
current_location = st.sidebar.selectbox("Select location", options=list(st.session_state.locations.keys()))
|
69 |
emoji_map = st.session_state.locations[current_location]
|
70 |
map_str = "\n".join(["".join(row) for row in emoji_map])
|
71 |
st.text(map_str)
|
72 |
|
73 |
col1, col2, col3 = st.columns(3)
|
74 |
+
|
75 |
with col1:
|
76 |
if st.button("West"):
|
77 |
+
st.session_state.direction = "West"
|
78 |
+
|
79 |
with col2:
|
80 |
if st.button("North"):
|
81 |
+
st.session_state.direction = "North"
|
82 |
if st.button("Stop"):
|
83 |
+
st.session_state.direction = "None"
|
84 |
if st.button("South"):
|
85 |
+
st.session_state.direction = "South"
|
86 |
+
|
87 |
with col3:
|
88 |
if st.button("East"):
|
89 |
+
st.session_state.direction = "East"
|
90 |
+
|
91 |
+
if st.session_state.direction != "None":
|
92 |
+
st.session_state.locations = move_emojis(st.session_state.locations, current_location, st.session_state.direction, velocity)
|
93 |
+
|
94 |
+
time.sleep(1)
|
95 |
+
st.experimental_rerun()
|
|
|
96 |
|
97 |
if __name__ == "__main__":
|
98 |
main()
|