File size: 4,499 Bytes
1b8a61e
08f6cf8
9353d37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1b8a61e
f322fc1
 
 
9353d37
f322fc1
 
 
1b8a61e
f322fc1
 
 
 
 
1b8a61e
08f6cf8
 
f322fc1
08f6cf8
f322fc1
 
1b8a61e
f322fc1
 
1b8a61e
9353d37
 
d3dc3f6
f322fc1
 
9353d37
f322fc1
 
9353d37
f322fc1
 
 
9353d37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d3dc3f6
f322fc1
 
1b8a61e
9353d37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1b8a61e
9353d37
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import streamlit as st
import numpy as np
import random

# Streamlit caching for faster location initialization
@st.cache(allow_output_mutation=True)
def initialize_locations(size):
    """Initialize different locations with unique emoji grids."""
    np.random.seed(42)  # Ensure reproducibility

    # Expanded emoji set for diverse landscapes
    emoji_set = ["🌲", "🌳", "πŸƒ", "πŸ„", "🏠", "🏰", "πŸ—Ό", "πŸ›€οΈ", "🌊", "🏞️",
                 "🌁", "🌾", "🏜️", "🏝️", "πŸ›–", "πŸ›£οΈ", "πŸ•οΈ", "πŸŒ‹", "⛰️", "🧱",
                 "🌡", "🍁", "🌼", "🌻", "🌺", "🏑", "πŸ—ΊοΈ", "πŸͺ¨", "πŸŒ…", "πŸŒ„",
                 "🌠", "🌌", "🏞️", "πŸŒ‰", "πŸŒ‡", "πŸ”οΈ", "β›Ί", "🌲", "🌳", "πŸ‚"]

    # Randomize emoji placement for each location
    locations = {
        'forest edge': np.random.choice(emoji_set, (size, size)),
        'deep forest': np.random.choice(emoji_set, (size, size)),
        'mountain range': np.random.choice(emoji_set, (size, size)),
        'desert oasis': np.random.choice(emoji_set, (size, size)),
        'city center': np.random.choice(emoji_set, (size, size)),
        'starry night': np.random.choice(emoji_set, (size, size)),
        'tropical island': np.random.choice(emoji_set, (size, size)),
        'camping site': 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:]  # Exclude first two numbers for this use case

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, 20)
    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)

    # WASD-like controls using Streamlit buttons
    cols = st.columns(5)
    direction = None

    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)
        st.experimental_rerun()

    st.sidebar.text("Controls: Use WASD buttons to navigate.")
    st.sidebar.text("Delay controls the speed of updates to help with motion sensitivity.")

    # Delay implementation
    st.time.sleep(delay / 1000.0)  # Convert ms to seconds

    # Display additional information in the sidebar
    st.sidebar.header("Additional Information")
    st.sidebar.subheader("Prime Numbers")
    prime_num = st.sidebar.number_input("Enter a number to check if it's prime", min_value=1, step=1)
    if is_prime(prime_num):
        st.sidebar.write(f"{prime_num} is a prime number.")
    else:
        st.sidebar.write(f"{prime_num} is not a prime number.")

    st.sidebar.subheader("Fibonacci Sequence")
    fib_limit = st.sidebar.number_input("Enter a limit for the Fibonacci sequence", min_value=1, step=1)
    fib_sequence_list = fib_sequence(fib_limit)
    st.sidebar.write(f"Fibonacci sequence up to {fib_limit}: {', '.join(str(num) for num in fib_sequence_list)}")

    # Random emoji generator
    st.sidebar.subheader("Random Emoji Generator")
    num_emojis = st.sidebar.number_input("Number of random emojis", min_value=1, max_value=20, value=5, step=1)
    random_emojis = random.sample(emoji_set, num_emojis)
    st.sidebar.write("Random emojis:")
    st.sidebar.write(" ".join(random_emojis))

if __name__ == "__main__":
    main()