topical media & game development
graphic-processing-algorithm-Ch08-p204-p204.pde / pde
int samples = 20;
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(){
size(500,500, P3D); //setup the screen
camera(-15,15,-20,0,0,0,0,0,1); //get a viewpoint
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);
point(x,y,z);
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);
}
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.