canvasaspectratio and picture coordinates


Author
Message
sharondan
sharondan
New Member (32 reputation)New Member (32 reputation)New Member (32 reputation)New Member (32 reputation)New Member (32 reputation)New Member (32 reputation)New Member (32 reputation)New Member (32 reputation)New Member (32 reputation)
Group: Forum Members
Posts: 12, Visits: 79
Hi,
I have a code that determines if a mouse click was on a picture and on which picture it was (there are 8 pictures).
This code works great when I do not make any change to the canvasaspectratio, however, when changing the canvasaspectratio to (4,3) it does not work (there is a shift between the mouse click and the picture position). Below please find an example of one picture.

<defaults>
/ canvasaspectratio = (4,3)  //if you comment this it works
/ canvassize = (100%, 100%)
</defaults>

<values>
/canvaswidth = display.canvaswidth //This does not received the change in canvasaspectratio and returns the display ratio
/canvasheight = display.canvasheight

/responseY = 9
/responseX = (canvasheight/canvaswidth) * (values.responseY)  //correcting this manualy to the changed ratio does not solve the problem.
</values>

<picture response1d>
/ items = ("response1disksR.png")
/ position = ( 50+values.responseX,50-values.responseY )
/ size = (15.8%,15.8%)
</picture>

<expressions 1_redL_4>
/ x11d = picture.response1d.left
/ y11d = picture.response1d.top
/ x12d = picture.response1d.right
/ y12d = picture.response1d.top
/ x13d = picture.response1d.left
/ y13d = picture.response1d.bottom
/ a1d = ((expressions.y12d - expressions.y13d)*(mouse.x - expressions.x13d) + (expressions.x13d - expressions.x12d)*(mouse.y - expressions.y13d)) / ((expressions.y12d - expressions.y13d)*(expressions.x11d - expressions.x13d)+(expressions.x13d - expressions.x12d)*(expressions.y11d - expressions.y13d))
/ b1d = ((expressions.y13d - expressions.y11d)*(mouse.x - expressions.x13d) + (expressions.x11d - expressions.x13d)*(mouse.y - expressions.y13d)) / ((expressions.y12d - expressions.y13d)*(expressions.x11d - expressions.x13d)+(expressions.x13d - expressions.x12d)*(expressions.y11d - expressions.y13d))
/ c1d = 1 - expressions.a1d - expressions.b1d
</expressions>

<expressions validresponse_disks>
/ validresponse_disks =
if (0<=expressions.a1d && expressions.a1d <= 1 && 0 <= expressions.b1d && expressions.b1d <= 1 && 0 <= expressions.c1d && expressions.c1d <= 1){
values.response = -1; true; values.p_confidence = 1;
}
</expressions>

<trial responsetrial>
/ stimulusframes = [ 1 = clearscreen;
   2 = response1d, response2d,response3d, response4d, response5d, response6d, response7d, response8d,
         qToAsk, circleInstruction, triangleInstruction, guess, sure, primaryOrSecondaryShapeMid, circleMid
]

/ ontrialbegin = [
values.response = "";
]
/ validresponse = (response_blank, response1d, response2d, response3d, response4d, response5d, response6d, response7d, response8d)
/ inputdevice = mouse
/ isvalidresponse = [
if (trial.responsetrial.response == "response_blank") false;
else expressions.validresponse_disks;
]

/ ontrialend = [
    values.response_time = trial.responsetrial.latency;            
]

</trial>

Dave
Dave
Supreme Being (855K reputation)Supreme Being (855K reputation)Supreme Being (855K reputation)Supreme Being (855K reputation)Supreme Being (855K reputation)Supreme Being (855K reputation)Supreme Being (855K reputation)Supreme Being (855K reputation)Supreme Being (855K reputation)
Group: Administrators
Posts: 10K, Visits: 59K
sharondan - 8/19/2020
Hi,
I have a code that determines if a mouse click was on a picture and on which picture it was (there are 8 pictures).
This code works great when I do not make any change to the canvasaspectratio, however, when changing the canvasaspectratio to (4,3) it does not work (there is a shift between the mouse click and the picture position). Below please find an example of one picture.

