#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

#### In this Discussion

edited April 2015 in General Posts: 5,613

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)

end
``````

Note: This feature is iOS 8 only, if you are on iOS 7 then you will see a radius and radiusTolerance of `0`.

Tagged:

• Posts: 418

Any ideas for what this could be used for?

• Posts: 192

More sensitive/accurate buttons, perhaps?

• Mod
Posts: 2,020

Painting apps

• Posts: 277

or a piano app, where velocity would be related to the radius?

• edited April 2015 Posts: 342

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.

• Mod
edited April 2015 Posts: 9,260

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.

EDIT: I show a radiusTolerance of 5.21875 .

• Mod
Posts: 5,396

We should have a fat finger contest )

• Posts: 871

@Ignatz - I was thinking that too! :-)

• Mod
Posts: 9,260

If I touch the screen with the palm of my hand, I get a value of 240.

Posts: 5,613

@Monkeyman32123 I think it could be very dependent on what device you have, what the accuracy of the touch radius is.

• Posts: 289

interesting，light touch and hard touch

• Posts: 2,048

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.

• Posts: 342

Makes sense @Simeon

And @Ignatz, I think my values give me the win for a "skinny finger" contest

• Posts: 91

Makes sense but my code to draw touch markers based on the touch.radius made the end of touch location marker disappear!

• edited May 2015 Posts: 39

I created a thumb detector but it isn't super accurate.

``````function touched(touch)
if touch.radius > 23.506999 and touch.state == BEGAN then
end
end
``````
• edited May 2015 Posts: 39

well, it works 79% of the time for me. Others may have a different thumb average.

• Posts: 2,048

@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

• edited May 2015 Posts: 39

@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
end

``````
• Posts: 1,178

@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.

• Posts: 1,178

Huh.

It works WAYYYY better on an iPhone.

Like, it works GREAT.

1. How is it that an iPhone has better touch sensitivity than an iPad?
2. Is there a way to trick an iPad into reporting touches with the sensitive of an iPhone?
• Posts: 871

@UberGoober I don’t think this was one of mine. Tried on both iPad and iPhone and get similar results. It’s not how hard you press which changes the radius, but the area which is contact with the screen for the touch - if you flatten your finger against the screen as if smearing or smudging something you get a large radius, if you barely touch the screen you get a small radius

• Posts: 1,178
@West whatever you call it, the same swipe on the iPhone and the iPad give very different results, for me.
• Mod
Posts: 9,260

It’s probably because the iPad and the iPhone have different pixels per inch. You can look those up and see if they’re different.

Posts: 5,613

@UberGoober are you using an iPhone with "3D touch" capability? (The newest iPhone 12s don't have it)

These iPhones have a pressure sensitive layer in the screen and can detect very fine differences in touch

• Posts: 1,178

My iPhone is an 8 and my iPad is the larger iPad Pro.

@West — you did a tweak to @JakAttak’s original thingy, here: https://www.codea.io/talk/discussion/4760/reverse-bounce