0
我正在尝试沿画布的y轴和x轴顺序绘制几个椭圆。点在随机y位置绘制。处理For循环序列
我以前有椭圆随机沿x轴绘制高度。但是,所有沿y轴的椭圆都是一次绘制的。
for (int x = 0; x < xStep; x++) {
int mh = int(map(noise(offset+(x*0.05)), 0, 1, 0, h));
for (int y = mh; y > mh - 3; y--) {
ellipse(x*diam, y*diam, diam, diam);
}
}
xStep++;
if (xStep > w) {
xStep = 0;
offset = random(1000);
}
然后,我继续添加另一个for循环,尝试沿y轴以及x轴顺序排列椭圆。因此,在绘制下一列(x轴)之前,视觉上每个椭圆在y轴上依次绘制。然而,使用下面的代码,我得到的是y和x轴的“绘图”,但同时在视觉上看起来并不像一行在下一列绘制之前完成。
//count rows and frames
if (counter > 7) {
counter = 0;
rowCounter++;
}
for (int j=0; j<7; j++) { //set values to match counter
if (j == counter){
for (int x = 0; x < xStep; x++) {
int mh = int(map(noise(offset+(x*0.05)), 0, 1, 0, h));
for (int y = mh; y > mh - 3; y--) {
y=y-j;
ellipse(x*diam, y*diam, diam, diam);
}
}
}
}
xStep++;
counter++;
if (rowCounter > 7) {
rowCounter = 0;
}
if (xStep > w) {
xStep = 0;
offset = random(1000);
}
或者,如果我尝试使用条件的特步我只得到绘制椭圆的一行。
//count rows and frames
if (counter > 7) {
counter = 0;
rowCounter++;
}
for (int j=0; j<7; j++) { //set values to match counter
if ((j == counter) && (xStep != lastXstep)) {
for (int x = 0; x < xStep; x++) {
int mh = int(map(noise(offset+(x*0.05)), 0, 1, 0, h));
for (int y = mh; y > mh - 3; y--) {
y=y-j;
ellipse(x*diam, y*diam, diam, diam);
xStep=lastXstep;
}
}
}
}
xStep++;
counter++;
if (rowCounter > 7) {
rowCounter = 0;
}
if (xStep > w) {
xStep = 0;
offset = random(1000);
}
任何人都可以帮助指向我的方向,我出错的for循环结构? 谢谢。