Easy vec tutorials?

Anyone want to help me out? (I know I’m a noob)

Hello @pewbert. Depending on what sort of help you need, this page on the Codea Wiki may be of help.

wow that’s very helpful, but what exactly is a vector @mpilgrem?

Hello @pewbert. A vector is a set of values: (5,6) is a vec2, (5,6,2) is a vec3 and (3,5,4,2) is a vec4. It is used in algebrae to represent positions in the plane (vec2) or in space (vec3). How old are you? (to adjust the answer).

That is a simple question, but a short accurate answer may not be of much help to you. The Wikipedia article on vector space illustrates what I mean.

As @Jmv38 indicates, you can think of a vec2 value as a pair of numbers, where the order of the pair matters: (1, 0) is not the same as (0, 1), for example.

Ordered pairs of numbers crop up in all sorts of places (@Jmv38 gives the common example of points on surfaces - there are many others) and it is useful to have a way to refer to the pair as a single thing, rather than have to keep track separately of each of the two numbers.

I think vectors are useful because

  • they give you a way to store two things in a table at once

  • Codea has a screen, so you are always working with x and y coordinates, ie pairs of numbers

  • Both Lua and Codea have special functions for vectors, eg calculating the distance or angle between them

Wow very useful stuff guys thanks for all the help!, so lets say I wanted to use vec2 to rotate and grow a tween, how would that be done?

This really helped me out. I added the vec3. Using z for rotation.

-- tween testing




-- Use this function to perform your initial setup
function setup()




    -- since we need to tween objects or tables 
    -- let's create a table that will store our values to tween
    -- this object might be your own sprite class or animation class




    -- this contains our starting values
    tweenObject =  vec3(WIDTH/2,HEIGHT/2,0)--{x = WIDTH/2,
                   --y = HEIGHT/2,
                   --rotation = 0}




    -- here we are actually creating the tween    
    -- the first value is the number of seconds the tween will take
    -- the second parameter is our tween object we just created.
    -- now we pass it a list of "ending values"
    -- we can also pass it our easing type and looping type as well as a 
    -- callback function which I'm not using




    -- the ending values
    
    tween(2,tweenObject, {x = WIDTH/4,
                            y = HEIGHT/4,
                            z = 360},
                       {easing = tween.easing.quintInOut,
                        loop = tween.loop.pingpong})
end




-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(40, 40, 50)




    -- This sets the line thickness
    strokeWidth(5)




    pushMatrix()




    -- here we are using our tween Object to control
    -- the translation and rotation
    -- during each call to draw our tween values are slowly updated from
    -- start values to end values 
    -- tween means "the in-between values"  
   translate(tweenObject.x,tweenObject.y)
    rotate(tweenObject.z)








    sprite("Platformer Art:Block Special")




    popMatrix()    
end





wow this is very useful stuff thank you!