Scripting of interactivity and animations - mkraska/meclib GitHub Wiki

Subtopic of Moving objects by scripts

Basic Elements of Meclib scripting

  • Create control points
  • Assign callbacks for dragging
  • Bind control points as sliders to lines or circles
  • Create animation sequences
  • Create groups for simultaneous movement of objects

Create control points

  • Create new points at the location of some object points and move the objects by callback of the control point
  • Convert an object point to a control point
    var st = objects[20];
    st.p1.setAttribute({fixed:false, visible:true, name:""})
    st.p2.setAttribute({fixed:false, visible:true, name:""})
    

Create animation sequences

  • moveTo() linear movements to a given position during a given time. Can be given a callback which is executed when the animation is finished. https://jsxgraph.org/docs/symbols/JXG.CoordsElement.html#moveTo

  • setTimeOut() delays the execution of commands wrapped in this function

  • moveAlong() moves along the points in a list during a given time. Example

    image

Make a point glide on objects

Create groups for simultaneous movement of objects

You can set a rotation center and a point or a set of them where the rotation can be controlled.

let g1 = board.create('group', [f1.p1, m1.p1, b1.p2, s1.p1]);
g1.setRotationCenter(f1.p1);
g1.setRotationPoints(m1.p1);