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

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

需要幫助將我的處理代碼轉(zhuǎn)換為 p5.js(ArrayList + 其他?。?/h1>

我是 Processing 和 p5.js 的新手,正在嘗試將此代碼從 Processing 轉(zhuǎn)換為 p5,但沒(méi)有成功。我遇到的主要問(wèn)題是第 21 和 26 行的 ArrayList,以及 ParticleSystem 類(lèi)中的函數(shù)。注意:我知道這可能是一個(gè)非常菜鳥(niǎo)的問(wèn)題,但是我已經(jīng)嘗試了很多方法,但似乎沒(méi)有任何效果,因此我向你們尋求幫助。這是工作處理代碼:ParticleSystem ps;void setup() {    size(1200, 800);    ps = new ParticleSystem(new PVector(width/2, 50));    for (int i=0; i<1200; i++) {        ps.addParticle();    }}void draw() {    background(255);    ps.move_away_from(mouseX, mouseY);    ps.run();}class ParticleSystem {    ArrayList<Particle> particles;    PVector origin;    ParticleSystem(PVector position) {        origin = position.copy();        particles = new ArrayList<Particle>();    }    void addParticle() {        particles.add(new Particle(origin));    }    void run() {        for (int i = particles.size()-1; i >= 0; i--) {            Particle p = particles.get(i);            p.run();      //      if (p.isDead()) {              //    particles.remove(i);      //      }        }    }    void move_away_from( float x, float y){        for(Particle p : particles){            float d = dist(x,y,p.position.x, p.position.y);            if( d < 200 ){                 p.velocity.x += map(d,0,200,0.5,0.1)*(p.position.x - x);                p.velocity.y += map(d,0,200,0.5,0.1)*(p.position.y - y);            }        }    }}class Particle {    PVector position;    PVector velocity;    PVector acceleration;    PVector home;    Particle(PVector l) {        acceleration = new PVector(0, 0);        velocity = new PVector(0,0);//random(-0.0001, 0.00001), random(-0.001, 0.0001));        l=new PVector(random(0, 1200), random(0, 800));        position = l.copy();        home = position.copy();    }    void run() {        update();        display();    }因此,如果有人有解決方案或可以告訴我我需要采取的步驟,請(qǐng)告訴我!
查看完整描述

1 回答

?
aluckdog

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

在 JavaScript 中,您根本不需要像 an 之類(lèi)的東西ArrayList。JavaScript 數(shù)組是動(dòng)態(tài)的。此外,沒(méi)有必要聲明屬性。當(dāng)分配了某些東西時(shí),屬性會(huì)自動(dòng)“創(chuàng)建”。


PVector您可以使用 uss代替對(duì)象p5.Vector。Ap5.Vector由createVector. 此外,請(qǐng)閱讀JavaScript 中的類(lèi)。


看例子:


class Particle {

  

    constructor(l) {

        this.acceleration = createVector(0, 0);

        this.velocity = createVector(0,0);//random(-0.0001, 0.00001), random(-0.001, 0.0001));

        this.position = l ? l.copy() : createVector(Math.random()*1200, Math.random()*1200,);

        this.home = this.position.copy();

    }


    run() {

        this.update();

        this.display();

    }


    // Method to update position

    update() {

        this.acceleration.x = -0.01*(this.position.x - this.home.x);

        this.acceleration.y = -0.01*(this.position.y - this.home.y);

        this.velocity.add(this.acceleration);

        this.velocity.mult(0.9);

        this.position.add(this.velocity);

        //   lifespan -= 1.0;

    }


    // Method to display

    display() {

        noStroke();//stroke(255, lifespan);

        //fill(255, lifespan);

        fill(0);

        ellipse(this.position.x, this.position.y, 25, 25);

    }

}


class ParticleSystem {

    constructor(position) {

        this.origin = position.copy();

        this.particles = [];

    }


    addParticle() {

        //this.particles.push(new Particle(this.origin));

        this.particles.push(new Particle());

    }


    run() {

        for (let i = this.particles.length-1; i >= 0; i--) {

            this.particles[i].run();

    //      if (p.isDead()) {

            //    particles.remove(i);

    //      }

        }

    }


    move_away_from(x, y){

        for (let i = 0; i < this.particles.length; i++) {

            let p = this.particles[i];

            let d = dist(x,y, p.position.x, p.position.y);

            if( d < 200 ){ 

                p.velocity.x += map(d,0,200,0.5,0.1)*(p.position.x - x);

                p.velocity.y += map(d,0,200,0.5,0.1)*(p.position.y - y);

            }

        }

    }

}


var ps;


function setup() {

    createCanvas(1200, 800);

    ps = new ParticleSystem(createVector(width/2, 50));

    for (var i=0; i<1200; i++) {

        ps.addParticle();

    }

}


function draw() {

    background(255);

    ps.move_away_from(mouseX, mouseY);

    ps.run();

}

<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.js"></script>


查看完整回答
反對(duì) 回復(fù) 2021-12-02
  • 1 回答
  • 0 關(guān)注
  • 218 瀏覽
慕課專(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)