peasycam

Processing 3


import peasy.*;
PeasyCam cam;

Attractor att, att2, att3;

void setup() {
  size(540, 540, P3D);
//  ortho(-width/2, width/2, -height/2, height/2);
  cam = new PeasyCam(this, 500);
  att = new Attractor(0.01, 0.0, 0.0, 0.01); //x, y, z, dt
  att2 = new Attractor(0.1, 0.0, 0.0, 0.01);
  att3 = new Attractor(0.1, 0.0, 0.0, 0.05);
}

void draw() {
  background(0);
  att.lorenz(10, 28, 8.0/3.0); //param a, b, c
  att.point_draw(0, 135, -80, 2); //x_position, ypos, zpos, *scale
  att.line_draw(0, -135, -80, 2);
  att2.aizawa(0.95, 0.7, 0.6, 3.5, 0.25, 0.1); //param a, b, c, d, e, f
  att2.line_draw(-135, 0, -80, 40);
  att3.thomas(0.19); //param b
  att3.line_draw(135, 0, -80, 14);
}

class Attractor {
  float x, y, z;
  float dt;
  ArrayList<PVector> points;

  Attractor(float _x, float _y, float _z, float _dt) {
    x = _x;
    y = _y;
    z = _z;
    dt = _dt;
    points = new ArrayList<PVector>();
  }

  void lorenz(float _a, float _b,float _c) {
    float a = _a;
    float b = _b;
    float c = _c;
    float dx = (a*(y - x))*dt;
    float dy = (x*(b - z) - y)*dt;
    float dz = (x*y - c*z)*dt;
    x = x + dx;
    y = y + dy;
    z = z + dz;
  }
  void aizawa(float _a, float _b,float _c, float _d,float _e, float _f) {
    float a = _a;
    float b = _b;
    float c = _c;
    float d = _d;
    float e = _e;
    float f = _f;
    for (int i = 0; i < 3; i = i+1) {
    float dx = ((z - b)*x - d*y)*dt;
    float dy = (d*x + (z - b)*y)*dt;
    float dz = (c + a*z - (pow(z,3)/3) - (pow(x,2) + pow(y,2))*(1 + e*z)+f*z*pow(x,3))*dt;
    x = x + dx;
    y = y + dy;
    z = z + dz;
    }
  }
  void thomas(float _b) {
    float b = _b;
    for (int i = 0; i < 3; i = i+1) {
    float dx = (-b*x + sin(y))*dt;
    float dy = (-b*y + sin(z))*dt;
    float dz = (-b*z + sin(x))*dt;
    x = x + dx;
    y = y + dy;
    z = z + dz;
    }
  }

  void line_draw(float _xpos, float _ypos, float _zpos, float _size) {
    points.add(new PVector(x*_size, y*_size, z*_size));

    pushMatrix();
      translate(_xpos, _ypos, _zpos);
      stroke(255);
      strokeWeight(2);
      noFill();

      beginShape();
        for (PVector v : points) {
        stroke(255, 50);
        vertex(v.x, v.y, v.z);
        }
      endShape();
    popMatrix();
  }
  void point_draw(float _xpos, float _ypos, float _zpos, float _scale) {
    points.add(new PVector(x*_scale, y*_scale, z*_scale));

    pushMatrix();
      translate(_xpos, _ypos, _zpos);
      stroke(255);
      strokeWeight(1);
      noFill();

      for (PVector v : points) {
        stroke(255, random(196));
        point(v.x, v.y, v.z);
      }
    popMatrix();
  }
}

<>が消える