canvasaspectratio and picture coordinates


Author
Message
sharondan
sharondan
Associate Member (191 reputation)Associate Member (191 reputation)Associate Member (191 reputation)Associate Member (191 reputation)Associate Member (191 reputation)Associate Member (191 reputation)Associate Member (191 reputation)Associate Member (191 reputation)Associate Member (191 reputation)
Group: Forum Members
Posts: 14, Visits: 102
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.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Explore
Messages
Mentions
Search