Royce3
YaBB Newbies
Offline
Posts: 5
Re: Applet start failed: class not found
Reply #2 - Dec 19th , 2007, 11:01pm
import processing.opengl.*; float rotx = PI/4; float roty = PI/4; ToroidParams toroid; PFont f; boolean play = false; int lastmillis = 0; int time = 0; void setup() { lastmillis = millis(); size(640, 480, P3D); fill(255); noStroke(); f = loadFont("Verdana-10.vlw"); textFont(f,10); toroid = new ToroidParams(); toroid.isHelix = true; } void draw() { background(0); lights(); pushMatrix(); translate(width/2.0, height/2.0, -100); rotateX(rotx); rotateY(roty); //scale(1); Toroid(toroid); popMatrix(); int dTime = millis()-lastmillis; lastmillis += dTime; if ( play ) { time += dTime; } text((play?"playing (":"paused (") + Integer.toString(time) + ")",32,height-32); } class Point3D { float x, y, z; // constructors Point3D() { } Point3D(float x, float y, float z) { this.x = x; this.y = y; this.z = z; } } class ToroidParams { public int pts; public float radius; public int segments; public float latheRadius; public boolean isHelix; public float helixOffset; public ToroidParams() { pts = 40; radius = 40; segments = 60; latheRadius = 100; isHelix = false; helixOffset = 5; } }; void Toroid(ToroidParams p) { Point3D vertices[], vertices2[]; // initialize point arrays vertices = new Point3D[p.pts+1]; vertices2 = new Point3D[p.pts+1]; // fill arrays float angle = 0; for(int i=0; i<=p.pts; i++) { vertices[i] = new Point3D(); vertices2[i] = new Point3D(); vertices[i].x = p.latheRadius + sin(radians(angle))*p.radius; if (p.isHelix) { vertices[i].z = cos(radians(angle))*p.radius-(p.helixOffset* p.segments)/2; } else { vertices[i].z = cos(radians(angle))*p.radius; } angle+=360.0/p.pts; } // draw toroid float latheAngle = 0; for(int i=0; i<=p.segments; i++) { beginShape(QUAD_STRIP); for(int j=0; j<=p.pts; j++) { if (i>0) { vertex(vertices2[j].x, vertices2[j].y, vertices2[j].z); } vertices2[j].x = cos(radians(latheAngle))*vertices[j].x; vertices2[j].y = sin(radians(latheAngle))*vertices[j].x; vertices2[j].z = vertices[j].z; // optional helix offset if (p.isHelix) { vertices[j].z+=p.helixOffset; } vertex(vertices2[j].x, vertices2[j].y, vertices2[j].z); } // create extra rotation for helix if (p.isHelix) { latheAngle+=720.0/p.segments; } else { latheAngle+=360.0/p.segments; } endShape(); } } /* left/right arrow keys control ellipse detail up/down arrow keys control segment detail. 'a','s' keys control lathe radius 'z','x' keys control ellipse radius 'w' key toggles between wireframe and solid 'h' key toggles between toroid and helix */ void keyPressed() { if(key == CODED) { // pts if (keyCode == UP) { if (toroid.pts<40) { toroid.pts++; } } else if (keyCode == DOWN) { if (toroid.pts>3) { toroid.pts--; } } // extrusion length if (keyCode == LEFT) { if (toroid.segments>3) { toroid.segments--; } } else if (keyCode == RIGHT) { if (toroid.segments<80) { toroid.segments++; } } } // lathe radius if ( key == ' ' ) { play = !play; } if (key =='a') { if (toroid.latheRadius>0) { toroid.latheRadius--; } } else if (key == 's') { toroid.latheRadius++; } // ellipse radius if (key =='z') { if (toroid.radius>10) { toroid.radius--; } } else if (key == 'x') { toroid.radius++; } // wireframe /*if (key =='w') { isWireFrame = !isWireFrame; }*/ // helix if (key =='h') { toroid.isHelix = !toroid.isHelix; } } void mouseDragged() { float rate = 0.01; rotx += (pmouseY-mouseY) * rate; roty += (mouseX-pmouseX) * rate; }