Re-drawing a line updating its orientation as mouse movement

Hi Meg,

I’m not very familiar with the draw component in the builder, but i think that what you want to achive can still be done in the builder with a little bit of coding.

My solution would be:

  • Create a “line” (a very tall and narrow rectangle)
  • Create a point (a very small circle) at the centre of the screen and of the line, the same color of the line so it is invisible
  • Set the orientation of the line as a variable to be updated every frame (e.g. $myOri)
  • Create a code component and place it at the top of the list of componets
  • In the “begin routine” tab set the orientation (myOri) you want the line to be at the beginning (like vertical, orizontal or even random)
  • In the “every frame” tab calculate the position of the mouse with mouse.getPos() when the mouse is clicked
  • With a little bit of geometry calculate the orientation the line should have to connect the mouse and the point in the middle and set myOri accordingly
  • Finally, you can have the routine end when a keyboard button is pressed and have the final myOri saved with thisExp.addData()

tandy

1 Like