void setup(){
size(800,600);
background(0);
fill(255,40,40);
noStroke();
ellipse(400,80,20,20);
ellipse(150,513,20,20);
ellipse(650,513,20,20);
fill(255);
frameRate(10);
}
float traceX = 350;
float traceY = 350;
String vertexPick = "";
float rand = 0;
void draw(){
point(traceX,traceY);
rand = random(1);
if (rand > 2/3) {
vertexPick = "A";
}
else if (rand < 1/3) {
vertexPick = "B";
} else {
vertexPick = "C";
}
if (vertexPick == "A") {
traceX = (traceX+400)/2;
traceY = (traceY+80)/2;
}
else if (vertexPick == "B") {
traceX = (traceX+150)/2;
traceY = (traceY+513)/2;
}
else
{
traceX = (traceX+650)/2;
traceY = (traceY+513)/2;
}
}
我已经检查过了,每次通过“抽奖”#39;函数它生成一个介于0和1之间的新随机数。但是不是根据数字将vertexPick分配给一个新的字母,它会被卡在vertexPick的一个值上并永远保留在那里。谁能告诉我为什么?为什么不在每个循环上再次执行if语句?
答案 0 :(得分:0)