I made interactive program with colliding blocks. The condition of collision is y<=x, where y & x are coordinates of two blocks along straight line of their motion. I could use the condition y<=x in Manipulate. But I couldn’t use the condition y<=x in version with DynamicModule. I have read Help chapters about dynamics and know that dynamic variables are objects in front end. I tried different methods to convert they to numbers to use in operator If[y<=x,“collision”,“separate”] but in vain.
I give simplified part of the program relative to collision
-
Manipulate
Manipulate[ Module[{l0 = 500, h = 30, d = 30, x0 = 100, y0 = 400, v = 1, u = -2}, x = x0 + v*t; y = y0 + u*t; Column[{Graphics[{Rectangle[{0, -10}, {l0, 0}], Green, Rectangle[{x - d, -0}, {x, h}], Blue, Rectangle[{y, 0}, {y + d, h}]}], {y < x, " ", If[y <= x, "Collision", "Separated"]}}]], {t, 0, 200, 1, Appearance -> "Labeled"} ] -
DynamicModule
DynamicModule[{l0 = 500, h = 30, d = 30, x0 = 100, y0 = 400, v = 1, u = -2}, x = Dynamic[x0 + v*t]; y = Dynamic[y0 + u*t]; Panel[Column[{Graphics[{Rectangle[{0, -10}, {l0, 0}], Green, Rectangle[{x - d, -0}, {x, h}], Blue, Rectangle[{y, 0}, {y + d, h}]}], {Slider[Dynamic@t, {0, 200, 1}], Dynamic@t}, {y <= x, " ", Dynamic@If[y <= x, "Collision", "Separated"]}}]] ]
Best regards, Ivan Siahlo