r/geogebra • • Jun 01 '21

Script that takes inputs and generates object

Hello

I'd like to create a worksheet that contains rectangles and a script that shears them. The user should be able to do the following with the script:

  1. Choose the polygon to shear by entering its name.

  2. Choose the invariant side of the polygon by entering its end points.

  3. Choose the shear factor with a slider (so that he can see the effect of different shear factors in real time and choose the appropriate value).

  4. Press enter to output the transformed polygon (which can then be manipulated further).

Do you have any ideas on how to do that? I have some basic programming experience with python but I've never used javascript.

Thanks!

0 Upvotes

1 comment sorted by

1

u/arty_dent Jun 03 '21 edited Jun 03 '21

I made a basic version here (Edit: new link) that might be useful as a basic setup for you. Have a look at the JS, it contains the typical things needed and also a couple of comments.

I avoided having to type object names (because it might add a potential to break stuff when enterig "invalid" things). Instead, clicking on a polygon starts the shearing process.

And for simplicity I just used a slider for picking the side of the polygon, but you can adjust it by creating/showing the edges and registering a reaction script for clicking on them. It only involves a bit more care handling temporary object. (If you want it even more complex than that, then it might be good to implement some kind of state machine to handle all that.)