Trial /draw only when mouse held down


Author
Message
JoeMunro
JoeMunro
New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)
Group: Forum Members
Posts: 2, Visits: 15
Hi,

I am looking to draw to the screen, which I can do with the draw attribute of the trial,
But is there a way to only draw when the mosue is held down? So don't draw, hold down mouse to draw, mouse up don't draw.
This is my current code to draw:

<trial draw>
/ stimulusframes = [1 = imagesBW]
/ inputdevice = keyboard
/ validresponse = (" ")
/ draw = brush
/ screencapture = true
</trial>

Any help or if it's not possible would be great.
Joe
Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 13K, Visits: 105K
JoeMunro - 12/2/2022
Hi,

I am looking to draw to the screen, which I can do with the draw attribute of the trial,
But is there a way to only draw when the mosue is held down? So don't draw, hold down mouse to draw, mouse up don't draw.
This is my current code to draw:

<trial draw>
/ stimulusframes = [1 = imagesBW]
/ inputdevice = keyboard
/ validresponse = (" ")
/ draw = brush
/ screencapture = true
</trial>

Any help or if it's not possible would be great.
Joe

You would have to do something like this:

<block example>
/ trials = [1=start]
</block>

// waits for mouse button to be pressed
<trial start>
/ stimulusframes = [1=surface, example_stimulus]
/inputdevice = mouse
/showmousecursor = true
/validresponse = (lbuttondown)
/ branch = [
    return trial.draw;
]
/ recorddata = false
</trial>

// does the actual drawing and waits for mouse button to be lifted
<trial draw>
/ stimulusframes = [1=exitbutton]
/ inputdevice = mouse
/ draw = pencil
/ validresponse = (lbuttonup)
/ undodraw = [
    false;
]
/branch = [
    trial.pause;
]
/ recorddata = false
</trial>

// waits for mouse button to be pressed again to continue drawing or click on exit to end drawing
<trial pause>
/ stimulusframes = [1=exitbutton]
/inputdevice = mouse
/showmousecursor = true
/validresponse = (exitbutton, surface)
/ branch = [
    if (trial.pause.response != "exitbutton") {
        return trial.draw;
    } else {
        return trial.end;
    };
]
/ recorddata = false
</trial>

// takes a screen capture of the end result
<trial end>
/ trialduration = 20
/ screencapture = true
</trial>

<text example_stimulus>
/ items = ("Start drawing by pressing the left mouse button, pause by releasing the left mouse button.
When you are done drawing, click the exit button.")
/ erase = false
/ size = (80%, 80%)
/ txbgcolor = antiquewhite
</text>

<shape surface>
/ shape = rectangle
/ size = (100%, 100%)
/ erase = false
/ color = white
</shape>

<shape pencil>
/ shape = circle
/ color = black
/ size = (.5%, .5%)
/ erase = false
</shape>

<button exitbutton>
/ caption = "EXIT"
/ size = (5%, 4%)
/ position = (50%, 95%)
/ erase = false
</button>

JoeMunro
JoeMunro
New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)
Group: Forum Members
Posts: 2, Visits: 15
Dave - 12/2/2022
JoeMunro - 12/2/2022
Hi,

I am looking to draw to the screen, which I can do with the draw attribute of the trial,
But is there a way to only draw when the mosue is held down? So don't draw, hold down mouse to draw, mouse up don't draw.
This is my current code to draw:

<trial draw>
/ stimulusframes = [1 = imagesBW]
/ inputdevice = keyboard
/ validresponse = (" ")
/ draw = brush
/ screencapture = true
</trial>

Any help or if it's not possible would be great.
Joe

You would have to do something like this:

<block example>
/ trials = [1=start]
</block>

// waits for mouse button to be pressed
<trial start>
/ stimulusframes = [1=surface, example_stimulus]
/inputdevice = mouse
/showmousecursor = true
/validresponse = (lbuttondown)
/ branch = [
    return trial.draw;
]
/ recorddata = false
</trial>

