Mohammed
YaBB Newbies
Offline
Posts: 12
superquadric made of images
Jul 18th , 2009, 5:13am
How can i make this skech faster ? i think i have to reduce the draw() part but i am not able to do that. I don't manage to do it. How can i do ? It is composed of a superquadric form which can be changed with controls. i think it is a bit slow. Here the code : int samples = 20; PImage b; float a1 = 10., a2 = 10., a3 = 10.; float u1 = 0., u2 = 20., v1 = 0., v2 = 20.; float dU = (u2 - u1) / samples; float dV = (v2 - v1) / samples; float n = 1., e = 1.; void setup(){ background(0); size(screen.width,screen.height, P3D); //size(500,500, P3D); //setup the screen size(screen.width,screen.height, P3D); //ambientLight(51, 102, 126); directionalLight(126, 126, 126, 0, 0, -1); ambientLight(102, 102, 102); camera(-15,15,-20,0,0,0,0,0,1); //get a viewpoint b = loadImage("wormhole.png"); } void draw(){ background(0); rotateY(frameCount * 0.01); float u = u1; for(int i=0; i<samples; i++){ float v = v1; for(int j=0; j<samples; j++){ float x = a1 * sqCos (u, n) * sqCos (v, e); float y = a2 * sqCos (u, n) * sqSin (v, e); float z = a3 * sqSin (u, n); pushMatrix(); translate(x, y, z); image(b, 0, 0, 1, 1); popMatrix(); v += dV; } u += dU; }} float sign ( float x ) { if ( x < 0 )return -1; if ( x > 0 )return 1; return 0; } float sqSin( float v, float n ) { return sign(sin(v)) * pow(abs(sin(v)),n); } float sqCos( float v, float n ) { return sign(cos(v)) * pow(abs(cos(v)),n); } void keyPressed() { if (key == CODED) { if (keyCode == UP) { n = 3.; e = 3.; } if (keyCode == LEFT) { n = 1.; e = 1.; } if (keyCode == RIGHT) { n = -0.2; e = 1.; } if (keyCode == DOWN) { n = 1; e = 0.3; } } }