Wiki

Clone wiki

Core / UserAcceleration

Back to Beyond the Codea in-app reference


FunctionIconConst-Small.png UserAcceleration global variable

Introduction

Codea's in-app reference documents most of the UserAcceleration global variable. The variable initially refers to a built-in vec3() userdata value that is set to the current acceleration vector returned by the iPad's accelerometer.

Value referenced by UserAcceleration

The length of the acceleration vector ranges from less than 1 for light shaking up to almost 3 for very vigorous shaking. For example:

function setup()
    maxAccel = 0
    watch("maxAccel")
end

function draw()
    maxAccel = math.max(maxAccel, UserAcceleration:len())
end

Variables other than UserAcceleration can refer to the value that is updated. For example:

UA = UserAcceleration  -- Now UA refers to the updated value
UserAcceleration = nil -- No longer refers to the updated value

function draw()
    background(0)
    local d = UA:len() * 1000
    ellipse(WIDTH / 2, HEIGHT / 2, d, d)
end

Updated