gpt4 book ai didi

p5.js - 是否可以更改粒子颜色?

转载 作者:行者123 更新时间:2023-12-04 07:43:07 25 4
gpt4 key购买 nike

是否可以将粒子颜色更改为任何颜色?
因为我只有一种颜色,我想更改它以使其更适合 Spring ,所以有没有办法根据您的口味配置颜色,以下是我的功能代码:

function Particle() {
this.pos = createVector(random(width), random(height));
this.vel = createVector(0, 0);
this.acc = createVector(0, 0);
this.maxspeed = 4;
this.h = 100;

this.prevPos = this.pos.copy();

this.update = function() {
this.vel.add(this.acc);
this.vel.limit(this.maxspeed);
this.pos.add(this.vel);
this.acc.mult(0);
}

this.follow = function(vectors) {
var x = floor(this.pos.x / scl);
var y = floor(this.pos.y / scl);
var index = x + y * cols;
var force = vectors[index];
this.applyForce(force);
}

this.applyForce = function(force) {
this.acc.add(force);
}

this.show = function() {
strokeWeight(6);
stroke(255, this.h, 10);
this.h = this.h + 1;
if (this.h > 255) {
this.h = 100;
}
strokeWeight(8);
line(this.pos.x, this.pos.y, this.prevPos.x, this.prevPos.y);
this.updatePrev();
}

this.updatePrev = function() {
this.prevPos.x = this.pos.x;
this.prevPos.y = this.pos.y;
}

this.edges = function() {
if (this.pos.x > width) {
this.pos.x = 0;
this.updatePrev();
}
if (this.pos.x < 0) {
this.pos.x = width;
this.updatePrev();
}
if (this.pos.y > height) {
this.pos.y = 0;
this.updatePrev();
}
if (this.pos.y < 0) {
this.pos.y = height;
this.updatePrev();
}
}
}

最佳答案

调用 stroke(255, this.h, 10)show函数决定了 Particle 绘制的线条的颜色。在这种情况下类。看起来它正在从红色循环到黄色。笔画函数是well documented .您当然可以使用它使本示例中绘制的线条成为您想要的任何颜色。您可以在 p5js.org 上了解有关 p5js 中颜色的更多信息.

关于p5.js - 是否可以更改粒子颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67344585/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com