乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      用Processing寫(xiě)一個(gè)簡(jiǎn)單的Flowfield流場(chǎng)

       g_memory 2017-07-19



      實(shí)例代碼出處:flowfield - OpenProcessing

      但是,寫(xiě)的有點(diǎn)啰嗦,我做了精簡(jiǎn),加了注釋

      原理:

      每一個(gè)流動(dòng)的粒子,含有一下屬性


      loc 位置

      dir 方向

      vel 速率


      在實(shí)時(shí)的計(jì)算中,每一幀每一個(gè)粒子都進(jìn)行以下運(yùn)算

      void move() {//perlin噪聲的三個(gè)參數(shù),分別是xy坐標(biāo)和當(dāng)前幀總數(shù)(也可以理解為時(shí)間)//這樣時(shí)空之間變建立起轉(zhuǎn)換規(guī)則,轉(zhuǎn)換為弧度 float angle=noise(loc.x/500, loc.y/500, frameCount/500);//方向的x,y坐標(biāo)分別用時(shí)空轉(zhuǎn)換來(lái)的弧度計(jì)算余弦和正弦   dir.x = cos(angle); dir.y = sin(angle);//方向用作速率(其實(shí)就是速度了,因?yàn)檫@里有方向)    vel = dir.get();//每一個(gè)粒子每一幀都乘以speed這個(gè)變量放大一下,算是簡(jiǎn)單的加速度    vel.mult(speed);//位置加上速度進(jìn)行更新    loc.add(vel);}


      歡迎付費(fèi)咨詢

      插個(gè)廣告


      做人要酷,這個(gè)夏天你要不要學(xué)一點(diǎn)C++順便做點(diǎn)藝術(shù)作品?


      2017年夏算法藝術(shù)實(shí)驗(yàn)室Processing基礎(chǔ)入門(mén)線上課程


      修改過(guò)后添加注釋的代碼:

      //粒子數(shù)int num = 1000;//存放粒子的數(shù)組Particle[] particles = new Particle[num];void setup() {  size(1024, 728);  noStroke();//迭代生成所有粒  for (int i=0; ium; i++) {    PVector loc = new PVector(random(width*1.2), random(height));   float angle = random(TWO_PI);   PVector dir = new PVector(cos(angle), sin(angle));    float speed = random(.5, 2);   particles[i]= new Particle(loc, dir, speed);  }}void draw() {//半透明背景 fill(0, 10);  noStroke(); rect(0, 0, width, height);  fill(255, 155); //遍歷數(shù),一個(gè)子都run起來(lái) for (int i=0; ingth; i++) { particles[i].run();  }}//粒子數(shù)據(jù)類(lèi)型class Particle {//屬性  PVector loc, dir, vel; float speed;  color col;//構(gòu)造函數(shù)  Particle(PVector _loc, PVector _dir, float _speed) {    loc = _loc;  dir = _dir;    speed = _speed;  }//運(yùn)動(dòng),渲染,越界函數(shù)在一個(gè)函數(shù)里  void run() {   move(); checkEdges();   render();  }//運(yùn)動(dòng)函數(shù)  void move() {   float angle=noise(loc.x/500, loc.y/500, millis()/10000)*TWO_PI; dir.x = cos(angle);    dir.y = sin(angle);   vel = dir.get();   vel.mult(speed);    loc.add(vel);  }//口就隨機(jī)一個(gè)窗內(nèi)位置 void checkEdges() {    if (loc.x<0 || loc.x>width || loc.y<0 || loc.y>height) {        loc.x = random(width*1.2);   loc.y = random(height);    } } void render() {   ellipse(loc.x, loc.y, 2, 2);  }}




        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類(lèi)似文章 更多