File size: 786 Bytes
8dde35a
da39594
 
8dde35a
d92a1e7
8dde35a
da39594
 
 
 
 
 
 
 
 
 
 
8dde35a
daec03b
da39594
 
 
 
 
 
 
 
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
import streamlit as st
import numpy as np
import plotly.graph_objects as go

st.title('Hexagon-Dice-Fractal-Math-Game')

def generate_fractal(num_rolls):
    rolls = [np.random.randint(1, 7) for i in range(num_rolls)]
    x = [0]
    y = [0]
    angle = 0
    step = 1
    for roll in rolls:
        angle += 60 if roll % 2 == 0 else -60
        x.append(x[-1] + step * np.cos(np.deg2rad(angle)))
        y.append(y[-1] + step * np.sin(np.deg2rad(angle)))
    return go.Scatter(x=x, y=y, mode='lines', line=dict(width=1))

num_rolls = st.slider('How many times do you want to roll the dice?', 1, 1000000,1000)
fig = go.Figure(generate_fractal(num_rolls))
fig.update_layout(
    title='Dice Fractal',
    xaxis_title='X',
    yaxis_title='Y',
    showlegend=False
)
st.plotly_chart(fig)