Howdy, Stranger!

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

Supported by

Moving and fixed stimuli at the same canvas

Hi!
I'm trying to figure out how to show a short sequence with three small squares, where each square is moving at a time. So, when the first square is moving sideways, the other two should be fixed. Then the first square stops, and the second square starts to move sideways. The squares will also move at different speeds.
I know how to make a canvas move by using an inline script, but I don't know how to make the two fixed squares to be shown at the same time. Does anyone know how to solve this?

Thanks!

Comments

  • Hi Charlotte,

    This is a little tricky, but not impossible. At any rate, you would need to use inline_scripting. The general idea would be something like this:

    • draw two squares that are fixed on a canvas
    • in a loop the following steps:
      • copy this canvas to a second canvas
      • in a loop draw the third stimulus on the second canvas,
      • clear that canvas
      • update x and y

    then repeat this procedure with the two other squares.

    This script should give you a good starting point. Let me know if you need more help.

    Eduard

    cv = canvas()
    cv1 = canvas()
    cv2 = canvas()
    kb= keyboard()
    
    # starting position
    x1,y1 = -100,-100
    x2,y2 = 400,300
    x3,y3 = 200,-300
    points = [[x1,y1],[x2,y2],[x3,y3]]
    
    # initial screen
    for x,y in points:
        cv.rect(x,y,50,50)
    cv.show()
    kb.get_key()
    
    # prepare first moving square
    for x,y in points[:2]:
        cv1.rect(x,y,50,50)
    
    # set a speed (sort of, this requires testing)
    speed = 3
    # let first square move
    for i in range(20):# range represents the distance that is covered on the screen
        cv2.copy(cv1)
        x3,y3 = x3-speed*i,y3+speed*i
        cv2.rect(x3,y3,50,50)
        cv2.show()
        cv2.clear()
    kb.get_key()
    
    cv1.clear()
    points = [[x1,y1],[x2,y2],[x3,y3]]
    # prepare 2nd moving square
    for x,y in points[1:]:
        cv1.rect(x,y,50,50)
    
    # let second square move
    # set a speed (sort of, this requires testing)
    speed = 2
    for i in range(20):# range represents the distance that is covered on the screen
        cv2.copy(cv1)
        x1,y1 = x1+speed*i,y1+speed*i
        cv2.rect(x1,y1,50,50)
        cv2.show()
        cv2.clear()
    kb.get_key()
    
    # prepare 3nd moving square
    cv1.clear()
    points = [[x1,y1],[x2,y2],[x3,y3]]
    for x,y in [[x1,y1],[x3,y3]]:
        cv1.rect(x,y,50,50)
    
    # set a speed (sort of, this requires testing)
    speed = 4
    # let third square move
    for i in range(20): # range represents the distance that is covered on the screen
        cv2.copy(cv1)
        x2,y2 = x2-speed *i,y2-speed*i
        cv2.rect(x2,y2,50,50)
        cv2.show()
        cv2.clear()
    kb.get_key()
    

    Buy Me A Coffee

Sign In or Register to comment.