canvasaspectratio and picture coordinates


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

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View
Threaded View
sharondan - 5 Years Ago
Dave - 5 Years Ago
Dave - 5 Years Ago
sharondan - 5 Years Ago
Dave - 5 Years Ago
Dave - 5 Years Ago
sharondan - 5 Years Ago
sharondan - 5 Years Ago
                         1.33 is obviously just an approximation. Make it more fine-grained if...
Dave - 5 Years Ago
                             Thanks Dave, To be honest, I was hoping for an elegant solution and...
sharondan - 5 Years Ago
Dave - 5 Years Ago

Reading This Topic

Explore
Messages
Mentions
Search