Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

How can I use translate() to move a shape?

$
0
0

I have used processing for a few months now. I had a question regarding the uses of Translate. I want to make it so that the grid, which I defined using vertices and beginShape(QUAD_STRIP);, lies in the center of the window. I would also like the sphere to be in the center. The code is below. Any answers?

import peasy.*;
int w = 20;
int h = 20;
int scl = 10;
float [][] grid;
PeasyCam camera;

void setup(){
  size(1000, 1000, P3D);
  grid = new float[w][h];
camera = new PeasyCam(this, 0, 0, 0, 100);
}
void draw(){
    lights();
   background (0);
      pushMatrix();
     fill(255);
   sphere(50);
   // noFill();
    noStroke();

popMatrix();

pushMatrix();

//translate(width/2, height/2, 0);
 translate(width/2, height/2 +50);
   rotateX(PI/2.8);                      //setting up perspective

   translate(-w/2, -h/2);
    for(int y = 0; y < h-1; y++) {
noFill();
stroke(255);
     beginShape(TRIANGLE_STRIP);       //preset object in Processing; I can use a net of vertices to make a strip/plane of triangles. The beginShape(); object uses any vertices to create the object specified in the argument ().
     for(int x = 0; x < w; x++){
      vertex(x*scl, y*scl, grid[x][y]);
      vertex(x*scl, (y+1)*scl,grid[x][y+1]);
     }
     endShape();
   }
popMatrix();

}

Viewing all articles
Browse latest Browse all 2896

Trending Articles