<defaults>
/ canvasaspectratio = (4,3)  //if you comment this it works
/ canvassize = (100%, 100%)
</defaults>

<values>
/canvaswidth = display.canvaswidth //This does not received the change in canvasaspectratio and returns the display ratio
/canvasheight = display.canvasheight

/responseY = 9
/responseX = (canvasheight/canvaswidth) * (values.responseY)  //correcting this manualy to the changed ratio does not solve the problem.
</values>

<picture response1d>
/ items = ("response1disksR.png")
/ position = ( 50+values.responseX,50-values.responseY )
/ size = (15.8%,15.8%)
</picture>

<expressions 1_redL_4>
/ x11d = picture.response1d.left
/ y11d = picture.response1d.top
/ x12d = picture.response1d.right
/ y12d = picture.response1d.top
/ x13d = picture.response1d.left
/ y13d = picture.response1d.bottom
/ a1d = ((expressions.y12d - expressions.y13d)*(mouse.x - expressions.x13d) + (expressions.x13d - expressions.x12d)*(mouse.y - expressions.y13d)) / ((expressions.y12d - expressions.y13d)*(expressions.x11d - expressions.x13d)+(expressions.x13d - expressions.x12d)*(expressions.y11d - expressions.y13d))
/ b1d = ((expressions.y13d - expressions.y11d)*(mouse.x - expressions.x13d) + (expressions.x11d - expressions.x13d)*(mouse.y - expressions.y13d)) / ((expressions.y12d - expressions.y13d)*(expressions.x11d - expressions.x13d)+(expressions.x13d - expressions.x12d)*(expressions.y11d - expressions.y13d))
/ c1d = 1 - expressions.a1d - expressions.b1d
</expressions>

<expressions validresponse_disks>
/ validresponse_disks =
if (0<=expressions.a1d && expressions.a1d <= 1 && 0 <= expressions.b1d && expressions.b1d <= 1 && 0 <= expressions.c1d && expressions.c1d <= 1){
values.response = -1; true; values.p_confidence = 1;
}
</expressions>

<trial responsetrial>
/ stimulusframes = [ 1 = clearscreen;
   2 = response1d, response2d,response3d, response4d, response5d, response6d, response7d, response8d,
         qToAsk, circleInstruction, triangleInstruction, guess, sure, primaryOrSecondaryShapeMid, circleMid
]

/ ontrialbegin = [
values.response = "";
]
/ validresponse = (response_blank, response1d, response2d, response3d, response4d, response5d, response6d, response7d, response8d)
/ inputdevice = mouse
/ isvalidresponse = [
if (trial.responsetrial.response == "response_blank") false;
else expressions.validresponse_disks;
]

/ ontrialend = [
    values.response_time = trial.responsetrial.latency;            
]

</trial>

The code is not particularly useful without the actual image file involved. Also, what exactly is the "shift"?

Please note that Inquisit will *not* distort an image's inherent aspect ratio (see e.g. https://www.millisecond.com/forums/Topic29219.aspx), i.e. whatever you set as the canvas aspect ratio will not affect the image's aspect ratio and any "shift" you're seeing is probably due to that single fact.

Dave
Dave
Supreme Being (855K reputation)Supreme Being (855K reputation)Supreme Being (855K reputation)Supreme Being (855K reputation)Supreme Being (855K reputation)Supreme Being (855K reputation)Supreme Being (855K reputation)Supreme Being (855K reputation)Supreme Being (855K reputation)
Group: Administrators
Posts: 10K, Visits: 59K
Dave - 8/19/2020
sharondan - 8/19/2020
Hi,
I have a code that determines if a mouse click was on a picture and on which picture it was (there are 8 pictures).
This code works great when I do not make any change to the canvasaspectratio, however, when changing the canvasaspectratio to (4,3) it does not work (there is a shift between the mouse click and the picture position). Below please find an example of one picture.

