【发布时间】:2021-12-16 08:43:00
【问题描述】:
您好,我在 P5.js 中使用 array() 和 randomGaussian() 创建了一个类似火花的形状。 p5.js 中的代码如下所示:
let distribution = new Array(360);
let b = false;
let x, y;
function setup() {
var cny = createCanvas(windowWidth, windowHeight);
cnv.parent("sketchholder");
for (let i = 0; i < distribution.length; i++) {
distribution[i] = floor(randomGaussian(60, 50));
}
colorMode(HSB, 255);
// hue, saturation, brightness
x = width / 4;
у = height / 3;
}
function draw() {
background(21, 30, 10);
translate(width / 2, height / 2);
strokeWeight(3);
stroke(255, 70);
line(0, 0, -x, y);
if (b) {
for (let i = 0; i < distribution.length; i++) {
rotate(TWO_PI / distribution.length);
var colorH = random(0, 255);
var colorS = random(100, 200);
var colorB = random(0, 255);
var YY = random(1, 4);
stroke(colorH, colorS, colorB);
strokeWeight(YY);
strokeCap(ROUND);
let dist = abs(distribution[i]);
line(0, 0, dist, 0);
}
}
}
我希望它沿着棍子慢慢移动,并在大约 20 秒后消失,然后到达终点。我可以在 p5.js 中实现吗?或者我可以使用 p5.js 层作为 html 中的 div 创建相同的效果并在 CSS 中对其进行动画处理吗? 谢谢。
【问题讨论】:
-
请不要发布代码截图。而是包含格式正确的代码(请参阅:meta.stackexchange.com/a/22189)。最好将您的代码发布为runnable StackSnippet。
-
@Dietrich 你是那个编辑的圣人!请其他人批准待定的编辑,它需要再批准一次。
-
@PaulWheeler 我很高兴能帮上忙! ^^