// does the actual drawing and waits for mouse button to be lifted
<trial draw>
/ stimulusframes = [1=exitbutton]
/ inputdevice = mouse
/ draw = pencil
/ validresponse = (lbuttonup)
/ undodraw = [
    false;
]
/branch = [
    trial.pause;
]
/ recorddata = false
</trial>

// waits for mouse button to be pressed again to continue drawing or click on exit to end drawing
<trial pause>
/ stimulusframes = [1=exitbutton]
/inputdevice = mouse
/showmousecursor = true
/validresponse = (exitbutton, surface)
/ branch = [
    if (trial.pause.response != "exitbutton") {
        return trial.draw;
    } else {
        return trial.end;
    };
]
/ recorddata = false
</trial>

// takes a screen capture of the end result
<trial end>
/ trialduration = 20
/ screencapture = true
</trial>

<text example_stimulus>
/ items = ("Start drawing by pressing the left mouse button, pause by releasing the left mouse button.
When you are done drawing, click the exit button.")
/ erase = false
/ size = (80%, 80%)
/ txbgcolor = antiquewhite
</text>

<shape surface>
/ shape = rectangle
/ size = (100%, 100%)
/ erase = false
/ color = white
</shape>

<shape pencil>
/ shape = circle
/ color = black
/ size = (.5%, .5%)
/ erase = false
</shape>

<button exitbutton>
/ caption = "EXIT"
/ size = (5%, 4%)
/ position = (50%, 95%)
/ erase = false
</button>

Thank you very much for this help.
This solves it very well.
Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 13K, Visits: 105K
JoeMunro - 12/2/2022
Dave - 12/2/2022
JoeMunro - 12/2/2022
Hi,

I am looking to draw to the screen, which I can do with the draw attribute of the trial,
But is there a way to only draw when the mosue is held down? So don't draw, hold down mouse to draw, mouse up don't draw.
This is my current code to draw:

<trial draw>
/ stimulusframes = [1 = imagesBW]
/ inputdevice = keyboard
/ validresponse = (" ")
/ draw = brush
/ screencapture = true
</trial>

Any help or if it's not possible would be great.
Joe

You would have to do something like this:

<block example>
/ trials = [1=start]
</block>

// waits for mouse button to be pressed
<trial start>
/ stimulusframes = [1=surface, example_stimulus]
/inputdevice = mouse
/showmousecursor = true
/validresponse = (lbuttondown)
/ branch = [
    return trial.draw;
]
/ recorddata = false
</trial>

// does the actual drawing and waits for mouse button to be lifted
<trial draw>
/ stimulusframes = [1=exitbutton]
/ inputdevice = mouse
/ draw = pencil
/ validresponse = (lbuttonup)
/ undodraw = [
    false;
]
/branch = [
    trial.pause;
]
/ recorddata = false
</trial>

// waits for mouse button to be pressed again to continue drawing or click on exit to end drawing
<trial pause>
/ stimulusframes = [1=exitbutton]
/inputdevice = mouse
/showmousecursor = true
/validresponse = (exitbutton, surface)
/ branch = [
    if (trial.pause.response != "exitbutton") {
        return trial.draw;
    } else {
        return trial.end;
    };
]
/ recorddata = false
</trial>

// takes a screen capture of the end result
<trial end>
/ trialduration = 20
/ screencapture = true
</trial>

<text example_stimulus>
/ items = ("Start drawing by pressing the left mouse button, pause by releasing the left mouse button.
When you are done drawing, click the exit button.")
/ erase = false
/ size = (80%, 80%)
/ txbgcolor = antiquewhite
</text>

<shape surface>
/ shape = rectangle
/ size = (100%, 100%)
/ erase = false
/ color = white
</shape>

<shape pencil>
/ shape = circle
/ color = black
/ size = (.5%, .5%)
/ erase = false
</shape>

<button exitbutton>
/ caption = "EXIT"
/ size = (5%, 4%)
/ position = (50%, 95%)
/ erase = false
</button>

Thank you very much for this help.
This solves it very well.

One addition: There is a little snag in that trial.pause will theoretically also accept a click with the right mouse button on either the exit button or the drawing surface. It's probably unlikely for anyone to actually do that, but if you want to avoid that possibility, we can instead define lbuttondown as the only allowable response in trial.pause and perform a point-in-rectangle test to check whether the left click occurred on the exit button or not:

<defaults>
/ canvasaspectratio = (4,3)
</defaults>

<block example>
/ trials = [1=start]
</block>

// waits for mouse button to be pressed
<trial start>
/ stimulusframes = [1=example_stimulus]
/inputdevice = mouse
/showmousecursor = true
/validresponse = (lbuttondown)
/ branch = [
    return trial.draw;
]
/ recorddata = false
</trial>

// does the actual drawing and waits for mouse button to be lifted
<trial draw>
/ stimulusframes = [1=exitbutton]
/ inputdevice = mouse
/ draw = pencil
/ validresponse = (lbuttonup)
/ undodraw = [
    false;
]
/branch = [
    trial.pause;
]
/ recorddata = false
</trial>

// waits for mouse button to be pressed again to continue drawing or click on exit to end drawing
<trial pause>
/ stimulusframes = [1=exitbutton]
/inputdevice = mouse
/showmousecursor = true
/ validresponse = (lbuttondown)
/ branch = [
    // check if we clicked the exit button or not
    if (mouse.x >= (button.exitbutton.xpx - button.exitbutton.widthpx/2) && mouse.x <= (button.exitbutton.xpx + button.exitbutton.widthpx/2) && mouse.y >= (button.exitbutton.ypx - button.exitbutton.heightpx/2) && mouse.y <= (button.exitbutton.ypx + button.exitbutton.heightpx/2)) {
        return trial.end;
    } else {
        return trial.draw;
    };
]
/ recorddata = false
</trial>

// takes a screen capture of the end result
<trial end>
/ trialduration = 20
/ screencapture = true
</trial>

<text example_stimulus>
/ items = ("Start drawing by pressing the left mouse button, pause by releasing the left mouse button.
When you are done drawing, click the exit button.")
/ erase = false
/ size = (80%, 80%)
/ txbgcolor = antiquewhite
</text>

<shape surface>
/ shape = rectangle
/ size = (100%, 100%)
/ erase = false
/ color = white
</shape>

<shape pencil>
/ shape = circle
/ color = black
/ size = (.5%, .5%)
/ erase = false
</shape>

<button exitbutton>
/ caption = "EXIT"
/ size = (5%, 4%)
/ position = (50%, 95%)
/ erase = false
</button>

Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 13K, Visits: 105K
Dave - 12/2/2022
JoeMunro - 12/2/2022
Dave - 12/2/2022
JoeMunro - 12/2/2022
Hi,

I am looking to draw to the screen, which I can do with the draw attribute of the trial,
But is there a way to only draw when the mosue is held down? So don't draw, hold down mouse to draw, mouse up don't draw.
This is my current code to draw:

<trial draw>
/ stimulusframes = [1 = imagesBW]
/ inputdevice = keyboard
/ validresponse = (" ")
/ draw = brush
/ screencapture = true
</trial>

Any help or if it's not possible would be great.
Joe

You would have to do something like this:

<block example>
/ trials = [1=start]
</block>

// waits for mouse button to be pressed
<trial start>
/ stimulusframes = [1=surface, example_stimulus]
/inputdevice = mouse
/showmousecursor = true
/validresponse = (lbuttondown)
/ branch = [
    return trial.draw;
]
/ recorddata = false
</trial>

// does the actual drawing and waits for mouse button to be lifted
<trial draw>
/ stimulusframes = [1=exitbutton]
/ inputdevice = mouse
/ draw = pencil
/ validresponse = (lbuttonup)
/ undodraw = [
    false;
]
/branch = [
    trial.pause;
]
/ recorddata = false
</trial>

// waits for mouse button to be pressed again to continue drawing or click on exit to end drawing
<trial pause>
/ stimulusframes = [1=exitbutton]
/inputdevice = mouse
/showmousecursor = true
/validresponse = (exitbutton, surface)
/ branch = [
    if (trial.pause.response != "exitbutton") {
        return trial.draw;
    } else {
        return trial.end;
    };
]
/ recorddata = false
</trial>

// takes a screen capture of the end result
<trial end>
/ trialduration = 20
/ screencapture = true
</trial>

<text example_stimulus>
/ items = ("Start drawing by pressing the left mouse button, pause by releasing the left mouse button.
When you are done drawing, click the exit button.")
/ erase = false
/ size = (80%, 80%)
/ txbgcolor = antiquewhite
</text>

<shape surface>
/ shape = rectangle
/ size = (100%, 100%)
/ erase = false
/ color = white
</shape>

<shape pencil>
/ shape = circle
/ color = black
/ size = (.5%, .5%)
/ erase = false
</shape>

<button exitbutton>
/ caption = "EXIT"
/ size = (5%, 4%)
/ position = (50%, 95%)
/ erase = false
</button>

Thank you very much for this help.
This solves it very well.

One addition: There is a little snag in that trial.pause will theoretically also accept a click with the right mouse button on either the exit button or the drawing surface. It's probably unlikely for anyone to actually do that, but if you want to avoid that possibility, we can instead define lbuttondown as the only allowable response in trial.pause and perform a point-in-rectangle test to check whether the left click occurred on the exit button or not:

<defaults>
/ canvasaspectratio = (4,3)
</defaults>

<block example>
/ trials = [1=start]
</block>

// waits for mouse button to be pressed
<trial start>
/ stimulusframes = [1=example_stimulus]
/inputdevice = mouse
/showmousecursor = true
/validresponse = (lbuttondown)
/ branch = [
    return trial.draw;
]
/ recorddata = false
</trial>

// does the actual drawing and waits for mouse button to be lifted
<trial draw>
/ stimulusframes = [1=exitbutton]
/ inputdevice = mouse
/ draw = pencil
/ validresponse = (lbuttonup)
/ undodraw = [
    false;
]
/branch = [
    trial.pause;
]
/ recorddata = false
</trial>

// waits for mouse button to be pressed again to continue drawing or click on exit to end drawing
<trial pause>
/ stimulusframes = [1=exitbutton]
/inputdevice = mouse
/showmousecursor = true
/ validresponse = (lbuttondown)
/ branch = [
    // check if we clicked the exit button or not
    if (mouse.x >= (button.exitbutton.xpx - button.exitbutton.widthpx/2) && mouse.x <= (button.exitbutton.xpx + button.exitbutton.widthpx/2) && mouse.y >= (button.exitbutton.ypx - button.exitbutton.heightpx/2) && mouse.y <= (button.exitbutton.ypx + button.exitbutton.heightpx/2)) {
        return trial.end;
    } else {
        return trial.draw;
    };
]
/ recorddata = false
</trial>

// takes a screen capture of the end result
<trial end>
/ trialduration = 20
/ screencapture = true
</trial>

<text example_stimulus>
/ items = ("Start drawing by pressing the left mouse button, pause by releasing the left mouse button.
When you are done drawing, click the exit button.")
/ erase = false
/ size = (80%, 80%)
/ txbgcolor = antiquewhite
</text>

<shape surface>
/ shape = rectangle
/ size = (100%, 100%)
/ erase = false
/ color = white
</shape>

<shape pencil>
/ shape = circle
/ color = black
/ size = (.5%, .5%)
/ erase = false
</shape>

<button exitbutton>
/ caption = "EXIT"
/ size = (5%, 4%)
/ position = (50%, 95%)
/ erase = false
</button>

Oh, and by the way, if you're looking for a more fleshed-out example, the Rey Visual Design test available in the library

https://www.millisecond.com/download/library/reyvisualdesignlearningtest

employs many of the same techniques.

Edited 3 Years Ago by Dave
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Explore
Messages
Mentions
Search