# Swinging movement (+ other stuff)

Hi guys!

For an assignment at school, my team and I have to create a new concept for a game.
To impress the judges, we’ve decided to make a little prototype of our idea.
We want to make it happen on an iPad, so Codea seemed the easiest solution (because we don’t have a mac).

To make things short, I’ve started modifing an example project (Gravity).
But their are stil some stuff (not much) that I want to change (but I don’t know how).

Let me provide the current code now

function draw()

GravityX = Gravity.x
GravityY = Gravity.y

background(127, 127, 127, 255)
stroke (255, 255, 255, 255)
strokeWidth(7)

lineCapMode(Round)
pushMatrix()
translate(WIDTH / 2, HEIGHT / 2)

grav = vec2(Gravity.x * 300, Gravity.y * 300)

rect (-50,0,100,20)
line(0,0,grav.x, grav.y)

down = vec2(1, 0)
orient = down::angleBetween(grav)

pushMatrix()
resetMatrix()

translate(WIDTH / 2, HEIGHT / 2)
translate(grav.x, grav.y)
rotate(math.deg(orient))

ellipse (0,0,40,40)

popMatrix()
end

The issue is that the lenght of the line is also variable to the position the iPad is held in.

1. It would be nice if that lenght was fixed

2. Now the line stops moving when the iPad is held still
Is their a solution to make a swinging movement (that the line moves a bit after the iPad is held stillà

To get a constant length on the gravity vector you can replace this line:

``````grav = vec2(Gravity.x * 300, Gravity.y * 300)
``````

With

``````grav = vec2(Gravity.x, Gravity.y):normalize() * 300
``````

But it sounds like what you really want is a Pendulum. For that, I’d recommend looking at some code shared by @Andrew_Stacey in this thread: http://twolivesleft.com/Codea/Talk/discussion/472 (A direct link to the code is here: http://www.math.ntnu.no/~stacey/documents/Codea/Pendulum). Unfortunately it is quite long because he wrote his own font renderer, as this project was created before Codea offered text rendering.

May you do ~~~ at the start and end of the code [-O<