# How to go from plane to 3D

``````float t=1;
void setup() {
size(800, 800);
}

void draw() {
background(0);
noStroke();
fill(255);
translate(width/2, height/2);

for (int i = 0; i < 100; i++) {
float x = width/4 * sin(t*i*PI*2);
float y = height/4 * sin(t*i*PI*3);
rect(x,y,2,2);
}
t += 0.00001;
}
``````

Hello,
I have this system of equations that cause the points to move like on a Lissajous curve. I’m trying to add a third dimension to it and be able to change the point of view of the camera to visualize what is happening.
I understand that I have to change rectangles to cubes and add a variable z, but I don’t know how to do it. I have tried something with Peasycam but I don’t know how to change the position of the cubes.
Any help or idea?
Thank you very much

Hello @Karrajo,

For starters you need to work with the P3D renderer.

Some tutorials and references to get you started:
https://processing.org/tutorials/rendering
https://processing.org/reference/size_.html
https://processing.org/tutorials/p3d

Interesting topic:

I suggest you start simple and build on that…

Some modifications to your code for P3D to give you some ideas:

``````float t=1;
void setup() {
size(800, 800, P3D);
}

void draw() {
background(0);
noStroke();
fill(255);
lights();

int counter = (frameCount-1)%720; // 0 to 719 and repeats
float angle = counter*(TAU/720);
// println(frameCount, counter, angle, degrees(angle)); // Testing

translate(width/2, height/2);
rotateX(angle);

for (int i = 0; i < 100; i++) {
float x = width/4 * sin(t*i*PI*2);
float y = height/4 * sin(t*i*PI*3);
float z = 200*sin(t*i*PI*4);
//rect(x, y, 2, 2);
stroke(0, 255, 0);
strokeWeight(5);

point(x+20, y+20, z+20); // offset by 20 so the sphere did not cover it

push();
translate(x, y, z);
noStroke();
sphere(10);
pop();

}
t += 0.00001;
}
``````

I really had to throttle back on the example I provided since this is your journey.

Have fun!

`:)`

1 Like

Omg, glv, thank you very much,
your code is incredible but also with the references I can continue to go deeper into the code. Thank you very much

1 Like