An Exploration of tween

Four programs that examine tweens. Code 12a - tween is a starting point, Code 12b - tween Experiments takes the investigation a little further, Code 12c - tween pause demonstrates pausing a tween with a touch and changing the destination with the same touch, Code 12d - tween path takes a look at using paths.
Code 12a:
Code 12b:
Code 12c:
Code 12d:

12b is heavily commented, but I think it works as intended.
These are example programs of how to make a tween work. An actual use is a different topic.
These programs are from my chapter on tweens in the textbook I am writing. I want the programs to be simple enough to give basic ideas and code without being overly complex. When I am trying to learn a new skill I want simple code I can copy and use. The Animation example is great for showing me what can be done, but I found it difficult to pull just the code I needed for my own program.
These programs are the result of my learning process.

@Brucewe - thank you, new demos are always useful, but I have a couple of questions for you

First, Code 12b doesn’t seem to do anything because the code is all commented out

Second, having done this, I’m interested in what practical use do you see for tweens (unless you want an object to go back and forward endlessly). Simply moving from A to B is easier to do without tweens, and I can’t see why I’d want to use tweens for any of the things you had in your examples.

Lastly, are these part of some kind of series? If so, are you going to share the others?

Thanks again

@Ignatz in terms of practical uses, I think it comes down to, they are useful for a specific set of problems, but don’t use them for everything.

So let’s say I have a character who jumps, I wouldn’t use tween even just for the vertical component, because I don’t know where he’s going to land, so I’m better of managing his position and velocity via gravity etc, and checking each cycle whether he’s landed.

But, as another example, let’s say we are talking cargo bot and I need to move the claw from up at rest to on the top box in the stack. Well, I know the start position, and the end position, it’s clearly predetermined, so I could still write code to move it down and detect the box, but a tween is very handy as I can just set the movement at the start and then not worry about it. And I can also pick an easing to give the feel of movement I want without having to model gravity/inertia/whatever.

So if you have a movement which has a clear start and end and no external factors to worry about, it makes life simple. I haven’t used the Codea tweens myself, but in my particle shader for fireworks I reimplemented the same tween style logic in the shader, and it means for things shooting out from the bang of a firework it’s dead easy without having to model proper motion.

Thanks for the explanation!