How do I change where the drawing is happening

My code:

float x = 0.10;

float y = 0.0;
float z = 0.0;

float a = 10;
float b = 28;
float c = 8.0/3.0;

ArrayList<PVector> points = new ArrayList<PVector>();


void setup() {
  size(800, 600);
  colorMode(HSB);

}

void draw() {
  background(0);
  float dt = 0.01;
  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;

  points.add(new PVector(x, y, z));
  
  scale(5);
  stroke(255);
  noFill();
  beginShape(); 
  
  float hu = 0;
  for (PVector v : points) {
    stroke(hu, 255, 255);
    vertex(v.x-1, v.y-1);
    hu += 0.1;
    if (hu > 255) {
      hu = 0; 
    }
    
  }
  endShape();
  //println(x, y, z);
}

Hi, I am new to processing and I was making the lorenz attractor similar to the video of Daniel Shiffman on YouTube.

It was made in 3d but I want to create it into 2D because I am working on another project.
I found that just getting rid of the peasycam and P3D option is ok but when I ran the program it was showing the program on the top left on the screen what exactly should I change.

If you want to know why I am doing this in 2D because I want to do some tests for the future because I want to get the simulation in the console using the Rust Programming language.

1 Like

just use translate()


float x = 0.10;
float y = 0.0;
float z = 0.0;

float a = 10;
float b = 28;
float c = 8.0/3.0;

ArrayList<PVector> points = new ArrayList<PVector>();


void setup() {
  size(1200, 600);
  colorMode(HSB);

  //x+=width/2.0; 
  //y+=height/2.0;
}

void draw() {
  background(0);

  float dt = 0.01;
  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;

  points.add(new PVector(x, y));

  translate(width/2, height/2);
  scale(5);
  stroke(255);
  noFill();
  beginShape(); 

  float hu = 0;
  for (PVector v : points) {
    stroke(hu, 255, 255);
    vertex(v.x, v.y);
    hu += 0.1;
    if (hu > 255) {
      hu = 0;
    }
  }
  endShape();
  //println(x, y, z);
}

1 Like

Thanks bro

But can You tell me what can i do without the translate function because in Rust there are no libraries that suppourt translate.

All translate does is move your pvectors to an alternative point.

So by having

vertex(x+xoffset, y+yoffset) ;


Where the offset are variables you control, should do the trick

How would I implement that because when I try doing it, it moves the whole shape

Check out the resources (tutorials, examples, examples and more…) here:
https://processing.org/

For starters:
2D Transformations / Processing.org

I often move the origin to center of canvas at the start of the sketch:

translate(width/2, height/2);

:)

Declare your offsets in your sketch and add assign values you feel are appropriate thats it. And add offsetx and offsety to your vertex.

Its honestly that simple.

No bro I cant get it can you post the code

Edit:
Thanks I got it

I will let you know more

3 Likes