|
import streamlit as st |
|
import numpy as np |
|
import time |
|
|
|
|
|
@st.cache(allow_output_mutation=True) |
|
def initialize_locations(size): |
|
"""Initialize different locations with unique emoji grids.""" |
|
np.random.seed(42) |
|
|
|
emoji_set = ["π²", "π³", "π", "π", "π ", "π°", "πΌ", "π€οΈ", "π", "ποΈ", |
|
"π", "πΎ", "ποΈ", "ποΈ", "π", "π£οΈ", "ποΈ", "π", "β°οΈ", "π§±", |
|
"π΅", "π", "πΌ", "π»", "πΊ", "π‘", "πΊοΈ", "πͺ¨", "π
", "π", |
|
"π ", "π", "ποΈ", "π", "π", "ποΈ", "βΊ", "π²", "π³", "π"] |
|
|
|
locations = { |
|
'forest edge': np.random.choice(emoji_set, (size, size)), |
|
'deep forest': np.random.choice(emoji_set, (size, size)), |
|
|
|
} |
|
return locations |
|
|
|
def is_prime(n): |
|
if n <= 1: |
|
return False |
|
for i in range(2, int(np.sqrt(n)) + 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:] |
|
|
|
directions = {"North": (-1, 0), "South": (1, 0), "West": (0, -1), "East": (0, 1)} |
|
|
|
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 |
|
|
|
def main(): |
|
st.title("Explore the Emoji World") |
|
|
|
size = st.sidebar.slider("Grid Size", 5, 40, 10) |
|
delay = st.sidebar.slider("Update Delay (ms)", 0, 1000, 100) |
|
|
|
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 = st.sidebar.selectbox("Move direction", ["None", "North", "South", "East", "West"]) |
|
if direction != "None": |
|
st.session_state.locations = move_emojis(st.session_state.locations, current_location, direction) |
|
|
|
|
|
cols = st.columns([1, 1, 1, 1, 1]) |
|
with cols[1]: |
|
if st.button('W'): |
|
direction = "North" |
|
with cols[0]: |
|
if st.button('A'): |
|
direction = "West" |
|
with cols[2]: |
|
if st.button('D'): |
|
direction = "East" |
|
with cols[4]: |
|
if st.button('S'): |
|
direction = "South" |
|
|
|
if direction: |
|
st.session_state.locations = move_emojis(st.session_state.locations, current_location, direction) |
|
|
|
time.sleep(delay / 1000.0) |
|
st.experimental_rerun() |
|
|
|
st.sidebar.text("Controls: Use WASD buttons or the dropdown to navigate.") |
|
st.sidebar.text("Delay controls the speed of updates to help with motion sensitivity.") |
|
|
|
if __name__ == "__main__": |
|
|
|
|