<defaults>
/ canvasaspectratio = (4,3)  //if you comment this it works
/ canvassize = (100%, 100%)
</defaults>

<values>
/canvaswidth = display.canvaswidth //This does not received the change in canvasaspectratio and returns the display ratio
/canvasheight = display.canvasheight

/responseY = 9
/responseX = (canvasheight/canvaswidth) * (values.responseY)  //correcting this manualy to the changed ratio does not solve the problem.
</values>

<picture response1d>
/ items = ("response1disksR.png")
/ position = ( 50+values.responseX,50-values.responseY )
/ size = (15.8%,15.8%)
</picture>

<expressions 1_redL_4>
/ x11d = picture.response1d.left
/ y11d = picture.response1d.top
/ x12d = picture.response1d.right
/ y12d = picture.response1d.top
/ x13d = picture.response1d.left
/ y13d = picture.response1d.bottom
/ a1d = ((expressions.y12d - expressions.y13d)*(mouse.x - expressions.x13d) + (expressions.x13d - expressions.x12d)*(mouse.y - expressions.y13d)) / ((expressions.y12d - expressions.y13d)*(expressions.x11d - expressions.x13d)+(expressions.x13d - expressions.x12d)*(expressions.y11d - expressions.y13d))
/ b1d = ((expressions.y13d - expressions.y11d)*(mouse.x - expressions.x13d) + (expressions.x11d - expressions.x13d)*(mouse.y - expressions.y13d)) / ((expressions.y12d - expressions.y13d)*(expressions.x11d - expressions.x13d)+(expressions.x13d - expressions.x12d)*(expressions.y11d - expressions.y13d))
/ c1d = 1 - expressions.a1d - expressions.b1d
</expressions>

<expressions validresponse_disks>
/ validresponse_disks =
if (0<=expressions.a1d && expressions.a1d <= 1 && 0 <= expressions.b1d && expressions.b1d <= 1 && 0 <= expressions.c1d && expressions.c1d <= 1){
values.response = -1; true; values.p_confidence = 1;
}
</expressions>

<trial responsetrial>
/ stimulusframes = [ 1 = clearscreen;
   2 = response1d, response2d,response3d, response4d, response5d, response6d, response7d, response8d,
         qToAsk, circleInstruction, triangleInstruction, guess, sure, primaryOrSecondaryShapeMid, circleMid
]

/ ontrialbegin = [
values.response = "";
]
/ validresponse = (response_blank, response1d, response2d, response3d, response4d, response5d, response6d, response7d, response8d)
/ inputdevice = mouse
/ isvalidresponse = [
if (trial.responsetrial.response == "response_blank") false;
else expressions.validresponse_disks;
]

/ ontrialend = [
    values.response_time = trial.responsetrial.latency;            
]

</trial>

The code is not particularly useful without the actual image file involved. Also, what exactly is the "shift"?

Please note that Inquisit will *not* distort an image's inherent aspect ratio (see e.g. https://www.millisecond.com/forums/Topic29219.aspx), i.e. whatever you set as the canvas aspect ratio will not affect the image's aspect ratio and any "shift" you're seeing is probably due to that single fact.

The code as posted also cannot be run, which isn't exactly ideal. It references various values and other elements that aren't present. That makes it hard to impossible to understand or replicate the problem you're referring to (or figuring out what it is in the first place). In addition to realistic and actually runnable code, plesae also be so kind and provide at least a short explanation of what that code is supposed to achieve eventually. None of that is particularly clear to me from the available information, e.g. why elaborate expressions are needed if the ultimate goal is only to determine whether a click on one of several objects occurred. Thank you!

sharondan
sharondan
New Member (32 reputation)New Member (32 reputation)New Member (32 reputation)New Member (32 reputation)New Member (32 reputation)New Member (32 reputation)New Member (32 reputation)New Member (32 reputation)New Member (32 reputation)
Group: Forum Members
Posts: 12, Visits: 79
Dave - 8/19/2020
sharondan - 8/19/2020
Hi,
I have a code that determines if a mouse click was on a picture and on which picture it was (there are 8 pictures).
This code works great when I do not make any change to the canvasaspectratio, however, when changing the canvasaspectratio to (4,3) it does not work (there is a shift between the mouse click and the picture position). Below please find an example of one picture.

