Dynamic radius in physics.body(CIRCLE, radius)

Hi

I have been playing with processing for a while and by coincidence just discovered Codea.

Therefore I’m new to codea and just taking my first steps :slight_smile:

If I add a physics.body, is’nt it possible to change the size of it?
E.g. making a ball that grows in size?

@Jorgensen I posted this a while ago, but I couldn’t find it, so here it is again. When the circle starts to fall, double tap the screen to increase it’s size. You have to destroy the object and create a new one to change it’s size along with it’s other original values.


function setup() 
    supportedOrientations(PORTRAIT)
    rad=50
    
    c1 = physics.body(CIRCLE,rad)
    c1.x=250
    c1.y=900
    
    c2 = physics.body(CIRCLE,50)
    c2.x=300
    c2.y=300
    c2.type=STATIC
end

function draw()
    background(40,40,50 )  
    stroke(255)
    strokeWidth(1)
    noFill()   
    ellipse(c1.x,c1.y,rad*2,rad*2) 
    ellipse(c2.x,c2.y,100,100)
end

function touched(t)
    if t.state==BEGAN then
        if t.tapCount==2 then
            rad=75   -- increase the radius
            c1x=c1.x    -- save the old values
            c1y=c1.y
            c1lv=c1.linearVelocity
            c1:destroy()    -- destroy the current object
            c1 = physics.body(CIRCLE,rad)  -- create a new object 
            c1.x=c1x     -- use old values
            c1.y=c1y   
            c1.linearVelocity=c1lv 
        end
    end                
end

Good to know! Thanks.

@dave
Thanks for your input.

So I guess the physics.body.radius is not dynamic :slight_smile:

Thanks for your time.

Just so you know, in 1.5 you will be able to change circle radius dynamically

Oh you tease, you. :wink:

:slight_smile: