Millisecond Forums

canvasaspectratio and picture coordinates

https://forums.millisecond.com/Topic29580.aspx

By sharondan - 8/18/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>
By Dave - 8/18/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.
By Dave - 8/18/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.

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!
By sharondan - 8/18/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.
By Dave - 8/18/2020

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.

Thanks. Could you provide actually working code -- i.e. stuff that can actually be run and doesn't reference non-existent things -- as well?

Nowhere in the snippet you posted, for example, are values.responseX and responseY actually being set based on any response. values,response and values.p_confidence are referenced in the code and expressions, yet they are nowhere defined, etc
By Dave - 8/18/2020

Dave - 8/19/2020
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.

Thanks. Could you provide actually working code -- i.e. stuff that can actually be run and doesn't reference non-existent things -- as well?

Nowhere in the snippet you posted, for example, are values.responseX and responseY actually being set based on any response. values,response and values.p_confidence are referenced in the code and expressions, yet they are nowhere defined, etc

Never mind. As you noted, the shift is by about 1.3. That's because 4:3 (the aspect ratio) = 1.3333. Changing the canvas area, of course affects the math in your expressions that rely on the mouse.x coordinates. The ratio is different, so you have to adjust for that there.

Condensed example:

<picture response1d>
/ items = ("response1disksR.png")
/ position = (50%,50%)
/ size = (15.8%,15.8%)
</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
/response = 0
/p_confidence = 0
/responseY = 9
/responseX = (canvasheight/canvaswidth) * (values.responseY) //correcting this manualy to the changed ratio does not solve the problem.
</values>

<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)*(1.33*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)*(1.33*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 = response1d;]
/ ontrialbegin = [
values.response = "";
]
/ validresponse = (response1d)
/ inputdevice = mouse
/ isvalidresponse = [
if (trial.responsetrial.response == "response_blank") false;
else expressions.validresponse_disks;
]
</trial>
By sharondan - 8/18/2020

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.

My apologies for this Dave (I was trying to be concise so it will be clear and got the opposite result)
In order for every 2 triangles pair to appear as one image, the pictures are superimposed - this is the reason for elaboratd expressions. 
Also to be on the safe side, attached please find a runnable experiment (with the pictures)


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

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

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

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

Also to be on the safe side, attached please find a runnable experiment (with the pictures)
Thanks,
Sharon.
By sharondan - 8/18/2020

sharondan - 8/19/2020
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.

My apologies for this Dave (I was trying to be concise so it will be clear and got the opposite result)
In order for every 2 triangles pair to appear as one image, the pictures are superimposed - this is the reason for elaboratd expressions. 
Also to be on the safe side, attached please find a runnable experiment (with the pictures)


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

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

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

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

Also to be on the safe side, attached please find a runnable experiment (with the pictures)
Thanks,
Sharon.

Thanks Dave,
I've tried this solution anbdit works generally fine, but not if you are close to the borders
By Dave - 8/18/2020

sharondan - 8/19/2020
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.

My apologies for this Dave (I was trying to be concise so it will be clear and got the opposite result)
In order for every 2 triangles pair to appear as one image, the pictures are superimposed - this is the reason for elaboratd expressions. 
Also to be on the safe side, attached please find a runnable experiment (with the pictures)


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

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

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

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

Also to be on the safe side, attached please find a runnable experiment (with the pictures)
Thanks,
Sharon.

As noted in my previous reply, correct for the aspect ratio change (4:3 = 1.33) by replacing mouse.x in your expressions with 1.33*mouse.x and things will work.
By Dave - 8/18/2020

sharondan - 8/19/2020
sharondan - 8/19/2020
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.

My apologies for this Dave (I was trying to be concise so it will be clear and got the opposite result)
In order for every 2 triangles pair to appear as one image, the pictures are superimposed - this is the reason for elaboratd expressions. 
Also to be on the safe side, attached please find a runnable experiment (with the pictures)


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

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

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

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

Also to be on the safe side, attached please find a runnable experiment (with the pictures)
Thanks,
Sharon.

Thanks Dave,
I've tried this solution anbdit works generally fine, but not if you are close to the borders

1.33 is obviously just an approximation. Make it more fine-grained if need be (multiply by 1.33333333) or change ot (4/3)*mouse.x.
By sharondan - 8/18/2020

Dave - 8/19/2020
sharondan - 8/19/2020
sharondan - 8/19/2020
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.

My apologies for this Dave (I was trying to be concise so it will be clear and got the opposite result)
In order for every 2 triangles pair to appear as one image, the pictures are superimposed - this is the reason for elaboratd expressions. 
Also to be on the safe side, attached please find a runnable experiment (with the pictures)


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

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

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

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

Also to be on the safe side, attached please find a runnable experiment (with the pictures)
Thanks,
Sharon.

Thanks Dave,
I've tried this solution anbdit works generally fine, but not if you are close to the borders

1.33 is obviously just an approximation. Make it more fine-grained if need be (multiply by 1.33333333) or change ot (4/3)*mouse.x.

Thanks Dave,
To be honest,  I was hoping for an elegant solution and not fine tunning of the few numbers that come after the dot (which for some reason need to be different for the left and right side of the screen).
I guess I have to live with that :-)
Thanks!
Cheers,
Sharon.