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.
IndexProgramming Questions & HelpSyntax Questions › Forward motion, rotation determined direction
Page Index Toggle Pages: 1
Forward motion, rotation determined direction? (Read 117 times)
Forward motion, rotation determined direction?
Mar 1st, 2009, 9:10pm
 
Confused.  I want to be able to determine the direction of these lil' objects through there rotation.  So i.e. whatever direction they're "facing" according to the rotate() function within a pushmatrix(), a +1 to the y coordinate will move in that direction, NOT just necessarily down on the screen's set coordinate plane...

I've been generally using Reas/Fry's book and the various examples as a guide, but yeah.  Anyway, thanks in advance.

Here's my code so far

Code:

int partCnt = 200;

offPart[]offP = new offPart[partCnt];
float[]x = new float[partCnt];
float[]y = new float[partCnt];
float[]ang = new float[partCnt];

void setup(){
size(640,480,P2D);
frameRate(24);
noStroke();
background(102);
for(int i=0; i < partCnt; i++){
x[i] = random(20,width-20);
y[i] = random(20,height-20);
ang[i] = random(0,360);
offP[i] = new offPart(width/2, height/2, 0, ang[i]);
}
}

void draw(){
background(102);
for(int i=0; i < partCnt; i++){
x[i] = x[i];
y[i] = y[i] + random(0,4);
ang[i] = ang[i] + (PI/2);
offP[i].move(x[i], y[i], ang[i]);
}
}

class offPart {
float x,y;
int children;
float ang;
float roAngle;

//offPart(){
// this(0,0,0,0);
//}

offPart(float x, float y, int children, float ang){
this.x = x;
this.y = y;
this.children = children;
ang = cos(ang + random(-0.1, 0.1));
this.ang = ang;
}

// return detect(float x, float y){
// for(int i=0; i < 10; i++){
// if((x-5)+i == x[l]


// }

void move(float x, float y, float angle) {
angle = radians(angle);
roAngle = sin(angle + random(-0.1, 0.1));
pushMatrix();
translate(x,y);
rotate(roAngle);
fill(200);
ellipseMode(CENTER);
ellipse(0,0,10,10);
ellipse(0,10,5,5);
popMatrix();

}


}
Page Index Toggle Pages: 1