There’s an undocumented feature in the current version of Codea.
It’s not documented because it hasn’t gone through testing. You can test it out now.
touch objects now have two extra fields: radius and radiusTolerance. This represents a very rough approximation of the radius of a touch based on how much of your finger is covering the screen.
The below example exaggerates the effect by multiplying the radius by two. If you roll your finger across the screen you should see the ellipse change size.
radiusTolerance represents the estimated accuracy of the radius. So the minimum radius is radius - radiusTolerance and the max is radius + radiusTolerance.
function setup()
end
function draw()
background(40, 40, 50)
strokeWidth(5)
ellipse(CurrentTouch.x, CurrentTouch.y, CurrentTouch.radius * 2)
end
Note: This feature is iOS 8 only, if you are on iOS 7 then you will see a radius and radiusTolerance of 0.
That code does not work for me (on ios8, latest release). It gives me incredibly small values, 1.7*(10^-189) is the average value Im getting. And that value is AFTER i had to use math.abs() on the numbers, because i was also getting super tiny negative numbers. Then i multiplied the radii by 10^190 and was getting ellipse sizes that were completely random, and not related to how much screen coverage i got. Interestingly enough, a bit later i was getting touch radii equal to -inf and inf.
EDIT: also, after the touch begins, it doesnt seem that the ellipse ever changes sizes
EDIT2: I decided to test the radius tolerance and it is a drastically larger number but still very small. Im getting about 1.3*(10^-133) on average for it, which is about 10^54 larger than the radius itself.
I took the above code and it works fine for me, iOS 8.3 and latest beta. When I print CurrentTouch.radius, I get 2 values depending on how hard I press. A light touch gives 20.890265 and a harder touch gives 31.34375.
Great! I just built a feature into my game for IPhones to have things you touch show above the finger but I had to choose a guesstimate value for average finger size. This should be a great help for that.
@jaj_TheDeveloper, you might be able to do it by having the user place all 5 fingers on the screen, then you see which is the largest and that is your thumb average
@JakAttak but I would need them to do it multiple times because the thumb’s touch.radius is not always the same. I could use the following or similar code to work out the average:
totalradius = 0
for i = 1, #radius do
totalradius = totalradius + radius[i]
end
thumbav = totalradius/#radius
@Simeon is there any way to get this more sensitive?
I tried to apply it to this old Wiggle project by @West and @JakAttak (attached)
Similar to other reports above, I only ever see two values for the radius: a smaller one, and if I press really really really hard, a larger one, but nothing in between.
I modified this project a little, to fake a tapering effect at the start of a touch, and I think it looks pretty cool, illustrating how much cooler it would be if it could actually detect finer variations of radius.