加工颗粒 [英] Processing Particle

查看:62
本文介绍了加工颗粒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试用这个项目做点什么,但到目前为止总是失败:) 所以决定在这里问:)

I've been trying to do something with this project I have but failed always so far :) so decided to ask here :)

我希望粒子围绕 Rock 类的椭圆,而不是穿过它而是围绕它,就像河流中的一块石头,水在它周围流动.有什么建议么 ?

I want the particles to go around the ellipse from Rock class, not through it but around it, like a rock inside a river that water flows around it. Any suggestions ?

int NUM_PARTICLES = 1000;
ParticleSystem p;
Rock r;
void setup()
{
  smooth();
  fullScreen(P2D);
  //size(700,700,P2D);
  //background(0);
  p = new ParticleSystem();
  r = new Rock();
}

void draw()
{
  background(0);
  p.update();
  p.render();
  r.rock();

}

float speed = 1;
class Particle
{
  PVector position, velocity;

  Particle()
  {
    position = new PVector(random(width),random(height));
    velocity = new PVector();
  }

  void update()
  {
    velocity.x = speed*(noise(position.y));
    velocity.y = speed*(noise(position.x));
    position.add(velocity);

    if(position.x<0)position.x+=width;
    if(position.x>width)position.x-=width;
    if(position.y<0)position.y+=height;
    if(position.y>height)position.y-=height;
  }

  void render()
  {
    stroke(0, 0, 255, 80);
    line(position.x,position.y,position.x-velocity.x,position.y-velocity.y);
  }
}

class ParticleSystem
{
  Particle[] particles;

  ParticleSystem()
  {
    particles = new Particle[NUM_PARTICLES];
    for(int i = 0; i < NUM_PARTICLES; i++)
    {
      particles[i]= new Particle();
    }
  }

  void update()
  {
    for(int i = 0; i < NUM_PARTICLES; i++)
    {
      particles[i].update();
    }
  }

  void render()
  {
    for(int i = 0; i < NUM_PARTICLES; i++)
    {
      particles[i].render();
    }
  }
}
class Rock{

  void rock()
  {
  noFill();
  stroke(255);
  strokeWeight(4);
  ellipse(mouseX,mouseY,50,50);

}



}

1

昨天我自己做了一些工作,我接近我想要的,但仍然有一些视觉问题.我想摆脱流的边缘,当我移动鼠标时,我仍然可以看到力的椭圆线.这是结果.

I did some work of my own on it yesterday and i am close to what I want, still got some visual issues.I want to get rid of the edges of the flow and when I move the mouse I can still see the lines of the ellipse from the force. Here is the result.

int NUM_PARTICLES = 9000;
ParticleSystem p;
Rock r;
void setup()
{
  smooth();
  size(700,700,P2D);
  p = new ParticleSystem();
  r = new Rock();
}

void draw()
{
  background(0);
  p.update();
  p.render();
  r.rock();

}

float speed = 2;
float rad = 100;
class Particle
{
  PVector position, velocity;
  float initialPosY;

  Particle()
  {
    position = new PVector(random(width), random(height));
    initialPosY = position.y;
    velocity = new PVector();
  }

  void update()
  {

    velocity.x = speed;
    velocity.y = 0;

    float d = dist (position.x, position.y, mouseX, mouseY);
    if (d < rad) {
      float force = map(d, 0, rad, speed, 0);
      if (position.x < mouseX) {
        if (position.y < mouseY) {
          velocity.y = -force;
        } else {
          velocity.y = force;
        }
      } else {
        if (position.y < mouseY) {
          velocity.y = force;
        } else {
          velocity.y = -force;
        }
      }
      position.add(velocity);
    } else {
      position = new PVector(position.x+speed, initialPosY);
    }



    if (position.x<0)position.x+=width;
    if (position.x>width)position.x-=width;
    if (position.y<0)position.y+=height;
    if (position.y>height)position.y-=height;
  }

  void render()
  {
    stroke(255, 255, 255, 80);
    point(position.x, position.y);
  }
}

class ParticleSystem
{
  Particle[] particles;

  ParticleSystem()
  {
    particles = new Particle[NUM_PARTICLES];
    for (int i = 0; i < NUM_PARTICLES; i++)
    {
      particles[i]= new Particle();
    }
  }

  void update()
  {
    for (int i = 0; i < NUM_PARTICLES; i++)
    {
      particles[i].update();
    }
  }

  void render()
  {
    for (int i = 0; i < NUM_PARTICLES; i++)
    {
      particles[i].render();
    }
  }
}

class Rock{

  void rock()
  {
  noFill();
  stroke(255);
  strokeWeight(4);
  ellipse(mouseX,mouseY,50,50);

}



}

推荐答案

我昨天做了一些自己的工作,我已经接近我想要的,仍然有一些视觉问题.我想摆脱边缘当我移动鼠标时,我仍然可以从力中看到椭圆的线条.这是结果.

I did some work of my own on it yesterday and i am close to what I want, still got some visual issues.I want to get rid of the edges of the flow and when I move the mouse I can still see the lines of the ellipse from the force. Here is the result.

int NUM_PARTICLES = 9000;
ParticleSystem p;
Rock r;
void setup()
{
  smooth();
  size(700,700,P2D);
  p = new ParticleSystem();
  r = new Rock();
}

void draw()
{
  background(0);
  p.update();
  p.render();
  r.rock();

}

float speed = 2;
float rad = 100;
class Particle
{
  PVector position, velocity;
  float initialPosY;

  Particle()
  {
    position = new PVector(random(width), random(height));
    initialPosY = position.y;
    velocity = new PVector();
  }

  void update()
  {

    velocity.x = speed;
    velocity.y = 0;

    float d = dist (position.x, position.y, mouseX, mouseY);
    if (d < rad) {
      float force = map(d, 0, rad, speed, 0);
      if (position.x < mouseX) {
        if (position.y < mouseY) {
          velocity.y = -force;
        } else {
          velocity.y = force;
        }
      } else {
        if (position.y < mouseY) {
          velocity.y = force;
        } else {
          velocity.y = -force;
        }
      }
      position.add(velocity);
    } else {
      position = new PVector(position.x+speed, initialPosY);
    }



    if (position.x<0)position.x+=width;
    if (position.x>width)position.x-=width;
    if (position.y<0)position.y+=height;
    if (position.y>height)position.y-=height;
  }

  void render()
  {
    stroke(255, 255, 255, 80);
    point(position.x, position.y);
  }
}

class ParticleSystem
{
  Particle[] particles;

  ParticleSystem()
  {
    particles = new Particle[NUM_PARTICLES];
    for (int i = 0; i < NUM_PARTICLES; i++)
    {
      particles[i]= new Particle();
    }
  }

  void update()
  {
    for (int i = 0; i < NUM_PARTICLES; i++)
    {
      particles[i].update();
    }
  }

  void render()
  {
    for (int i = 0; i < NUM_PARTICLES; i++)
    {
      particles[i].render();
    }
  }
}

class Rock{

  void rock()
  {
  noFill();
  stroke(255);
  strokeWeight(4);
  ellipse(mouseX,mouseY,50,50);

}



}

这篇关于加工颗粒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