We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexDiscussionExhibition › path tween (complex)
Page Index Toggle Pages: 1
path tween (complex) (Read 1252 times)
path tween (complex)
Jan 8th, 2010, 9:54pm
 
Here is an example of a tween that follows a complex 3d path.
Library: http://www.ekeneijeoma.com/processing/tween

Code:
/**
Title: complex 3d tween

Author: Bloom
Date: january 2010
Description: An object follows a complex path
*/

import processing.opengl.*;

import ijeoma.tween.*;
import ijeoma.easing.*;

//∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞

Thing obj;

//path coords
int i = 50;
float[][] path = {{i, i, i},{i*1.5, 0, 0},{i, -i, -i},{0, -i*1.5, 0},{-i, -i, i},{-i*1.5, 0, 0},{-i, i, -i},{0, i*1.5, 0}};

TweenSequence tweenSequence;

//∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞

void setup(){
size(400, 400, OPENGL);

obj = new Thing();

TweenGroup[] tweenGroup = new TweenGroup[path.length];

//fill groups for a full sequence
for(int i = 0; i < path.length; i++){
int next = ((i+1) == path.length)?0:i+1;
Tween tx = new Tween(this, "tweenX", obj, "object", path[i][0], path[next][0], 50f, Tween.FRAMES, 0f, Tween.LINEAR_EASE_OUT);
Tween ty = new Tween(this, "tweenY", obj, "object", path[i][1], path[next][1], 50f, Tween.FRAMES, 0f, Tween.LINEAR_EASE_OUT);
Tween tz = new Tween(this, "tweenZ", obj, "object", path[i][2], path[next][2], 50f, Tween.FRAMES, 0f, Tween.LINEAR_EASE_OUT);
tweenGroup[i] = new TweenGroup(this, "tweenGroupXYZ_" + i, new Object[]{tx, ty, tz});
}

tweenSequence = new TweenSequence(this, "tweenSequence", tweenGroup);
tweenSequence.repeat(Tween.NO_REVERSE); //repeat the sequence

tweenSequence.start();

}

void draw() {
background(255);

translate(width/2, height/2, 0);
rotateY(frameCount/100.0);
rotateX(2.0);
rotateZ(frameCount/200.0);

//simple guide..
noFill();
stroke(200);
box(i*2);

//path
noFill();
stroke(100);
beginShape();
for(int i = 0; i < path.length; i++){
vertex(path[i][0], path[i][1], path[i][2]);
}
endShape(CLOSE);

//tween object
Tween tx = tweenSequence.getCurrentTweenGroup().getTweenByName("tweenX");
Tween ty = tweenSequence.getCurrentTweenGroup().getTweenByName("tweenY");
Tween tz = tweenSequence.getCurrentTweenGroup().getTweenByName("tweenZ");
obj.draw(tx.getPosition(), ty.getPosition(), tz.getPosition());

}

//∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞

class Thing{

Thing(){}

void draw(float _x, float _y, float _z){
fill(0);
translate(_x, _y, _z);
box(20);
}

}



for the simple example: http://processing.org/discourse/yabb2/num_1263016190.html
Page Index Toggle Pages: 1