awacke1 commited on
Commit
f2d0a0e
Β·
verified Β·
1 Parent(s): 668cb89

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +88 -0
app.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
30
+
31
+ def fib_sequence(n):
32
+ fib_seq = [0, 1]
33
+ while fib_seq[-1] + fib_seq[-2] <= 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
+