第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

加工。粒子系統(tǒng)-如何讓粒子一顆一顆的進(jìn)來(lái)

加工。粒子系統(tǒng)-如何讓粒子一顆一顆的進(jìn)來(lái)

拉風(fēng)的咖菲貓 2023-10-27 10:50:39
我試圖讓我的粒子系統(tǒng)一個(gè)接一個(gè)地生成粒子,而不是同時(shí)生成所有粒子。我的代碼目前將立即生成所有 100 個(gè)粒子。我沒(méi)有嘗試太多,因?yàn)槲沂蔷幋a新手。我有一個(gè)設(shè)置,可以調(diào)用并更新我的粒子類(lèi),以及一個(gè)包含粒子系統(tǒng)所有參數(shù)的類(lèi)。int num = 100;Particle[] p = new Particle[num];void setup() {    size(1080, 720);    colorMode(HSB);    for (int i = 0; i < num; i ++) {        p[i] = new Particle(new PVector(random(width), random(height)), 100, 150);    }    stroke(255);}void draw() {    background(0);    for (int i = 0; i < num; i ++) {        p[i].update(p, i);    }}class Particle {    PVector pos;    PVector vel;    float r, mr;    float spd = 0.1;    float max = 2;    Particle(PVector pos, float r, float mr) {        this.pos = pos;        this.r = r;        this.mr = mr;        vel = new PVector(random(-1, 1), random(-1, 1));    }    void update(Particle[] p, int i) {        float h = map(mouseX, 0, width, 0, 255);        pos.add(vel);        if (pos.x < -10) pos.x = width;        if (pos.x > width + 10) pos.x = 0;        if (pos.y < -10) pos.y = height;        if (pos.y > height + 10) pos.y = 0;        vel.x = constrain(vel.x + random(-spd, spd), -max, max);        vel.y = constrain(vel.y + random(-spd, spd), -max, max);        for (int j = i + 1; j < p.length; j ++) {            float ang = atan2(pos.y - p[j].pos.y, pos.x - p[j].pos.x);            float dist = pos.dist(p[j].pos);            if (dist < r) {                stroke(h, 255, map(dist, 0, r, 255, 0));                strokeWeight(map(dist, 0, r, 3, 0));                line(pos.x, pos.y, p[j].pos.x, p[j].pos.y);                float force = map(dist, 0, r, 4, 0);                vel.x += force * cos(ang);                vel.y += force * sin(ang);            }        }
查看完整描述

1 回答

?
浮云間

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超4個(gè)贊

創(chuàng)建一個(gè)ArrayList粒子,但不要在 中添加任何粒子setup()

ArrayList<Particle> paticles = new ArrayList<Particle>();


void setup() {

? ? size(400, 400);

? ? colorMode(HSB);

? ? stroke(255);

}

連續(xù)添加顆粒draw()。該函數(shù)millis()用于獲取自程序啟動(dòng)以來(lái)的時(shí)間:

void draw() {


? int num = 100;

? ? int interval = 100; // 0.5 seconds

? ? int time = millis();? ?// milliseconds? since starting the program

? ? if (paticles.size() < num && paticles.size()*interval+5000 < time) {

? ? ? ? paticles.add(new Particle(new PVector(random(width), random(height)), 100, 150));

? ? }


? ? background(0);

? ? for (int i = 0; i < paticles.size(); i ++) {

? ? ? ? Particle p = paticles.get(i);

? ? ? ? p.update(paticles, i);

? ? }

}?

請(qǐng)注意,該類(lèi)Particle必須進(jìn)行調(diào)整,因?yàn)樗仨毷褂肁rrayList可變長(zhǎng)度的數(shù)組而不是固定長(zhǎng)度的數(shù)組進(jìn)行操作:


class Particle {


? ? PVector pos;

? ? PVector vel;


? ? float r, mr;


? ? float spd = 0.1;

? ? float max = 2;


? ? Particle(PVector pos, float r, float mr) {

? ? ? ? this.pos = pos;

? ? ? ? this.r = r;

? ? ? ? this.mr = mr;

? ? ? ? vel = new PVector(random(-1, 1), random(-1, 1));

? ? }


? ? void update(ArrayList<Particle> paticles, int i) {

? ? ? ? float h = map(mouseX, 0, width, 0, 255);

? ? ? ? pos.add(vel);


? ? ? ? if (pos.x < -10) pos.x = width;

? ? ? ? if (pos.x > width + 10) pos.x = 0;

? ? ? ? if (pos.y < -10) pos.y = height;

? ? ? ? if (pos.y > height + 10) pos.y = 0;


? ? ? ? vel.x = constrain(vel.x + random(-spd, spd), -max, max);

? ? ? ? vel.y = constrain(vel.y + random(-spd, spd), -max, max);


? ? ? ? for (int j = i + 1; j < paticles.size(); j ++) {

? ? ? ? ? ? Particle pj = paticles.get(j);

? ? ? ? ? ? float ang = atan2(pos.y - pj.pos.y, pos.x - pj.pos.x);

? ? ? ? ? ? float dist = pos.dist(pj.pos);


? ? ? ? ? ? if (dist < r) {

? ? ? ? ? ? ? ? stroke(h, 255, map(dist, 0, r, 255, 0));

? ? ? ? ? ? ? ? strokeWeight(map(dist, 0, r, 3, 0));

? ? ? ? ? ? ? ? line(pos.x, pos.y, pj.pos.x, pj.pos.y);


? ? ? ? ? ? ? ? float force = map(dist, 0, r, 4, 0);

? ? ? ? ? ? ? ? vel.x += force * cos(ang);

? ? ? ? ? ? ? ? vel.y += force * sin(ang);

? ? ? ? ? ? }

? ? ? ? }


? ? ? ? float ang = atan2(pos.y - mouseY, pos.x - mouseX);

? ? ? ? float dist = pos.dist(new PVector(mouseX, mouseY));


? ? ? ? if (dist < r) {

? ? ? ? ? ? stroke(0, 0, map(dist, 0, r, 255, 0));

? ? ? ? ? ? strokeWeight(map(dist, 0, r, 3, 0));

? ? ? ? ? ? line(pos.x, pos.y, mouseX, mouseY);


? ? ? ? ? ? float force = map(dist, 0, r, 30, 0);

? ? ? ? ? ? vel.x += force * cos(ang);

? ? ? ? ? ? vel.y += force * sin(ang);

? ? ? ? }

? ? ? ? noStroke();

? ? ? ? fill(h, 255, 255);

? ? ? ? ellipse(pos.x, pos.y, 5, 5);

? ? }

}



查看完整回答
反對(duì) 回復(fù) 2023-10-27
  • 1 回答
  • 0 關(guān)注
  • 117 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)