14
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Processingのライブラリpunktiertを使ったアニメーション

Posted at

tumblr_nqwf04DF4x1r1tpsmo1_500.gif
punktiertは、2D/3D空間上に有機的なアニメーションを搭載できるライブラリです。

比較的短いスクリプトで様々な物理エンジンが利用できます。
exampleを見るとパーティクル系が多いです。
また、ドラッグでカメラ視点を変えられるpeasycamも今回使用しました。
こちらも3D作品の際には役に立つライブラリです。

p5.pde
import peasy.PeasyCam;
import punktiert.math.Vec;
import punktiert.physics.*;

VPhysics physics;

PeasyCam cam;

public void setup() {
  size(800, 600, P3D);
  smooth();

  cam = new PeasyCam(this, 800);

  physics = new VPhysics();

  for (int i = 0; i < 1000; i++) {

    Vec pos = new Vec(0, 0, 0).jitter(1);
    Vec vel = new Vec(random(-1, 1), random(-1, 1), random(-1, 1));
    VBoid p = new VBoid(pos, vel);
    p.setRadius(20);

    p.swarm.setCohesionRadius(80);
    p.trail.setInPast(3);
    p.trail.setreductionFactor(2);
    physics.addParticle(p);

    p.addBehavior(new BCollision());

    physics.addSpring(new VSpringRange(p, new VParticle(), 300, 400, 0.0005f));
  }
}

public void draw() {
  background(240);

  physics.update();
  for (int i = 0; i < physics.particles.size(); i++) {
    VBoid boid = (VBoid) physics.particles.get(i);

    strokeWeight(5);
    stroke(0);
    point(boid.x, boid.y, boid.z);

    if (frameCount > 400) {
      boid.trail.setInPast(100);
    }
    strokeWeight(1);
    stroke(200, 0, 0);
    noFill();
    beginShape();
    for (int j = 0; j < boid.trail.particles.size(); j++) {
      VParticle t = boid.trail.particles.get(j);
      vertex(t.x, t.y, t.z);
    }
    endShape();
  }
}
14
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?