当他们移动窗口时,我如何增加一行椭圆的大小?我想让它看起来就像它们到达窗户的底部,它们变大了。
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);
}
}
答案 0 :(得分:1)
ellipse()功能的最后两个参数允许您控制宽度和高度:
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>