Convert p5js to Processing

there are small points that had to be fixed and I thought it’s easier to show the fix rather than explaining each points so I just give you the “answer” :slight_smile:

float rotx;
float roty;
float rotz;
int axisx;
int axisy;
float axisz;
LineSystem line_system;
boolean drawing = false;
void setup () {
  size (800, 800, P3D);
  colorMode (RGB, 256);
  background (0);
  rotx = 0.0;
  roty = 0.0;
  rotz = 0.0;
  axisx = 0;
  axisy = 0;
  axisz = 0.0;
  line_system = new LineSystem ();
}
void draw () {
  background (0);
  translate(width / 2, height / 2);
  translate (axisx, axisy, axisz);
  rotateX (rotx);
  rotateY (roty);
  rotateZ (rotz);
  rotx += 0.06;
  roty += 0.00;
  rotz += 0.00;
  line_system.update ();
  line_system.render ();
  strokeWeight (2);
  stroke (255, 0, 0);
  line (-960, 0, 0, 960, 0, 0);
  stroke (0, 255, 0);
  line (0, -540, 0, 0, 540, 0);
}
void mousePressed () {
  drawing = true;
  line_system = new LineSystem ();
}
void mouseReleased () {
  drawing = false;
}


class LineSystem {
  ArrayList<LineCreate> line_create = new ArrayList<LineCreate>();
  float x = (mouseX - (width / 2)) * cos (roty);
  float y = (mouseY - (height / 2)) * cos (rotx);
  float z = (mouseX - (width / 2)) * cos ((PI / 2) - roty) - (mouseY - (height / 2)) * cos ((PI / 2) - rotx);
  float targetx = 0.0;
  float targety = 0.0;
  float targetz = 0.0;
  float easing = 0.1;
  boolean create = true;
  
  LineSystem () {
  line_create.add(new LineCreate (x, y, z));
  }

  void update () {
    targetx = (mouseX - (width / 2)) * cos (roty);
    targety = (mouseY - (height / 2)) * cos (rotx);
    targetz = (mouseX - (width / 2)) * cos ((PI / 2) - roty) - (mouseY - (height / 2)) * cos ((PI / 2) - rotx);
    x += (targetx - x) * easing;
    y += (targety - y) * easing;
    z += (targetz - z) * easing;
    if (drawing == true) {
      line_create.add (new LineCreate (x, y, z));
    }
  }
  void render () {
    for (int i = 0; i < line_create.size(); i++) {
      if (i > 0) {
        LineCreate line_prev = line_create.get(i - 1);
        LineCreate line_next = line_create.get(i);
        stroke (255, 255, 255);
        strokeWeight (dist (line_prev.x, line_prev.y, line_prev.z, line_next.x, line_next.y, line_next.z) / 4.0);
        line (line_prev.x, line_prev.y, line_prev.z, line_next.x, line_next.y, line_next.z);
      }
    }
  }
}
class LineCreate {
  float x, y, z;
  LineCreate (float ax, float ay, float az) {
    this.x = ax;
    this.y = ay;
    this.z = az;
  }
}
3 Likes