Tonderai’s Cube code

 
import processing.opengl.*;
import javax.media.opengl.*; 
 
void setup()
{
   size(600, 600, OPENGL); 
 
}
 
void draw()
{
   background(255);
   strokeWeight(5);
 
    // camera control
  beginCamera();
  if (keyPressed)
  {
    if (key == 'w')
      translate(0, 0, -10);
    if (key == 's')
      translate(0, 0, 10);
    if (key == 'a')
      translate(-10, 0, 0);
    if (key == 'd')
      translate(10, 0, 0);
 
 
  }
  if (mousePressed)
  {
    // pitch
    rotateX((PI/16)*float(mouseY-pmouseY)/300);
    // yaw
    rotateY(-(PI/16)*float(mouseX-pmouseX)/300);
  }
  endCamera();
 
 
 
  PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;  // g may change
  GL gl = pgl.beginGL();  // always use the GL object returned by beginGL
 
  gl.glColor3f(1, 0, 0);
 
  gl.glBegin(GL.GL_TRIANGLE_STRIP);
  gl.glVertex3f(200, 200, -200);//front
  gl.glVertex3f(200, 400, -200);
  gl.glVertex3f(400, 200, -200);
  gl.glVertex3f(400, 400, -200);
 
  gl.glVertex3f(200, 200, -400);//further back
  gl.glVertex3f(200, 400, -400);
  gl.glVertex3f(400, 200, -400);
  gl.glVertex3f(400, 400, -400);
 
  gl.glVertex3f(400, 200, -200);//right
  gl.glVertex3f(400, 400, -200);
  gl.glVertex3f(400, 200, -400);
  gl.glVertex3f(400, 400, -400);
 
  gl.glVertex3f(200, 200, -200);//left
  gl.glVertex3f(200, 400, -200);
  gl.glVertex3f(200, 200, -400);
  gl.glVertex3f(200, 400, -400);
 
  gl.glVertex3f(200, 400, -200);//bottom
  gl.glVertex3f(200, 400, -400);
  gl.glVertex3f(400, 400, -200);
  gl.glVertex3f(400, 400, -400);
 
  gl.glVertex3f(200, 200, -200);//right
  gl.glVertex3f(200, 200, -400);
  gl.glVertex3f(400, 200, -200);
  gl.glVertex3f(400, 200, -400);
 
 
 
 
 
 
  gl.glEnd();
 
  pgl.endGL();
 
}
Create PDF    Send article as PDF to