awacke1 commited on
Commit
6a9e178
Β·
verified Β·
1 Parent(s): 3ed0554

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -48
app.py CHANGED
@@ -1,29 +1,11 @@
1
  import streamlit as st
2
  import numpy as np
3
- import time # Ensure this import is included for the delay functionality
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
- # Expanded emoji set for diverse landscapes
11
- emoji_set = ["🌲", "🌳", "πŸƒ", "πŸ„", "🏠", "🏰", "πŸ—Ό", "πŸ›€οΈ", "🌊", "🏞️",
12
- "🌁", "🌾", "🏜️", "🏝️", "πŸ›–", "πŸ›£οΈ", "πŸ•οΈ", "πŸŒ‹", "⛰️", "🧱",
13
- "🌡", "🍁", "🌼", "🌻", "🌺", "🏑", "πŸ—ΊοΈ", "πŸͺ¨", "πŸŒ…", "πŸŒ„",
14
- "🌠", "🌌", "🏞️", "πŸŒ‰", "πŸŒ‡", "πŸ”οΈ", "β›Ί", "🌲", "🌳", "πŸ‚"]
15
- # Randomize emoji placement for each location
16
- locations = {
17
- 'forest edge': np.random.choice(emoji_set, (size, size)),
18
- 'deep forest': np.random.choice(emoji_set, (size, size)),
19
- # Additional locations with their unique emoji maps can be added here
20
- }
21
- return locations
22
 
 
23
  def is_prime(n):
24
  if n <= 1:
25
  return False
26
- for i in range(2, int(np.sqrt(n)) + 1):
27
  if n % i == 0:
28
  return False
29
  return True
@@ -34,55 +16,49 @@ def fib_sequence(n):
34
  fib_seq.append(fib_seq[-1] + fib_seq[-2])
35
  return fib_seq[2:] # Exclude first two numbers for this use case
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  directions = {"North": (-1, 0), "South": (1, 0), "West": (0, -1), "East": (0, 1)}
38
 
 
39
  def move_emojis(locations, current_location, direction):
 
40
  dx, dy = directions[direction]
41
  locations[current_location] = np.roll(locations[current_location], shift=(dx, dy), axis=(0, 1))
42
  return locations
43
 
 
44
  def main():
45
  st.title("Explore the Emoji World")
46
 
47
  size = st.sidebar.slider("Grid Size", 5, 40, 10)
48
- delay = st.sidebar.slider("Update Delay (ms)", 0, 1000, 100)
49
-
50
  if 'locations' not in st.session_state:
51
  st.session_state.locations = initialize_locations(size)
52
-
53
  current_location = st.sidebar.selectbox("Select location", options=list(st.session_state.locations.keys()))
54
  emoji_map = st.session_state.locations[current_location]
55
  map_str = "\n".join(["".join(row) for row in emoji_map])
56
  st.text(map_str)
57
 
58
- # Sidebar selectbox for movement
59
  direction = st.sidebar.selectbox("Move direction", ["None", "North", "South", "East", "West"])
60
  if direction != "None":
61
  st.session_state.locations = move_emojis(st.session_state.locations, current_location, direction)
62
-
63
- # WASD-like controls using Streamlit buttons
64
- cols = st.columns([1, 1, 1, 1, 1])
65
- with cols[1]:
66
- if st.button('W'):
67
- direction = "North"
68
- with cols[0]:
69
- if st.button('A'):
70
- direction = "West"
71
- with cols[2]:
72
- if st.button('D'):
73
- direction = "East"
74
- with cols[4]:
75
- if st.button('S'):
76
- direction = "South"
77
-
78
- if direction:
79
- st.session_state.locations = move_emojis(st.session_state.locations, current_location, direction)
80
- # Delay implementation
81
- time.sleep(delay / 1000.0) # Convert ms to seconds
82
  st.experimental_rerun()
83
 
84
- st.sidebar.text("Controls: Use WASD buttons or the dropdown to navigate.")
85
- st.sidebar.text("Delay controls the speed of updates to help with motion sensitivity.")
86
-
87
  if __name__ == "__main__":
88
- main()
 
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
8
+ for i in range(2, int(n**0.5) + 1):
9
  if n % i == 0:
10
  return False
11
  return True
 
16
  fib_seq.append(fib_seq[-1] + fib_seq[-2])
17
  return fib_seq[2:] # Exclude first two numbers for this use case
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) # Optional: for reproducible emoji distributions
28
+ locations = {
29
+ 'forest edge': np.random.choice(emoji_set, (size, size)),
30
+ 'deep forest': np.random.choice(emoji_set, (size, size)),
31
+ # Additional locations can be added here
32
+ }
33
+ return locations
34
+
35
+ # Directions for movement
36
  directions = {"North": (-1, 0), "South": (1, 0), "West": (0, -1), "East": (0, 1)}
37
 
38
+ # Movement and emoji map update functions
39
  def move_emojis(locations, current_location, direction):
40
+ """Shift emojis in the specified direction with wrap-around for the current location."""
41
  dx, dy = directions[direction]
42
  locations[current_location] = np.roll(locations[current_location], shift=(dx, dy), axis=(0, 1))
43
  return locations
44
 
45
+ # Streamlit application setup
46
  def main():
47
  st.title("Explore the Emoji World")
48
 
49
  size = st.sidebar.slider("Grid Size", 5, 40, 10)
 
 
50
  if 'locations' not in st.session_state:
51
  st.session_state.locations = initialize_locations(size)
52
+
53
  current_location = st.sidebar.selectbox("Select location", options=list(st.session_state.locations.keys()))
54
  emoji_map = st.session_state.locations[current_location]
55
  map_str = "\n".join(["".join(row) for row in emoji_map])
56
  st.text(map_str)
57
 
 
58
  direction = st.sidebar.selectbox("Move direction", ["None", "North", "South", "East", "West"])
59
  if direction != "None":
60
  st.session_state.locations = move_emojis(st.session_state.locations, current_location, direction)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  st.experimental_rerun()
62
 
 
 
 
63
  if __name__ == "__main__":
64
+ main()