Howdy, Stranger!

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

Touch Radius

SimeonSimeon Admin Mod
edited April 2015 in General Posts: 4,957

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.

Comments

  • Posts: 418

    Any ideas for what this could be used for?

  • More sensitive/accurate buttons, perhaps?

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

  • dave1707dave1707 Mod
    edited April 2015 Posts: 7,602

    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 .

  • IgnatzIgnatz Mod
    Posts: 5,396

    We should have a fat finger contest :))

  • Posts: 730

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

  • dave1707dave1707 Mod
    Posts: 7,602

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

  • SimeonSimeon Admin Mod
    Posts: 4,957

    @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,042

    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.

  • Makes sense @Simeon

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

  • touch.radius==0 when touch.state==ENDED

    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
            print("that is your thumb.")
        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,042

    @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
        totalradius = totalradius + radius[i]
    end
    
    thumbav = totalradius/#radius
    
Sign In or Register to comment.