2010年6月7日 星期一

machine activation sample codes

wheel object1;
wheel2 object2;
int state = 0;
void setup()
{
size(640, 360);
background(255);
smooth();
object1 = new wheel(100, 100);
object2 = new wheel2(300, 100);

}
void draw()
{
if ((mousePressed) && (mouseX> width/2))
{
state= 1;
object1.input();
}
if (state ==1)
{
object1.update();
object1.display();
}
if (state == 2)
{

object2.update();
object2.display();
}


}



class wheel
{
int x, y;
float angle;
int nRotate;

wheel(int xc, int yc)
{
x= xc;
y= yc;
angle = 0;


}

void input()
{
nRotate= 0;
}
void update()
{
nRotate ++;
angle= angle + 10;
if (nRotate >50)
output();
display();


}

void display()
{
pushMatrix();
translate(x, y);
rotate(radians(angle));
rect(-10, -10, 20, 20);

popMatrix();

}
void output()
{
state = 2;
object2.input();
}


}
class wheel2
{
int x, y;
float angle;
int nRotate;

wheel2(int xc, int yc)
{
x= xc;
y= yc;
angle = 0;


}

void input()
{
nRotate= 0;
}
void update()
{
nRotate ++;
angle= angle + 10;
if (nRotate >50)
output();
display();


}

void display()
{

pushMatrix();
translate(x, y);
rotate(radians(angle));
rect(-10, -10, 20, 20);

popMatrix();

}
void output()
{
state = 1;
object1.input();
}


}

沒有留言:

張貼留言