当一排椭圆移动到窗口下时,我该如何增加它们的大小呢?我想让它看起来像当它们到达窗口底部时,它们变得更大。
size(300, 500);
background(255);
noStroke();
smooth();
translate(width/8, height/2);
for (int a = 0; a < 7; a++) {
for (int b = 0; b < 7; b++) {
fill(random(0, 50));
ellipse(a * 76, b * 65, 100, 100);
}
}
椭圆()函数的最后两个参数允许您控制宽度和高度:
size(300, 500);
background(255);
noStroke();
smooth();
translate(width/8, height/2);
for (int a = 0; a < 7; a++) {
for (int b = 0; b < 7; b++) {
// int ellipseSize = (a+b)*10;//depending both x and y
int ellipseSize = b * 10;//depdning just on y
fill(random(0, 50));
ellipse(a * 76, b * 65, ellipseSize, ellipseSize);
}
}
这里有一个快速的演示,你可以在这里运行:(它使用javascript端口,但语法非常接近)
function setup() {
createCanvas(600, 500);
background(255);
noStroke();
smooth();
translate(width/16, height/16);
for (var a = 0; a < 7; a++) {
for (var b = 0; b < 7; b++) {
var ellipseSize = (b+a+1) * 7.5;
fill(color((a+b)*18));
ellipse(a * 76, b * 65, ellipseSize, ellipseSize);
}
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.4.9/p5.min.js"></script>