0
我試圖在Processing上實現動畫螺旋曲線,以便在每個draw()函數內逐漸構建曲線。我已經成功地將曲線創建爲靜態形狀 - 現在我正在嘗試更進一步。使用curveVertex動畫曲線Proccesing
不幸的是,儘管我的努力,我的代碼似乎並沒有工作。經過一段等待時間我與以下錯誤消息一起再次獲得形狀靜:
您必須使用curveVertex前beginShape()或beginShape(多邊形)()
與此相反的消息,我已經一個beginShape()指令
這裏是我的代碼(也許在錯誤的地方?):
float x,y;
float stepSize;
float angle;
int counter;
void setup() {
size(900, 600);
background(255);
frameRate(30);
smooth();
//noStroke();
stroke(0);
x = 0;
y = 0;
stepSize = 6;
angle = radians(270);
counter = 0;
}
void draw() {
translate(width/3, height/2);
if (counter == 0) {
beginShape();
curveVertex(x, y); // initial control point
} else {
if (stepSize > 1.0) {
curveVertex(x, y);
x = x + cos(angle) * stepSize;
y = y + sin(angle) * stepSize;
stepSize = stepSize * 0.99;
angle = angle - radians(1.5);
} else {
// return to previous x,y values for last control point
angle = angle + radians(1.5);
stepSize = stepSize/0.99;
y = y - sin(angle) * stepSize;
x = x - cos(angle) * stepSize;
curveVertex(x, y); // last control point
endShape();
}
}
counter++;
}
非常感謝您提供的幫助! - 伊利亞斯
謝謝凱文,給出了聰明的答案!我這麼知道增強循環,這是我以前不知道的;;) –