Skip to content

Scripting of interactivity and animations

mkraska edited this page Dec 8, 2023 · 10 revisions

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);

Tryout Space

In order to try code snippets in jsfiddle,

  1. copy the code from the wiki page to the clipboard
  2. follow the link for the JSXGraph version you want to try
  3. Replace the code in the HTML section (contents of <p hidden id="init">) with the content of the clipboard
Clone this wiki locally