O/⚪ᕤᕦ⚪ИN⚪ꖴ⚪ᙏ⚪ᗩ⚪ᴥ⚪ᕤᕦ⚪Ⓞ⚪ᴥ⚪ߦ⚪◌⚪◌.../⚪ИN⚪Ⓞ⚪옷⚪✤⚪人⚪ߦ⚪◌⚪◌⚪◌⚪◌⚪◌⚪◌⚪ߦ.../⚪ᴥ⚪ᗱᗴ⚪✤⚪人⚪ߦ⚪ᑎ⚪ᒍᒐ⚪◌⚪◌⚪◌⚪◌⚪◌⚪.../YP..⚪ᴥ⚪ᗱᗴ⚪✤⚪Ⓞ⚪ᙁ⚪ߦ⚪◯⚪ᗱᗴ⚪ᗯ⚪ᴥ⚪...

137 lines
11 KiB
Python
Raw Blame History

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import numpy as np
import plotly.graph_objects as go
from math import *
import mpmath
from ipywidgets import interact, widgets, Text, Layout
from plotly.subplots import make_subplots
# Input field for formula
formula = widgets.Text(
value='(1-cos(((4)/2)*x))/2',
layout=widgets.Layout(width='100%'),
description='⚪ᗩ⚪ᙁ⚪ᑎ⚪ᙏ⚪ᴥ⚪Ⓞ⚪ꗳ⚪◌⚪◌⚪◌⚪◌⚪◌⚪◌⚪ꗳ⚪Ⓞ⚪ᴥ⚪ᙏ⚪ᑎ⚪ᙁ⚪ᗩ⚪'
)
RANGE_FROM_SLIDER = widgets.FloatSlider(
min=-4*(4*atan(1)),
max=4*(4*atan(1)),
value=-2*(4*atan(1)),
step=(4*atan(1))/4,
layout=widgets.Layout(width='100%'),
readout_format='.256f',
description='⚪ᙏ⚪Ⓞ⚪ᴥ⚪ꗳ⚪◯⚪ᗱᗴ⚪ᕤᕦ⚪ИN⚪ᗩ⚪ᴥ⚪◌⚪◌⚪◌⚪◌⚪◌⚪◌⚪ᴥ⚪ᗩ⚪ИN⚪ᕤᕦ⚪ᗱᗴ⚪◯⚪ꗳ⚪ᴥ⚪Ⓞ⚪ᙏ⚪'
)
RANGE_TO_SLIDER = widgets.FloatSlider(
min=-4*(4*atan(1)),
max=4*(4*atan(1)),
value=2*(4*atan(1)),
step=(4*atan(1))/4,
layout=widgets.Layout(width='100%'),
readout_format='.256f',
description='⚪Ⓞ⚪✤⚪◯⚪ᗱᗴ⚪ᕤᕦ⚪ИN⚪ᗩ⚪ᴥ⚪◌⚪◌⚪◌⚪◌⚪◌⚪◌⚪ᴥ⚪ᗩ⚪ИN⚪ᕤᕦ⚪ᗱᗴ⚪◯⚪✤⚪Ⓞ⚪'
)
N_slider = widgets.IntSlider(
min=1,
max=16,
value=8,
layout=widgets.Layout(width='100%'),
readout_format='.256f',
description='⚪ᴥ⚪ᗱᗴ⚪ᗯ⚪Ⓞ⚪ߦ⚪◯⚪ᴥ⚪ᗱᗴ⚪⚭⚪ᙏ⚪ᑎ⚪ИN⚪◯⚪✤⚪ИN⚪ꖴ⚪Ⓞ⚪ᑫ⚪◌⚪◌⚪◌⚪◌⚪◌⚪◌⚪ᑫ⚪Ⓞ⚪ꖴ⚪ИN⚪✤⚪◯⚪ИN⚪ᑎ⚪ᙏ⚪⚭⚪ᗱᗴ⚪ᴥ⚪◯⚪ߦ⚪Ⓞ⚪ᗯ⚪ᗱᗴ⚪ᴥ⚪'
)
O_REDILS_1_W_O_W_1_SLIDER_O = widgets.FloatSlider(
min=-2,
max=2,
value=1,
step=1/256,
layout=widgets.Layout(width='100%'),
readout_format='.256f',
description='⚪·⚪◯⚪ᗱᗴ⚪ᙁ⚪⚭⚪ᗩ⚪ꖴ⚪ᴥ⚪ᗩ⚪ᗯ⚪◌⚪◌⚪◌⚪◌⚪◌⚪◌⚪ᗯ⚪ᗩ⚪ᴥ⚪ꖴ⚪ᗩ⚪⚭⚪ᙁ⚪ᗱᗴ⚪◯⚪·⚪'
)
O_REDILS_2_W_O_W_2_SLIDER_O=widgets.FloatSlider(
min=-2,
max=2,
value=1,
step=1/256,
layout=widgets.Layout(width='100%'),
readout_format='.256f',
description='⚪꞉⚪◯⚪ᗱᗴ⚪ᙁ⚪⚭⚪ᗩ⚪ꖴ⚪ᴥ⚪ᗩ⚪ᗯ⚪◌⚪◌⚪◌⚪◌⚪◌⚪◌⚪ᗯ⚪ᗩ⚪ᴥ⚪ꖴ⚪ᗩ⚪⚭⚪ᙁ⚪ᗱᗴ⚪◯⚪꞉⚪'
)
def clamp(x):
return max(min(1, x), -1)
def compute(formula, x, variable1, variable2):
func_dict = {fn: eval(f'lambda *args:mpmath.{fn}(*args)') for fn in dir(mpmath)}
return float(eval(formula, {'x': x, 'O_1_W_O_W_1_O': variable1, 'O_2_W_O_W_2_O': variable2, 'clamp': clamp, **func_dict}))
def plot(formula='1.4795/O_2_W_O_W_2_O-((x)/(4*atan(1)*O_1_W_O_W_1_O/2*O_2_W_O_W_2_O))*1.4795', RANGE_FROM=0*(4*atan(1)), RANGE_TO=4*(4*atan(1)), N=8, O_1_W_O_W_1_O=1, O_2_W_O_W_2_O=1):
num_points = 1 + 2**N
x_vals = np.linspace(RANGE_FROM, RANGE_TO, num_points)
kappa_vals = np.array([compute(formula, x_val, O_1_W_O_W_1_O, O_2_W_O_W_2_O) for x_val in x_vals])
theta_vals = np.cumsum(kappa_vals) * (x_vals[1] - x_vals[0]) if num_points > 1 else np.array([0])
x_coords_ = np.cumsum(np.cos(theta_vals)) * (x_vals[1] - x_vals[0]) if num_points > 1 else np.array([0])
y_coords_ = np.cumsum(np.sin(theta_vals)) * (x_vals[1] - x_vals[0]) if num_points > 1 else np.array([0])
if x_coords_[0] != 0 or y_coords_[0] != 0:
x_coords = np.insert(x_coords_, 0, 0)
y_coords = np.insert(y_coords_, 0, 0)
else:
x_coords = x_coords_
y_coords = y_coords_
y_vals = [compute(formula, x_val, O_1_W_O_W_1_O, O_2_W_O_W_2_O) for x_val in x_vals]
# Determine maximum range for consistency across all charts
min_x_range = min(map(min, [x_coords, x_vals]))
min_y_range = min(map(min, [y_coords, y_vals]))
max_x_range = max(map(max, [x_coords, x_vals]))
max_y_range = max(map(max, [y_coords, y_vals]))
# Create and display the first plot
fig1 = go.Figure()
fig1.add_trace(go.Scatter(x=x_coords, y=y_coords, mode='lines', line=dict(color='#CECECE'), name='', hovertemplate='X:%{x:.256f}' + '<br>Y:%{y:.256f}'))
fig1.update_layout(
autosize=True,
margin=dict(
l=0, # left margin
r=0, # right margin
b=0, # bottom margin
t=0, # top margin
pad=0 # padding
),
height=512,
xaxis=dict(scaleanchor='y', scaleratio=1, gridcolor='#CECECE',zeroline=True, zerolinecolor='#CECECE', tickfont=dict(color='#9C9C9C',size=16)),
yaxis=dict(gridcolor='#CECECE',zeroline=True, zerolinecolor='#CECECE',tickfont=dict(color='#9C9C9C',size=16)),
hoverlabel=dict(bgcolor="#FFFFFF", font_color='#9C9C9C', bordercolor="#CECECE",font_size=16), plot_bgcolor='#FFFFFF'
)
fig1.update_xaxes(range=[min_x_range, max_x_range])
fig1.update_yaxes(range=[min_y_range, max_y_range])
fig1.show()
# Create and display the second plot
fig2 = go.Figure()
fig2.add_trace(go.Scatter(x=x_vals, y=y_vals, mode='lines', line=dict(color='#CECECE'), name='', hovertemplate='X:%{x:.256f}' + '<br>Y:%{y:.256f}'))
fig2.update_layout(
autosize=True,
margin=dict(
l=0, # left margin
r=0, # right margin
b=0, # bottom margin
t=0, # top margin
pad=0 # padding
),
height=512,
xaxis=dict(scaleanchor='y', scaleratio=1, gridcolor='#CECECE',zeroline=True,zerolinecolor='#CECECE',tickfont=dict(color='#9C9C9C',size=16)),
yaxis=dict(gridcolor='#CECECE',zeroline=True, zerolinecolor='#CECECE',tickfont=dict(color='#9C9C9C',size=16)),
hoverlabel=dict(bgcolor="#FFFFFF", font_color='#9C9C9C', bordercolor="#CECECE",font_size=16), plot_bgcolor='#FFFFFF'
)
fig2.update_xaxes(range=[min_x_range, max_x_range])
fig2.update_yaxes(range=[min_y_range, max_y_range])
fig2.show()
interact(plot,formula=formula,RANGE_FROM=RANGE_FROM_SLIDER,RANGE_TO=RANGE_TO_SLIDER,N=N_slider,O_1_W_O_W_1_O=O_REDILS_1_W_O_W_1_SLIDER_O,O_2_W_O_W_2_O=O_REDILS_2_W_O_W_2_SLIDER_O);