beginner_processing
YaBB Newbies
Offline
Posts: 41
Re: "frames" in processing?
Reply #8 - Apr 12th , 2010, 1:48pm
import controlP5.*; ControlP5 controlP5; int messageBoxResult = -1; ControlGroup messageBox; String messageBoxString = ""; float rotx=radians(-5), roty=radians(-20); int achl=600; int a=100, offx=0, offy=0,offz=0; int transx, transy, transz=-300; int lastWidth, lastHeight; int pfeil=6; void setup(){ size(800,600,P3D); controlP5 = new ControlP5(this); lastWidth = width; lastHeight = height; frame.setResizable(true); stroke(0); strokeWeight(1); strokeJoin(MITER); transx=width/2; transy=height/2; registerPre(this); controlP5.Button b = controlP5.addButton("toggleBox",1,20,20,100,20); b.setLabel("Toggle Box"); } void pre(){ if(width != lastWidth || height != lastHeight){ int deltaX = transx - lastWidth/2; int deltaY = transy - lastHeight/2; transx = deltaX + width/2; transy = deltaY + height/2; lastWidth = width; lastHeight = height; } } void draw(){ background(226); //camera(); // //perspective(); hint(ENABLE_DEPTH_TEST); pushMatrix(); translate(transx,transy,transz); rotateX(rotx); rotateY(roty); koordinatensystem(); //einheitswuerfel(); //punkt(150,150,150); //quadf(2,3,2); popMatrix(); hint(DISABLE_DEPTH_TEST); line(10,20,30,40); } void koordinatensystem(){ strokeWeight(1.5); beginShape(LINES); stroke(255,0,0); //z-achse rot vertex(0,0,-achl); vertex(0,0,achl); vertex(0,0,-achl); // Pfeil 1 vertex(pfeil,0,-achl+pfeil); vertex(0,0,-achl); vertex(-pfeil,0,-achl+pfeil); vertex(0,0,achl); //Pfeil 2 vertex(pfeil,0,achl-pfeil); vertex(0,0,achl); vertex(-pfeil,0,achl-pfeil); stroke(0,255,0); //y-achse grün vertex(0,-achl,0); vertex(0,achl,0); vertex(0,achl,0); // Pfeil 1 vertex(0,achl-pfeil,pfeil); vertex(0,achl,0); vertex(0,achl-pfeil,-pfeil); vertex(0,-achl,0); // Pfeil 2 vertex(pfeil,-achl+pfeil,0); vertex(0,-achl,0); vertex(-pfeil,-achl+pfeil,0); stroke(0,0,255); //x-achse blau vertex(-achl,0,0); vertex(achl,0,0); vertex(-achl,0,0); // Pfeil 1 vertex(-achl+pfeil,0,pfeil); vertex(-achl,0,0); vertex(-achl+pfeil,0,-pfeil); vertex(achl,0,0); // Pfeil 2 vertex(achl-pfeil,0,pfeil); vertex(achl,0,0); vertex(achl-pfeil,0,-pfeil); endShape();} void einheitswuerfel(){ beginShape(QUADS); noStroke(); fill(255,0,0); vertex(-a/2+offx,-a/2+offy,a/2+offz); vertex(-a/2+offx,a/2+offy,a/2+offz); vertex(a/2+offx,a/2+offy,a/2+offz); vertex(a/2+offx,-a/2+offy,a/2+offz); fill(0,255,0); vertex(-a/2+offx,-a/2+offy,a/2+offz); vertex(a/2+offx,-a/2+offy,a/2+offz); vertex(a/2+offx,-a/2+offy,-a/2+offz); vertex(-a/2+offx,-a/2+offy,-a/2+offz); fill(0,0,255); vertex(-a/2+offx,-a/2+offy,-a/2+offz); vertex(a/2+offx,-a/2+offy,-a/2+offz); vertex(a/2+offx,a/2+offy,-a/2+offz); vertex(-a/2+offx,a/2+offy,-a/2+offz); fill(255,255,0); vertex(-a/2+offx,a/2+offy,-a/2+offz); vertex(a/2+offx,a/2+offy,-a/2+offz); vertex(a/2+offx,a/2+offy,a/2+offz); vertex(-a/2+offx,a/2+offy,a/2+offz); fill(0,255,255); vertex(a/2+offx,-a/2+offy,a/2+offz); vertex(a/2+offx,-a/2+offy,-a/2+offz); vertex(a/2+offx,a/2+offy,-a/2+offz); vertex(a/2+offx,a/2+offy,a/2+offz); fill(255,0,255); vertex(-a/2+offx,-a/2+offy,-a/2+offz); vertex(-a/2+offx,a/2+offy,-a/2+offz); vertex(-a/2+offx,a/2+offy,a/2+offz); vertex(-a/2+offx,-a/2+offy,a/2+offz); endShape(); } void punkt(int px, int py, int pz){ beginShape(POINTS); strokeWeight(6); stroke(0); vertex(px,py,pz); vertex(px+20,py+20); endShape(); } void quadf(int a, int b, int c){ noFill(); strokeWeight(1); stroke(0); smooth(); beginShape(); for (float x=-250;x<250;x+=1) { vertex(x, -a*x*x - b*x - c); } endShape(); } void mouseDragged() { float factor = 0.01; if (key==CODED){ // Alt + Maus --> Rotation if(keyCode==ALT){ rotx += (pmouseY-mouseY) * factor; roty += (mouseX-pmouseX) * factor; } if(keyCode==CONTROL){ // Ctrl + Maus --> Translation transx+=(mouseX-pmouseX); transy+=(mouseY-pmouseY); } }} void keyPressed(){ if(key!=CODED){ if (key=='1'){ rotx=0; roty=0; transx=width/2; transy=height/2; transz=-300; } if (key=='3'){ rotx=0; roty=radians(-90); transx=width/2; transy=height/2; transz=-300; } if (key=='7'){ rotx=radians(-90); roty=0; transx=width/2; transy=height/2; transz=-300; } } if (key == CODED) { if(keyCode==CONTROL){ if(key=='1'){ rotx=0; roty=PI; } if(key=='3'){ rotx=0; roty=radians(90); } if(key=='7'){ rotx=radians(90); roty=0; } } } }