<defaults>
/ canvasaspectratio = (4,3)  //if you comment this it works
/ canvassize = (100%, 100%)
</defaults>

<values>
/canvaswidth = display.canvaswidth //This does not received the change in canvasaspectratio and returns the display ratio
/canvasheight = display.canvasheight

/responseY = 9
/responseX = (canvasheight/canvaswidth) * (values.responseY)  //correcting this manualy to the changed ratio does not solve the problem.
</values>

<picture response1d>
/ items = ("response1disksR.png")
/ position = ( 50+values.responseX,50-values.responseY )
/ size = (15.8%,15.8%)
</picture>

<expressions 1_redL_4>
/ x11d = picture.response1d.left
/ y11d = picture.response1d.top
/ x12d = picture.response1d.right
/ y12d = picture.response1d.top
/ x13d = picture.response1d.left
/ y13d = picture.response1d.bottom
/ a1d = ((expressions.y12d - expressions.y13d)*(mouse.x - expressions.x13d) + (expressions.x13d - expressions.x12d)*(mouse.y - expressions.y13d)) / ((expressions.y12d - expressions.y13d)*(expressions.x11d - expressions.x13d)+(expressions.x13d - expressions.x12d)*(expressions.y11d - expressions.y13d))
/ b1d = ((expressions.y13d - expressions.y11d)*(mouse.x - expressions.x13d) + (expressions.x11d - expressions.x13d)*(mouse.y - expressions.y13d)) / ((expressions.y12d - expressions.y13d)*(expressions.x11d - expressions.x13d)+(expressions.x13d - expressions.x12d)*(expressions.y11d - expressions.y13d))
/ c1d = 1 - expressions.a1d - expressions.b1d
</expressions>

<expressions validresponse_disks>
/ validresponse_disks =
if (0<=expressions.a1d && expressions.a1d <= 1 && 0 <= expressions.b1d && expressions.b1d <= 1 && 0 <= expressions.c1d && expressions.c1d <= 1){
values.response = -1; true; values.p_confidence = 1;
}
</expressions>

<trial responsetrial>
/ stimulusframes = [ 1 = clearscreen;
   2 = response1d, response2d,response3d, response4d, response5d, response6d, response7d, response8d,
         qToAsk, circleInstruction, triangleInstruction, guess, sure, primaryOrSecondaryShapeMid, circleMid
]

/ ontrialbegin = [
values.response = "";
]
/ validresponse = (response_blank, response1d, response2d, response3d, response4d, response5d, response6d, response7d, response8d)
/ inputdevice = mouse
/ isvalidresponse = [
if (trial.responsetrial.response == "response_blank") false;
else expressions.validresponse_disks;
]

/ ontrialend = [
    values.response_time = trial.responsetrial.latency;            
]

</trial>

The code is not particularly useful without the actual image file involved. Also, what exactly is the "shift"?

Please note that Inquisit will *not* distort an image's inherent aspect ratio (see e.g. https://www.millisecond.com/forums/Topic29219.aspx), i.e. whatever you set as the canvas aspect ratio will not affect the image's aspect ratio and any "shift" you're seeing is probably due to that single fact.

Thanks for your quick reply.
The shift can be described in multiplying the mouse.x in 1.3 (after changing the ratio) and then it falls (roughly) on the picture coordinates. (The Y coordinate does not change after change the ratio)
The image size is 284X284 and in some 286X285 or 285X286. 
Thanks,
Sharon.

