如何在处理过程中每次撞墙时改变球的颜色?我的代码如下
How to change the color of ball everytime it strike the wall, in processing? My code is as below
这是我的代码。在下一步中,如何通过键盘按键对弹跳球产生影响。
float circleX = 0;
float circleY = 0;
float xSpeed = 2.5;
float ySpeed = 2;
void setup() {
size(500, 500);
}
void draw() {
background(0,200,0);
circleX += xSpeed;
if (circleX < 0 || circleX > width) {
xSpeed *= -1;
}
circleY += ySpeed;
if (circleY < 0 || circleY > height) {
ySpeed *= -1;
}
ellipse(circleX, circleY, 100, 100);
}
每次球撞墙时改变颜色fill()
:
float circleX = 0;
float circleY = 0;
float xSpeed = 2.5;
float ySpeed = 2;
void setup() {
size(500, 500);
}
void changeColor() {
fill(random(255), random(255), random(255));
}
void draw() {
background(0,200,0);
circleX += xSpeed;
if (circleX < 0 || circleX > width) {
xSpeed *= -1;
changeColor();
}
circleY += ySpeed;
if (circleY < 0 || circleY > height) {
ySpeed *= -1;
changeColor();
}
ellipse(circleX, circleY, 100, 100);
}
这是我的代码。在下一步中,如何通过键盘按键对弹跳球产生影响。
float circleX = 0;
float circleY = 0;
float xSpeed = 2.5;
float ySpeed = 2;
void setup() {
size(500, 500);
}
void draw() {
background(0,200,0);
circleX += xSpeed;
if (circleX < 0 || circleX > width) {
xSpeed *= -1;
}
circleY += ySpeed;
if (circleY < 0 || circleY > height) {
ySpeed *= -1;
}
ellipse(circleX, circleY, 100, 100);
}
每次球撞墙时改变颜色fill()
:
float circleX = 0;
float circleY = 0;
float xSpeed = 2.5;
float ySpeed = 2;
void setup() {
size(500, 500);
}
void changeColor() {
fill(random(255), random(255), random(255));
}
void draw() {
background(0,200,0);
circleX += xSpeed;
if (circleX < 0 || circleX > width) {
xSpeed *= -1;
changeColor();
}
circleY += ySpeed;
if (circleY < 0 || circleY > height) {
ySpeed *= -1;
changeColor();
}
ellipse(circleX, circleY, 100, 100);
}