level 1
需要做一个正在顺时针运动的圆,当按下键盘后圆就反方向运动了。
现在写出来的code只长按键盘才能反方向运动,松开又是顺时针了,
如何能让圆在按一次键盘后就反方向,再次按下键盘后又变回顺时针。。。
2015年05月04日 13点05分
1
level 1
void draw (){
background (0);
x = x + speed * cos ( direction );
y = y + speed * sin ( direction );
direction = direction + increment * 0.03;
ellipse (x ,y ,20 ,20);
}
现在希望keyPressed之后这个圆能反方向转动,求大神
2015年05月06日 01点05分
3
level 9
float speed=2;
float direction=1;
float angle=0;
float r=70;
void setup() {
size(400, 400);
}
void draw () {
background (0);
pushMatrix();
translate(width/2, height/2);
rotate(radians(angle));
angle=angle+speed*direction;
ellipse (0, 0, r, r);
line(0, 0, 0, r);
popMatrix();
}
void keyPressed() {
direction=direction*-1;
}
2015年05月06日 04点05分
4