Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,36 @@
|
|
1 |
import streamlit as st
|
2 |
import numpy as np
|
3 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
-
# Helper functions for number theory-based emoji placement
|
6 |
def is_prime(n):
|
7 |
if n <= 1:
|
8 |
return False
|
9 |
-
for i in range(2, int(n
|
10 |
if n % i == 0:
|
11 |
return False
|
12 |
return True
|
@@ -17,58 +41,78 @@ def fib_sequence(n):
|
|
17 |
fib_seq.append(fib_seq[-1] + fib_seq[-2])
|
18 |
return fib_seq[2:] # Exclude first two numbers for this use case
|
19 |
|
20 |
-
# Expanded set of emojis for landscape elements
|
21 |
-
emoji_set = ["π²", "π³", "π", "π²", "πΏ", "π", "π ", "π°", "πΌ", "π€οΈ", "π", "ποΈ", "π", "πΎ", "ποΈ", "ποΈ", "π", "π€οΈ", "π£οΈ", "ποΈ", "π", "β°οΈ", "π§±", "π΅", "π", "πΌ", "π»", "πΊ", "π‘", "πΊοΈ", "βΊ", "π
", "π", "π ", "π", "π", "π΄", "π", "π΅", "π", "β", "π€οΈ", "πͺ"]
|
22 |
-
|
23 |
-
# Initialize locations with more varied and staggered emojis
|
24 |
-
def initialize_locations(size):
|
25 |
-
np.random.seed(42) # For reproducibility
|
26 |
-
locations = {
|
27 |
-
'forest edge': np.random.choice(emoji_set, (size, size)),
|
28 |
-
'deep forest': np.random.choice(emoji_set, (size, size)),
|
29 |
-
# Add other locations with corresponding maps as needed
|
30 |
-
}
|
31 |
-
return locations
|
32 |
-
|
33 |
-
# Directions for movement
|
34 |
directions = {"North": (-1, 0), "South": (1, 0), "West": (0, -1), "East": (0, 1)}
|
35 |
|
36 |
-
# Shift emojis based on direction with wrap-around
|
37 |
def move_emojis(locations, current_location, direction):
|
38 |
dx, dy = directions[direction]
|
39 |
locations[current_location] = np.roll(locations[current_location], shift=(dx, dy), axis=(0, 1))
|
40 |
return locations
|
41 |
|
42 |
-
# WASD movement interface
|
43 |
-
def wasd_interface():
|
44 |
-
direction = None
|
45 |
-
with st.form("wasd_form", clear_on_submit=True):
|
46 |
-
direction_input = st.text_input("Enter direction (WASD):", "")
|
47 |
-
submitted = st.form_submit_button("Move")
|
48 |
-
if submitted and direction_input.upper() in ['W', 'A', 'S', 'D']:
|
49 |
-
direction = {'W': 'North', 'A': 'West', 'S': 'South', 'D': 'East'}[direction_input.upper()]
|
50 |
-
return direction
|
51 |
-
|
52 |
-
# Main application
|
53 |
def main():
|
54 |
st.title("Explore the Emoji World")
|
55 |
|
56 |
-
size = st.sidebar.slider("Grid Size", 5, 40,
|
57 |
-
delay = st.sidebar.slider("
|
58 |
|
59 |
if 'locations' not in st.session_state:
|
60 |
st.session_state.locations = initialize_locations(size)
|
61 |
-
|
62 |
current_location = st.sidebar.selectbox("Select location", options=list(st.session_state.locations.keys()))
|
63 |
emoji_map = st.session_state.locations[current_location]
|
|
|
64 |
map_str = "\n".join(["".join(row) for row in emoji_map])
|
65 |
st.text(map_str)
|
66 |
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
if direction:
|
69 |
st.session_state.locations = move_emojis(st.session_state.locations, current_location, direction)
|
70 |
-
time.sleep(delay) # Delay to adjust the speed of movement
|
71 |
st.experimental_rerun()
|
72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
if __name__ == "__main__":
|
74 |
-
main()
|
|
|
1 |
import streamlit as st
|
2 |
import numpy as np
|
3 |
+
import random
|
4 |
+
|
5 |
+
# Streamlit caching for faster location initialization
|
6 |
+
@st.cache(allow_output_mutation=True)
|
7 |
+
def initialize_locations(size):
|
8 |
+
"""Initialize different locations with unique emoji grids."""
|
9 |
+
np.random.seed(42) # Ensure reproducibility
|
10 |
+
|
11 |
+
# Expanded emoji set for diverse landscapes
|
12 |
+
emoji_set = ["π²", "π³", "π", "π", "π ", "π°", "πΌ", "π€οΈ", "π", "ποΈ",
|
13 |
+
"π", "πΎ", "ποΈ", "ποΈ", "π", "π£οΈ", "ποΈ", "π", "β°οΈ", "π§±",
|
14 |
+
"π΅", "π", "πΌ", "π»", "πΊ", "π‘", "πΊοΈ", "πͺ¨", "π
", "π",
|
15 |
+
"π ", "π", "ποΈ", "π", "π", "ποΈ", "βΊ", "π²", "π³", "π"]
|
16 |
+
|
17 |
+
# Randomize emoji placement for each location
|
18 |
+
locations = {
|
19 |
+
'forest edge': np.random.choice(emoji_set, (size, size)),
|
20 |
+
'deep forest': np.random.choice(emoji_set, (size, size)),
|
21 |
+
'mountain range': np.random.choice(emoji_set, (size, size)),
|
22 |
+
'desert oasis': np.random.choice(emoji_set, (size, size)),
|
23 |
+
'city center': np.random.choice(emoji_set, (size, size)),
|
24 |
+
'starry night': np.random.choice(emoji_set, (size, size)),
|
25 |
+
'tropical island': np.random.choice(emoji_set, (size, size)),
|
26 |
+
'camping site': np.random.choice(emoji_set, (size, size)),
|
27 |
+
}
|
28 |
+
return locations
|
29 |
|
|
|
30 |
def is_prime(n):
|
31 |
if n <= 1:
|
32 |
return False
|
33 |
+
for i in range(2, int(np.sqrt(n)) + 1):
|
34 |
if n % i == 0:
|
35 |
return False
|
36 |
return True
|
|
|
41 |
fib_seq.append(fib_seq[-1] + fib_seq[-2])
|
42 |
return fib_seq[2:] # Exclude first two numbers for this use case
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
directions = {"North": (-1, 0), "South": (1, 0), "West": (0, -1), "East": (0, 1)}
|
45 |
|
|
|
46 |
def move_emojis(locations, current_location, direction):
|
47 |
dx, dy = directions[direction]
|
48 |
locations[current_location] = np.roll(locations[current_location], shift=(dx, dy), axis=(0, 1))
|
49 |
return locations
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
def main():
|
52 |
st.title("Explore the Emoji World")
|
53 |
|
54 |
+
size = st.sidebar.slider("Grid Size", 5, 40, 20)
|
55 |
+
delay = st.sidebar.slider("Update Delay (ms)", 0, 1000, 100)
|
56 |
|
57 |
if 'locations' not in st.session_state:
|
58 |
st.session_state.locations = initialize_locations(size)
|
59 |
+
|
60 |
current_location = st.sidebar.selectbox("Select location", options=list(st.session_state.locations.keys()))
|
61 |
emoji_map = st.session_state.locations[current_location]
|
62 |
+
|
63 |
map_str = "\n".join(["".join(row) for row in emoji_map])
|
64 |
st.text(map_str)
|
65 |
|
66 |
+
# WASD-like controls using Streamlit buttons
|
67 |
+
cols = st.columns(5)
|
68 |
+
direction = None
|
69 |
+
|
70 |
+
with cols[1]:
|
71 |
+
if st.button('W'):
|
72 |
+
direction = "North"
|
73 |
+
|
74 |
+
with cols[0]:
|
75 |
+
if st.button('A'):
|
76 |
+
direction = "West"
|
77 |
+
|
78 |
+
with cols[2]:
|
79 |
+
if st.button('D'):
|
80 |
+
direction = "East"
|
81 |
+
|
82 |
+
with cols[4]:
|
83 |
+
if st.button('S'):
|
84 |
+
direction = "South"
|
85 |
+
|
86 |
if direction:
|
87 |
st.session_state.locations = move_emojis(st.session_state.locations, current_location, direction)
|
|
|
88 |
st.experimental_rerun()
|
89 |
|
90 |
+
st.sidebar.text("Controls: Use WASD buttons to navigate.")
|
91 |
+
st.sidebar.text("Delay controls the speed of updates to help with motion sensitivity.")
|
92 |
+
|
93 |
+
# Delay implementation
|
94 |
+
st.time.sleep(delay / 1000.0) # Convert ms to seconds
|
95 |
+
|
96 |
+
# Display additional information in the sidebar
|
97 |
+
st.sidebar.header("Additional Information")
|
98 |
+
st.sidebar.subheader("Prime Numbers")
|
99 |
+
prime_num = st.sidebar.number_input("Enter a number to check if it's prime", min_value=1, step=1)
|
100 |
+
if is_prime(prime_num):
|
101 |
+
st.sidebar.write(f"{prime_num} is a prime number.")
|
102 |
+
else:
|
103 |
+
st.sidebar.write(f"{prime_num} is not a prime number.")
|
104 |
+
|
105 |
+
st.sidebar.subheader("Fibonacci Sequence")
|
106 |
+
fib_limit = st.sidebar.number_input("Enter a limit for the Fibonacci sequence", min_value=1, step=1)
|
107 |
+
fib_sequence_list = fib_sequence(fib_limit)
|
108 |
+
st.sidebar.write(f"Fibonacci sequence up to {fib_limit}: {', '.join(str(num) for num in fib_sequence_list)}")
|
109 |
+
|
110 |
+
# Random emoji generator
|
111 |
+
st.sidebar.subheader("Random Emoji Generator")
|
112 |
+
num_emojis = st.sidebar.number_input("Number of random emojis", min_value=1, max_value=20, value=5, step=1)
|
113 |
+
random_emojis = random.sample(emoji_set, num_emojis)
|
114 |
+
st.sidebar.write("Random emojis:")
|
115 |
+
st.sidebar.write(" ".join(random_emojis))
|
116 |
+
|
117 |
if __name__ == "__main__":
|
118 |
+
main()
|