Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

trail making test

Hi,

I am a new user of OpenSesame.

I am interested to implement the Trail Making Test in experiments (cf. sample picture, Instructions: "There are numbers in circles on this page. Please take the pencil and draw a line from one number to the next, in order. Start at 1 [point to the number], then go to 2 [point], then go to 3 [point], and so on. Please try not to lift the pen as you move from one number to the next. Work asquickly and accurately as you can.").


Is it possible to draw a line produced by user in real time?

How can I do this?

Thanks a lot for your help.

Comments

  • Hi Lucie,

    Yes, that's possible, and not even that complicated. But how would the user draw the line, though? With a finger on a touch screen? Or with a Wacom-like tablet? Or with the mouse?

    Cheers!

    Sebastiaan

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

  • Hi Sebastiaan,

    The user will draw the line with the mouse or with a finger on a touch screen.

    Thank you for your answer.

    Lucie

  • Hi Lucie,

    In that case, something like the logic below should do the trick. You may need to tweak the details though. But if you carefully read through the code, then you will probably be able to understand how it works and modify it for your purpose.

    Cheers!

    Sebastiaan

    MIN_DIST = 50
    
    # A sketchpad to draw onto
    my_canvas = items['my_sketchpad'].canvas
    my_keyboard = Keyboard(timeout=10)
    my_mouse = Mouse()
    my_mouse.show_cursor(True)
    
    vertices = []
    while True:
    	# Wait until a key has been pressed
    	key, timestamp = my_keyboard.get_key()
    	if key is not None:
    		break
    	if not any(my_mouse.get_pressed()):
    		continue
    	# Get the current cursor position
    	(x, y), timestamp = my_mouse.get_pos()
    	if vertices:
    		# Get the distance to the last stored point and skip
    		# if this too nearby so that we don't collect too
    		# many points
    		px, py = vertices[-1]
    		d = ((x - px) ** 2 + (y - py) ** 2) ** .5
    		if d < MIN_DIST:
    			continue
    		# Update the canvas, but only when there are at least two points
    		if len(vertices) >= 2:
    			my_canvas += Line(px, py, x, y)			
    	# Store the current mouse position
    	vertices.append((x, y))
    	my_canvas.show()
    # Assign vertices to experimental variable so that they are logged
    var.vertices = vertices
    

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

  • Hi Sebastiaan,

    Thank you so much.

    I look and contact you again if necessary.

    When it is done, the implemented test can be shared by example experiments?

    Best,

    Lucie

  • > When it is done, the implemented test can be shared by example experiments?

    That's very generous! 👍️

    There's no systematic system for sharing experiments. However, you could upload it to the OSF in a public project. That's what I usually do.

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

Sign In or Register to comment.