Jump to Content

RSS Feeds:

Posts | Comments

http://ivanwlam.com/experiments/programming

Leave a Reply


Example

The images in these examples shift depending on mouse positions.

Processing Code in Example

 import processing.opengl.*;    PFont font;    void setup(){   size(500,500,P3D);     font=createFont("Franklin Gothic Demi",30,false);   textFont(font,15);  }    void draw(){   background(196);   pushMatrix();   pushStyle();   translate(258,248,0);   float rotX=mouseX/100.0;   float rotY=mouseY/100.0;   rotateX(-rotY);   rotateY(-rotX);   smooth();   noFill();   box(200);   translate(100,100,0);   sphere(100);   popStyle();   popMatrix();   text("mouseX:"+mouseX+" mouseX/100:"+rotX,10,height-30);   text("mouseY:"+mouseY+" mouseY/100:"+rotY,10,height-10);      }    void mouseClicked(){   saveFrame("output.jpg");  }

Processing Code in Example

 PFont font;    void setup(){   size(1000,750,P3D);  // noFill();   font=loadFont("CourierNewPSMT-12.vlw");   textFont(font);  }    void draw(){   background(196);     beginCamera();   camera(width/2.0,0,(height/2.0)/tan(PI*60.0/360.0),   width/2.0,height/2.0,0,   0,1,0);   rotateX((-height/2+mouseY)/75.0);   rotateY((width/2-mouseX)/100.0);   endCamera();     pushMatrix();   pushStyle();   translate(0,height/2,0);   rotateX(PI/2);   fill(128,0,0);   rect(0,0,width,height);   popStyle();   popMatrix();     pushMatrix();   pushStyle();   translate(100,100,0);   fill(255,0,0);   box(100);   translate(100,100,100);   fill(0,255,0);   box(100);   translate(100,100,100);   fill(0,0,255);   box(100);   popStyle();   popMatrix();     pushMatrix();   translate(width/2.0,height/2.0,0);   sphere(20);   popMatrix();     pushMatrix();   translate(width/2.0,0,(height/2.0)/tan(PI*60.0/360.0));   sphere(1000);   popMatrix();     pushMatrix();   pushStyle();   translate(width/2.0,0,(height/2.0)/tan(PI*60.0/360.0));     pushMatrix();   fill(200,200,255);   translate(0,0,-1000);   drawOuterRect();   translate(0,0,2000);   drawOuterRect();   popMatrix();     fill(255,200,200);   pushMatrix();   rotateX(-PI/2);   translate(0,0,1000);   drawOuterRect();   translate(0,0,-2000);   drawOuterRect();   popMatrix();     fill(200,255,200);   pushMatrix();   rotateY(-PI/2);   translate(0,0,1000);   drawOuterRect();   translate(0,0,-2000);   drawOuterRect();   popMatrix();     popStyle();   popMatrix();         fill(0);   beginCamera();   camera();   rotateX(0);   rotateY(0);   endCamera();   text("mouseX:"+mouseX+" | mouseY:"+mouseY,10,height-20);   noFill();  }    void drawOuterRect(){   rect(-width,-height,2000,2000);  }