Grundlefly the Numeric Theory Simulator and A Graphic AI Novel (GAIN) Application

#1
by awacke1 - opened
Owner

Mix my two programs below to have the emoji based numeric simulation generate the tilemap of moves when the user chooses to move shift the generated emojis to north (move emojis downwards and wrap if they go off screen, south upwards, west move emojis to right, and east move emojis to left so it looks like the user is walking due to the emojis moving. Here is my numeric simulation - use the emojis for this feature. import streamlit as st
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.colors as mcolors

Global constant for golden ratio

golden_ratio = (1 + np.sqrt(5)) / 2
color_wheel = plt.get_cmap('hsv') # Use the HSV color wheel for harmonious colors

def is_prime(n):
"""Check if a number is prime."""
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):
"""Generate Fibonacci sequence up to 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

def adjust_color_brightness(color, factor):
"""Adjust the brightness of a color."""
return tuple(np.array(mcolors.to_rgb(color)) * factor)

def generate_colored_circle_template(num_circles):
"""Improved use of color and symmetry in circle generation."""
fig, ax = plt.subplots(figsize=(6, 6))
ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
ax.axis('off')

for i in range(num_circles):
    radius = np.random.uniform(0.05, 0.1)
    angle = 2 * np.pi * i / num_circles
    distance = np.sqrt(np.random.uniform(0.1, 0.9))
    x = 0.5 + distance * np.cos(angle)
    y = 0.5 + distance * np.sin(angle)
    color = color_wheel(i / num_circles)
    alpha = 0.6 + 0.4 * (1 - distance)  # More transparent further out
    circle = plt.Circle((x, y), radius, color=color, alpha=alpha)
    ax.add_artist(circle)
return fig

def generate_symmetrical_circle_layout(num_layers):
"""Generate a more symmetrical circle layout."""
fig, ax = plt.subplots(figsize=(6, 6))
ax.set_aspect('equal')
ax.axis('off')

max_radius = 0.1 + 0.15 * (num_layers - 1)  # Adjust so outer circles don't overlap the figure boundary
center = (0.5, 0.5)

for layer in range(num_layers):
    radius = 0.05 + layer * 0.1
    num_circles = layer * 6 if layer > 0 else 1  # Increase circles in outer layers
    for i in range(num_circles):
        angle = 2 * np.pi * i / num_circles
        x = center[0] + radius * np.cos(angle)
        y = center[1] + radius * np.sin(angle)
        color = color_wheel(i / num_circles)
        circle = plt.Circle((x, y), max_radius / num_layers, color=color, alpha=0.5 + 0.5 * (1 - layer / num_layers))
        ax.add_artist(circle)
return fig

def generate_fibonacci_spiral_layout(num_points):
"""Generate layout based on Fibonacci spiral."""
fig, ax = plt.subplots(figsize=(6, 6))
ax.axis('off')
radius = 0.05
for i in range(num_points):
angle = i * 2 * np.pi / golden_ratio
distance = np.sqrt(i) * radius
x = 0.5 + distance * np.cos(angle)
y = 0.5 + distance * np.sin(angle)
color = color_wheel(i / num_points)
circle = plt.Circle((x, y), radius, color=color, fill=True, alpha=0.8)
ax.add_artist(circle)
ax.set_aspect('equal')
return fig

def generate_prime_number_spiral(num_points):
"""Generate spiral layout highlighting prime numbers."""
fig, ax = plt.subplots(figsize=(6, 6))
ax.axis('off')
radius = 0.05
for i in range(1, num_points + 1):
if is_prime(i):
angle = i * 2 * np.pi / golden_ratio
distance = np.sqrt(i) * radius
x = 0.5 + distance * np.cos(angle)
y = 0.5 + distance * np.sin(angle)
color = color_wheel(i / num_points)
circle = plt.Circle((x, y), radius, color=color, fill=True, alpha=0.8)
ax.add_artist(circle)
ax.set_aspect('equal')
return fig

def emoji_dynamics_and_number_theory_simulation(size):
"""Simulate emoji dynamics based on number theory."""
fib_seq = fib_sequence(size**2)
grid = []

for i in range(1, size**2 + 1):
    if i in fib_seq:
        grid.append("πŸŒ€")  # Fibonacci positions
    elif is_prime(i):
        grid.append("🌟")  # Prime positions
    else:
        grid.append("βšͺ")  # Other positions

    if i % size == 0:
        grid.append("\n")  # Newline at the end of each row

return "".join(grid)

Streamlit UI setup

st.title("Circle Packings and Number Theory Visualizations")

mode = st.radio(
"Choose a visualization mode:",
("Random Circle Packings", "Symmetrical Circle Layouts", "Fibonacci Spiral Layout", "Prime Number Spiral", "Emoji Dynamics and Number Theory Simulation")
)

if mode == "Random Circle Packings":
num_circles = st.slider("Number of Circles", 5, 50, 10)
fig = generate_colored_circle_template(num_circles)
elif mode == "Symmetrical Circle Layouts":
num_layers = st.slider("Number of Symmetrical Layers", 1, 5, 3)
fig = generate_symmetrical_circle_layout(num_layers)
elif mode == "Fibonacci Spiral Layout":
num_points = st.slider("Number of Points", 10, 100, 30)
fig = generate_fibonacci_spiral_layout(num_points)
elif mode == "Prime Number Spiral":
num_points = st.slider("Number of Points", 10, 1000, 200)
fig = generate_prime_number_spiral(num_points)
elif mode == "Emoji Dynamics and Number Theory Simulation":
size = st.slider("Grid Size", 5, 20, 10)
simulation = emoji_dynamics_and_number_theory_simulation(size)
st.text(simulation)
else:
st.text("Select a visualization mode to display.")

if 'fig' in locals():
st.pyplot(fig)
Then within my second program which I want combined with the program above keeping all features have this move north south east west interface to change to parameterize the inputs for the emoji numeric tilemap of emojis that look like terrain and landscape. Feel free to expand too the list of emojis to use each one that ccan represent a land element building elemment, wall, or it that is human sized as inventory. There should be about 30 different emojis in the landscape generator. Use the max too from number simulation for the x and y size of number of emojis in the terrain tilemap: Actually change the code so the slider can show variable number from 5 to 40 with default slidder at forty.. import streamlit as st
import random
import numpy as np

Initialize or reset the game state with all features

def initialize_state():
st.session_state.update({
'character': None,
'knowledge': 0,
'inventory': [],
'map_position': (2, 2), # Center position in a 5x5 grid
'current_location': 'forest edge',
'initialized': True
})

if 'initialized' not in st.session_state:
initialize_state()

Characters and descriptions

characters = {
"Wizard": {"emoji": "πŸ§™β€β™‚οΈ", "knowledge": 5, "description": "Wise and powerful, connected to magical forces."},
"Witch": {"emoji": "πŸ§™β€β™€οΈ", "knowledge": 5, "description": "Cunning, skilled in potions and spells."}
}

Locations and emoji grid maps

locations = {
'forest edge': np.array([["🌲", "🌳", "πŸƒ", "🌲", "🌿"], ["πŸ„", "πŸƒ", "🌳", "πŸƒ", "πŸ„"], ["🌲", "🚢", "🌿", "πŸƒ", "🌳"], ["🌳", "πŸƒ", "πŸ„", "🌿", "🌲"], ["🌲", "πŸƒ", "🌳", "πŸƒ", "🌿"]]),
'deep forest': np.array([["🌲", "🌿", "πŸƒ", "🌳", "πŸ„"], ["🌿", "🌳", "πŸƒ", "🌲", "🌿"], ["πŸ„", "πŸƒ", "🚢", "πŸƒ", "🌳"], ["🌳", "🌲", "πŸƒ", "πŸ„", "🌿"], ["πŸƒ", "πŸƒ", "🌳", "🌲", "🌿"]]),
# Add other locations with corresponding maps
}

Actions and movement

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

Main Streamlit application

def main():
st.title("The Magic Workshop In The Great Tree 🌳✨")
if st.session_state.character is None:
choose_character()
else:
display_character_info()
navigate_world()

def choose_character():
st.header("Choose your character πŸ§™β€β™‚οΈπŸ§™β€β™€οΈ")
character = st.selectbox("Select your character", options=list(characters.keys()), format_func=lambda x: f"{x} {characters[x]['emoji']}")
if st.button("Choose"):
st.session_state.character = characters[character]
st.experimental_rerun()

def display_character_info():
char = st.session_state.character
st.subheader(f"Character: {char['description']}")
st.write(f"Knowledge: {char['knowledge']}")
if st.session_state.inventory:
st.write(f"Inventory: {', '.join(st.session_state.inventory)}")
else:
st.write("Inventory: Empty")

def navigate_world():
st.header("Explore the World")
location = st.session_state.current_location
st.write(f"You are in the {location}.")
display_map(location)
move_direction = st.selectbox("Which direction would you like to go?", options=list(directions.keys()))
if st.button("Move"):
move_player(move_direction)
handle_location_change()

def display_map(location):
map_with_player = locations[location]
map_display = "\n".join(["".join(row) for row in map_with_player])
st.text(map_display)

def move_player(direction):
dx, dy = directions[direction]
x, y = st.session_state.map_position
nx, ny = x + dx, y + dy
if 0 <= nx < 5 and 0 <= ny < 5: # Ensure new position is within bounds
# Update map position
st.session_state.map_position = (nx, ny)
# Update the character's position on the map
update_map_position(st.session_state.current_location, st.session_state.map_position)

def update_map_position(location, new_position):
# Remove old position
locations[location][st.session_state.map_position] = "πŸƒ" # Replace with default terrain
# Set new position
st.session_state.map_position = new_position
locations[location][new_position] = "🚢"

def handle_location_change():
# This function can be expanded to include logic for handling encounters, finding items, etc., based on the new location
pass

if name == "main":
main()
:

Owner

If you give Modern LLMS two different things to do they forget one of them and go for the gusto on the last you asked for (not terrible but you can then correct it! just think of it as AI QA).. You forgot to include the code I gave you: "Emoji Dynamics and Number Theory Simulation":
size = st.slider("Grid Size", 5, 20, 10)
simulation = emoji_dynamics_and_number_theory_simulation(size)
st.text(simulation) and this leads into these two visualizations. make both happen with the emojis.. just like in the code but make them bigger from 5 to 40 on the slider.
def generate_prime_number_spiral(num_points):
"""Generate spiral layout highlighting prime numbers."""
fig, ax = plt.subplots(figsize=(6, 6))
ax.axis('off')
radius = 0.05
for i in range(1, num_points + 1):
if is_prime(i):
angle = i * 2 * np.pi / golden_ratio
distance = np.sqrt(i) * radius
x = 0.5 + distance * np.cos(angle)
y = 0.5 + distance * np.sin(angle)
color = color_wheel(i / num_points)
circle = plt.Circle((x, y), radius, color=color, fill=True, alpha=0.8)
ax.add_artist(circle)
ax.set_aspect('equal')
return fig

def emoji_dynamics_and_number_theory_simulation(size):
"""Simulate emoji dynamics based on number theory."""
fib_seq = fib_sequence(size**2)
grid = []

for i in range(1, size**2 + 1):
    if i in fib_seq:
        grid.append("πŸŒ€")  # Fibonacci positions
    elif is_prime(i):
        grid.append("🌟")  # Prime positions
    else:
        grid.append("βšͺ")  # Other positions

    if i % size == 0:
        grid.append("\n")  # Newline at the end of each row

return "".join(grid)
Owner

Another: Ok add these into the mix, you forgot to use the 30 emoji library I asked for which represents landmarks, terrain, buildings, grasslands, plains etc and also inventories, add it with something like this! # Locations and emoji grid maps
locations = {
'forest edge': np.array([["🌲", "🌳", "πŸƒ", "🌲", "🌿"], ["πŸ„", "πŸƒ", "🌳", "πŸƒ", "πŸ„"], ["🌲", "🚢", "🌿", "πŸƒ", "🌳"], ["🌳", "πŸƒ", "πŸ„", "🌿", "🌲"], ["🌲", "πŸƒ", "🌳", "πŸƒ", "🌿"]]),
'deep forest': np.array([["🌲", "🌿", "πŸƒ", "🌳", "πŸ„"], ["🌿", "🌳", "πŸƒ", "🌲", "🌿"], ["πŸ„", "πŸƒ", "🚢", "πŸƒ", "🌳"], ["🌳", "🌲", "πŸƒ", "πŸ„", "🌿"], ["πŸƒ", "πŸƒ", "🌳", "🌲", "🌿"]]),
# Add other locations with corresponding maps
}

Actions and movement

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

Main Streamlit application

def main():
st.title("The Magic Workshop In The Great Tree 🌳✨")
if st.session_state.character is None:
choose_character()
else:
display_character_info()
navigate_world()

Owner

Can you Use WASD directional logic in streamlit? Maybe with a hot key or labeled input that everytime you click it as a button or type it as a WASD letter into a streamlit input it moves.

Owner

Revised to this.. Change the land border types and have them use randomness and stagger them together since edges scroll. maybe put like emojis closer together? Then please find a way to change the speed adding maybe a delay slider that way the user doesnt get motion sickness. Also add more emojis that are landscape or sea or anything that looks like a ground terrain type like hills mountains etc. Change also the keyboard interface you wrote. Don't loose any good code. Here is a reminder of the full code listing. Reply back to me with only the modified full code listing not omitting any bit of code. import streamlit as st
import numpy as np

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 = ["🌲", "🌳", "πŸƒ", "🌲", "🌿", "πŸ„", "🏠", "🏰", "πŸ—Ό", "πŸ›€οΈ", "🌊", "🏞️", "🌁", "🌾", "🏜️", "🏝️", "πŸ›–", "πŸ›€οΈ", "πŸ›£οΈ", "πŸ•οΈ", "πŸŒ‹", "⛰️", "🧱", "🌡", "🍁", "🌼", "🌻", "🌺", "🏑", "πŸ—ΊοΈ"]

Locations and emoji grid maps initialization

def initialize_locations(size):
"""Initialize different locations with unique emoji grids."""
# Placeholder for location initialization logic
# Randomly fill grids with emojis from emoji_set for each location
np.random.seed(42) # Optional: for reproducible emoji distributions
locations = {
'forest edge': np.random.choice(emoji_set, (size, size)),
'deep forest': np.random.choice(emoji_set, (size, size)),
# Additional locations can be added here
}
return locations

Directions for movement

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

Movement and emoji map update functions

def move_emojis(locations, current_location, direction):
"""Shift emojis in the specified direction with wrap-around for the current location."""
dx, dy = directions[direction]
locations[current_location] = np.roll(locations[current_location], shift=(dx, dy), axis=(0, 1))
return locations

Streamlit application setup

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

size = st.sidebar.slider("Grid Size", 5, 40, 10)
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)
    st.experimental_rerun()

if name == "main":
main()

Sign up or log in to comment