1
我正在處理草圖,其中使用二維數組中的點繪製Delaunay圖。 我隨機生成陣列中的點,所以現在它們正在快速生成,因爲draw()
循環運行。處理中的間隔運行功能
for(int i = 0; i < points.length; i++){
pX = random(nX);
pY = random(nY);
points[i][0] = pX;
points[i][1] = pY;
}
我要生成這些數字,例如每1秒。我試着用下面的代碼,但線路被只繪製一個很短的時間每隔1秒,間隔似乎有所不同......
if (millis() - timeCheck > timeInterval){
for(int i = 0; i < points.length; i++){
timeCheck = millis();
pX = random(nX);
pY = random(nY);
points[i][0] = pX;
points[i][1] = pY;
}
}
我的最終目標是讓老之間的變速線新的點,因爲它們正在生成。我想使用寬鬆的方式,所以整個事情看起來不錯,順暢。
這是整個代碼。我使用mesh library來繪製網格。
import megamu.mesh.*;
import processing.svg.*;
import processing.pdf.*;
boolean recording = false;
void rec() {
if (key == 'r' || key == 'R') {
recording = !recording;
}
}
float numX;
float numY;
float x;
float y;
float offset = 0.00;
float easing = 0.05;
Delaunay myDelaunay ;
int timeCheck;
int timeInterval = 1000;
void setup(){
size(600,400);
timeCheck = millis();
}
void draw(){
rec();
if (recording){
beginRecord(SVG, "####.svg");
}
offset = offset + .005;
background(noise(offset) * 50);
stroke((noise(offset) * 255)+100, (noise(offset) * 100)+50, noise(offset) * 255);
float[][] points = new float[10][2];
numX = (width);
numY = (height);
float nX = noise(offset) * width;
float pX = random(nX);
float targetX = random(nX);
float dX;
float nY = noise(offset) * height;
float pY = random(nY);
float targetY = random(nY);
float dY;
if (millis() - timeCheck > timeInterval){
for(int i = 0; i < points.length; i++){
timeCheck = millis();
//println(timeCheck);
pX = random(nX);
pY = random(nY);
points[i][0] = pX;
points[i][1] = pY;
}
}
myDelaunay = new Delaunay(points);
float[][] myEdges = myDelaunay.getEdges();
for(int i=0; i<myEdges.length; i++) {
dX = targetX - pX;
x += dX * easing;
dY = targetY - pY;
y += dY * easing;
float startX = myEdges[i][0];
float startY = myEdges[i][1];
float endX = myEdges[i][2];
float endY = myEdges[i][3];
line(startX, startY, endX, endY);
ellipse(startX, startY, 5, 5);
}
endRecord();
}
是否有你使用'frameCount%60 == 1'而不是'frameCount%60 == 0'的原因? –
@KevinWorkman這是我的印象,在調用'draw()'後,'frameCount = 1',所以'frameCount%60 == 1'將允許在draw()的第一次迭代中生成這些點。 – UnknowableIneffable
是的'frameCount'確實從'1'開始。有趣的一點。 –