awacke1 commited on
Commit
d3dc3f6
Β·
verified Β·
1 Parent(s): f322fc1

Update app.py

Browse files

import streamlit as st
import numpy as np
import time

# Helper functions for number theory-based emoji placement
def is_prime(n):
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True

def fib_sequence(n):
fib_seq = [0, 1]
while fib_seq[-1] + fib_seq[-2] <= n:
fib_seq.append(fib_seq[-1] + fib_seq[-2])
return fib_seq[2:] # Exclude first two numbers for this use case

# Expanded set of emojis for landscape elements
emoji_set = ["🌲", "🌳", "πŸƒ", "🌲", "🌿", "πŸ„", "🏠", "🏰", "πŸ—Ό", "πŸ›€οΈ", "🌊", "🏞️", "🌁", "🌾", "🏜️", "🏝️", "πŸ›–", "πŸ›€οΈ", "πŸ›£οΈ", "πŸ•οΈ", "πŸŒ‹", "⛰️", "🧱", "🌡", "🍁", "🌼", "🌻", "🌺", "🏑", "πŸ—ΊοΈ", "β›Ί", "πŸŒ…", "πŸŒ„", "🌠", "πŸ‚", "πŸ€", "🌴", "πŸŽ„", "🌡", "πŸŒ™", "⭐", "🌀️", "πŸŒͺ"]

# Initialize locations with more varied and staggered emojis
def initialize_locations(size):
np.random.seed(42) # For reproducibility
locations = {
'forest edge': np.random.choice(emoji_set, (size, size)),
'deep forest': np.random.choice(emoji_set, (size, size)),
# Add other locations with corresponding maps as needed
}
return locations

# Directions for movement
directions = {"North": (-1, 0), "South": (1, 0), "West": (0, -1), "East": (0, 1)}

# Shift emojis based on direction with wrap-around
def move_emojis(locations, current_location, direction):
dx, dy = directions[direction]
locations[current_location] = np.roll(locations[current_location], shift=(dx, dy), axis=(0, 1))
return locations

# WASD movement interface
def wasd_interface():
direction = None
with st.form("wasd_form", clear_on_submit=True):
direction_input = st.text_input("Enter direction (WASD):", "")
submitted = st.form_submit_button("Move")
if submitted and direction_input.upper() in ['W', 'A', 'S', 'D']:
direction = {'W': 'North', 'A': 'West', 'S': 'South', 'D': 'East'}[direction_input.upper()]
return direction

# Main application
def main():
st.title("Explore the Emoji World")

size = st.sidebar.slider("Grid Size", 5, 40, 10)
delay = st.sidebar.slider("Movement Delay (seconds)", 0.0, 1.0, 0.1)

if 'locations' not in st.session_state:
st.session_state.locations = initialize_locations(size)

current_location = st.sidebar.selectbox("Select location", options=list(st.session_state.locations.keys()))
emoji_map = st.session_state.locations[current_location]
map_str = "\n".join(["".join(row) for row in emoji_map])
st.text(map_str)

direction = wasd_interface()
if direction:
st.session_state.locations = move_emojis(st.session_state.locations, current_location, direction)
time.sleep(delay) # Delay to adjust the speed of movement
st.experimental_rerun()

if __name__ == "__main__":
main()

Files changed (1) hide show
  1. app.py +22 -12
app.py CHANGED
@@ -1,5 +1,6 @@
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):
@@ -17,36 +18,44 @@ def fib_sequence(n):
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
 
@@ -55,9 +64,10 @@ def main():
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__":
 
1
  import streamlit as st
2
  import numpy as np
3
+ import time
4
 
5
  # Helper functions for number theory-based emoji placement
6
  def is_prime(n):
 
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, 10)
57
+ delay = st.sidebar.slider("Movement Delay (seconds)", 0.0, 1.0, 0.1)
58
+
59
  if 'locations' not in st.session_state:
60
  st.session_state.locations = initialize_locations(size)
61
 
 
64
  map_str = "\n".join(["".join(row) for row in emoji_map])
65
  st.text(map_str)
66
 
67
+ direction = wasd_interface()
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__":