各位大大好
小弟想請教一下,關於球類的問題 只要球有連一條線就變色 二條線又變另一種顏色 三條線又變一種色
那我的代碼要怎麼打比較好 請各位大大指教
1.一條線變藍
2.二條線變紅
3.三條線變黃
int num = 50, radius = 50;
int[] posX, posY, speedX, speedY;
void setup() {
size(800, 600);
stroke(255);
strokeWeight(15);
posX = new int[num];
posY = new int[num];
speedX = new int[num];
speedY = new int[num];
for (int i=0; i<num; i++) {
posX[i] = int(random(width));
posY[i] = int(random(height));
speedX[i] = int(random(-5, 5));
speedY[i] = int(random(-5, 5));
}
}
void draw() {
background(0);
for (int i=0; i<num; i++) {
ball(i);
}
}
void ball(int i) {
posX[i] = posX[i] + speedX[i];
posY[i] = posY[i] + speedY[i];
if (posX[i] > width) {
speedX[i] = -1 * speedX[i];
} else if (posX[i] < 0) {
speedX[i] = -1 * speedX[i];
}
if (posY[i] > height) {
speedY[i] = -1 * speedY[i];
} else if (posY[i] < 0) {
speedY[i] = -1 * speedY[i];
}
point(posX[i], posY[i]);
for (int j = 0; j < num; j++) {
if(dist(posX[i], posY[i], posX[j], posY[j]) < radius) {
strokeWeight(1);
line(posX[i], posY[i], posX[j], posY[j]);
strokeWeight(15);
}
}
}