Attachments
response1disksR.png (8 views, 4.00 KB)
response7disksL.png (8 views, 8.00 KB)
Dave
Dave
Supreme Being (855K reputation)Supreme Being (855K reputation)Supreme Being (855K reputation)Supreme Being (855K reputation)Supreme Being (855K reputation)Supreme Being (855K reputation)Supreme Being (855K reputation)Supreme Being (855K reputation)Supreme Being (855K reputation)
Group: Administrators
Posts: 10K, Visits: 59K
sharondan - 8/19/2020
Dave - 8/19/2020
sharondan - 8/19/2020
Hi,
I have a code that determines if a mouse click was on a picture and on which picture it was (there are 8 pictures).
This code works great when I do not make any change to the canvasaspectratio, however, when changing the canvasaspectratio to (4,3) it does not work (there is a shift between the mouse click and the picture position). Below please find an example of one picture.

<defaults>
/ canvasaspectratio = (4,3)  //if you comment this it works
/ canvassize = (100%, 100%)
</defaults>

<values>
/canvaswidth = display.canvaswidth //This does not received the change in canvasaspectratio and returns the display ratio
/canvasheight = display.canvasheight

/responseY = 9
/responseX = (canvasheight/canvaswidth) * (values.responseY)  //correcting this manualy to the changed ratio does not solve the problem.
</values>

<picture response1d>
/ items = ("response1disksR.png")
/ position = ( 50+values.responseX,50-values.responseY )
/ size = (15.8%,15.8%)
</picture>

<expressions 1_redL_4>
/ x11d = picture.response1d.left
/ y11d = picture.response1d.top
/ x12d = picture.response1d.right
/ y12d = picture.response1d.top
/ x13d = picture.response1d.left
/ y13d = picture.response1d.bottom
/ a1d = ((expressions.y12d - expressions.y13d)*(mouse.x - expressions.x13d) + (expressions.x13d - expressions.x12d)*(mouse.y - expressions.y13d)) / ((expressions.y12d - expressions.y13d)*(expressions.x11d - expressions.x13d)+(expressions.x13d - expressions.x12d)*(expressions.y11d - expressions.y13d))
/ b1d = ((expressions.y13d - expressions.y11d)*(mouse.x - expressions.x13d) + (expressions.x11d - expressions.x13d)*(mouse.y - expressions.y13d)) / ((expressions.y12d - expressions.y13d)*(expressions.x11d - expressions.x13d)+(expressions.x13d - expressions.x12d)*(expressions.y11d - expressions.y13d))
/ c1d = 1 - expressions.a1d - expressions.b1d
</expressions>

<expressions validresponse_disks>
/ validresponse_disks =
if (0<=expressions.a1d && expressions.a1d <= 1 && 0 <= expressions.b1d && expressions.b1d <= 1 && 0 <= expressions.c1d && expressions.c1d <= 1){
values.response = -1; true; values.p_confidence = 1;
}
</expressions>

<trial responsetrial>
/ stimulusframes = [ 1 = clearscreen;
   2 = response1d, response2d,response3d, response4d, response5d, response6d, response7d, response8d,
         qToAsk, circleInstruction, triangleInstruction, guess, sure, primaryOrSecondaryShapeMid, circleMid
]

/ ontrialbegin = [
values.response = "";
]
/ validresponse = (response_blank, response1d, response2d, response3d, response4d, response5d, response6d, response7d, response8d)
/ inputdevice = mouse
/ isvalidresponse = [
if (trial.responsetrial.response == "response_blank") false;
else expressions.validresponse_disks;
]

/ ontrialend = [
    values.response_time = trial.responsetrial.latency;            
]

</trial>

The code is not particularly useful without the actual image file involved. Also, what exactly is the "shift"?

Please note that Inquisit will *not* distort an image's inherent aspect ratio (see e.g. https://www.millisecond.com/forums/Topic29219.aspx), i.e. whatever you set as the canvas aspect ratio will not affect the image's aspect ratio and any "shift" you're seeing is probably due to that single fact.

Thanks for your quick reply.
The shift can be described in multiplying the mouse.x in 1.3 (after changing the ratio) and then it falls (roughly) on the picture coordinates. (The Y coordinate does not change after change the ratio)
The image size is 284X284 and in some 286X285 or 285X286. 
Thanks,
Sharon.