1 回答

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超8個(gè)贊
如果我沒理解錯(cuò)的話,您想在畫布上隨機(jī)位置繪制一串橢圓。我已經(jīng)回答假設(shè)這就是你要問的。如果這不是您想要的,我們深表歉意。
這個(gè)程序所做的是創(chuàng)建兩個(gè)列表來保存關(guān)于省略號(hào)的數(shù)據(jù)。我們選擇setup()隨機(jī)數(shù)量的橢圓來繪制。我們制作了那么多隨機(jī)大小和位置,然后將它們放入列表中。當(dāng)需要繪制橢圓時(shí),我們循環(huán)遍歷包含有關(guān)它們的信息的列表,并使用它來繪制許多橢圓。
const ellipseMinSize = 1;
const ellipseMaxSize = 10;
const ellipseMinAmount = 10;
const ellipseMaxAmount = 100;
// Create some lists so we can remember where the ellipses are and how big they are
var ellipseSizes = [];
var ellipsePositions = [];
function setup() {
createCanvas(500, 500);
// Choose an amount of ellipses to make
var ellipseAmount = random(ellipseMinAmount, ellipseMaxAmount);
for (var i = 0; i < ellipseAmount; i ++) {
// Choose a random size and position, then remember those
var ellipseSize = random(ellipseMinSize, ellipseMaxSize);
var ellipsePosition = createVector(random(0, width), random(0, height));
ellipseSizes.push(ellipseSize);
ellipsePositions.push(ellipsePosition);
}
}
function draw() {
background(0);
fill(255);
// Then loop through the remembered positions and sizes, and draw an ellipse with those parameters
for (var i = 0; i < ellipseSizes.length; i ++) {
var ellipseSize = ellipseSizes[i];
var ellipsePosition = ellipsePositions[i];
ellipse(ellipsePosition.x, ellipsePosition.y, ellipseSize, ellipseSize);
}
}
添加回答
舉報(bào)