diff --git a/wave_simulate.html b/wave_simulate.html index bc35a1c..493d7a9 100755 --- a/wave_simulate.html +++ b/wave_simulate.html @@ -36,7 +36,7 @@
- +
@@ -45,6 +45,26 @@ + ++ + + + + +
+ ++ + + + + +
+ +@@ -74,7 +94,7 @@
- @@ -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) @@ -156,6 +192,12 @@ def reload(): global trenie 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 @@ -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,17 +264,32 @@ 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] base_y_last = ym - (ym - y1) * y_scale * y_values[i - 1] 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