Browse Source

График скорости и сил

master
parent
commit
a1a122fe8a
  1. 77
      wave_simulate.html

77
wave_simulate.html

@ -36,7 +36,7 @@
</p>
<p>
<input type="checkbox" id="right_second" checked />
<input type="checkbox" id="right_second" />
<label for="right_second" alt="">Вторая половина справа - другая среда</label>
</p>
@ -45,6 +45,26 @@
<label for="generate" alt="">Генерирование волны слева</label>
</p>
<p>
<input type="checkbox" id="vel_graph_on" checked />
<label for="vel_graph_on" alt="">График скорости</label>
<input type="range" id="vel_graph_scale_range" for="omega" name="volume" min="0" max="10000" value="300"
oninput='document.getElementById("vel_graph_scale").value = document.getElementById("vel_graph_scale_range").value / 100;'>
<input id = "vel_graph_scale" type="number" value="3.0" step=".1"/>
<label for="vel_graph_scale" alt="">Маштаб</label>
</p>
<p>
<input type="checkbox" id="force_graph_on" checked />
<label for="force_graph_on" alt="">График сил</label>
<input type="range" id="force_graph_scale_range" for="omega" name="volume" min="0" max="10000" value="3000"
oninput='document.getElementById("force_graph_scale").value = document.getElementById("force_graph_scale_range").value / 100;'>
<input id = "force_graph_scale" type="number" value="30.0" step=".1"/>
<label for="force_graph_scale" alt="">Маштаб</label>
</p>
<p>
<input type="range" id="length_range" for="omega" name="volume" min="0" max="200" value="50"
oninput='document.getElementById("length").value = document.getElementById("length_range").value / 100;'>
@ -74,7 +94,7 @@
</p>
<p>
<input type="range" id="trenie_range" for="omega" name="volume" min="-0" max="1000" value="980"
<input type="range" id="trenie_range" for="omega" name="volume" min="0" max="1000" value="980"
oninput='document.getElementById("trenie").value = document.getElementById("trenie_range").value / 100;'>
<input id = "trenie" type="number" value="0.98" step=".01"/>
<label for="trenie" alt="">Трение</label>
@ -112,6 +132,14 @@ trenie = 0.0
acsel = 0.0
acsel_second = 0.0
vel_graph_on = False
vel_graph_scale = 0.0
force_graph_on = False
force_graph_scale = 0.0
y_scale = 0.3
y_values = []
vel_values = []
@ -142,6 +170,14 @@ def DrawAxesScreen():
DrawLine(x1, y1, x1, y2, lw, style)
DrawLine(x2, y1, x2, y2, lw, style)
style1 = 'blue'
base_y = ym - (ym - y1) * y_scale * 1
DrawLine(x1, base_y, x2, base_y, lw, style1)
base_y = ym - (ym - y1) * y_scale * (-1)
DrawLine(x1, base_y, x2, base_y, lw, style1)
def base_func(length, omega):
return math.sin(length * omega)
@ -157,6 +193,12 @@ def reload():
global acsel
global acsel_second
global vel_graph_on
global vel_graph_scale
global force_graph_on
global force_graph_scale
max_step = int(document["max_step"].value)
y_values = [0.0] * max_step
vel_values = [0.0] * max_step
@ -170,6 +212,11 @@ def reload():
acsel = float(document["acsel"].value)
acsel_second = float(document["acsel_second"].value)
vel_graph_on = document["vel_graph_on"].checked
vel_graph_scale = float(document["vel_graph_scale"].value)
force_graph_on = document["force_graph_on"].checked
force_graph_scale = float(document["force_graph_scale"].value)
def recalculate():
global max_step
global y_values
@ -182,6 +229,12 @@ def recalculate():
global acsel
global acsel_second
global vel_graph_on
global vel_graph_scale
global force_graph_on
global force_graph_scale
global omega
DrawBlackScreen()
@ -195,8 +248,9 @@ def recalculate():
y2 = canvas.height - y1
ym = canvas.height/2
style = 'white'
style_vel = 'green'
style_force = 'red'
line_width_scale = 4.0
y_scale = 0.3
cur_x = 0
prev_x = cur_x
@ -210,11 +264,13 @@ def recalculate():
y_values[i] = base_func(length, omega)
vel_values[i] = 0.0
else:
force = 0.0
if i != max_step - 1:
ac = acsel
if right_second and i > max_step / 2:
ac = acsel_second
vel_values[i] += (y_values[i - 1] - y_values[i]) * ac + (y_values[i + 1] - y_values[i]) * ac
force = (y_values[i - 1] - y_values[i]) * ac + (y_values[i + 1] - y_values[i]) * ac
vel_values[i] += force
vel_values[i] *= trenie
y_values[i] += vel_values[i]
base_y = ym - (ym - y1) * y_scale * y_values[i]
@ -222,6 +278,19 @@ def recalculate():
DrawLine(prev_x, base_y_last, cur_x, base_y, 1.0 * line_width_scale, style)
if vel_graph_on:
base_y = ym - (ym - y1) * vel_graph_scale * vel_values[i]
base_y_last = ym - (ym - y1) * vel_graph_scale * vel_values[i - 1]
DrawLine(prev_x, base_y_last, cur_x, base_y, 1.0, style_vel)
if force_graph_on:
base_y = ym - (ym - y1) * force_graph_scale * force
base_y_last = ym - (ym - y1) * force_graph_scale * force
DrawLine(prev_x, base_y_last, cur_x, base_y, 1.0, style_force)
prev_x = cur_x
def recalculate_event():

Loading…
Cancel
Save