Code for example exam

        import processing.opengl.*;
	import javax.media.opengl.*; 
 
	PVector position;
	float angle = 0.0;
 
	void setup()
	{
	   size(500, 500, OPENGL); 
	   position = new PVector(0, 0, 0);
	}
 
	void draw()
	{
	  background(255);
 
	  keyboardInput();
 
	  PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;  
	  GL gl = pgl.beginGL();  
 
	  gl.glColor3f(1, 0, 0);
	  gl.glRotatef(angle, 0, 0, 1);
	  gl.glTranslatef(position.x, position.y, 0);
	  drawSquare(gl);
 
	  gl.glColor3f(0, 1, 0);
	  gl.glTranslatef(300, 200, 0);
	  drawSquare(gl);
 
	  pgl.endGL();
	}  
 
 
 
 
	void keyboardInput()
	{
		if (keyPressed)
		  {
		    if (key == 'w')
		      position.y -= 1;
		    if (key == 's')
		      position.y += 1;
		    if (key == 'a')
		      position.x -= 1;
		    if (key == 'd')
		      position.x += 1;
 
		    if(key =='o')
		      angle -= 0.1;
		    if(key == 'p')
		      angle += 0.1;
		  }
	}
 
	void drawSquare(GL gl)
	{
	   gl.glBegin(GL.GL_TRIANGLE_STRIP);
	    gl.glVertex3f(-50,  50, -100);
	    gl.glVertex3f(-50, -50, -100);
	    gl.glVertex3f( 50,  50, -100);
	    gl.glVertex3f( 50, -50, -100);
	  gl.glEnd();   
	}
PDF Printer    Send article as PDF to