a while ago i had a lot of trouble with this i figured it out after a while though
you could use it for images to with modification
- import peasy.org.apache.commons.math.*;
- import peasy.*;
- import peasy.org.apache.commons.math.geometry.*;
- int round =0;
- int radius = 200;
- int sides = 500;
- int x=250;
- int y =250;
- int z = 0;
- //float firstx,firsty,firstz;
- //float x1,y1,z1,x2,y2,z2,xloop,yloop,zloop;//x1 = point x2 = connector loop = finisher
- PeasyCam camera;
- sphere tom;
- void setup(){
- size(500,500,P3D);
- camera = new PeasyCam(this,width/2,height/2,0,int((height/2.0)/tan(PI*60.0/360)));
- tom = new sphere(500,200);
- }
- //3,4,12
- void draw(){
- background(0);
- tom.update(x,y,z);
- }
- void keyTyped(){
- if(key=='w'){
- y=y-1;
- z = z-1;
- }
- if(key=='s'){
- y=y+1;
- z=z-1;
- }
- if(key=='d'){
- x=x+1;
- }
- if(key=='a'){
- x=x-1;
- }
- }
- class sphere{
-
- int size;
- float increment;
- float x1,z1,y1;
- sphere(int qual, int se){
- size = se;
- increment = TWO_PI/qual;
- }
- void update(int x,int y,int z){
- for(float theta =-PI/2; theta< PI/2; theta = theta+increment){//only 1 roTATE
- //0,0,-1 to;
- //0,0,1
- float sinz=sin(theta);
- float cosz=cos(theta);
- //define sin and cosine early
- //
- //
- ///
- //
- for(float phi=0; phi<TWO_PI; phi = phi+(increment)){//making x,y rotation
- stroke(255-(theta+PI/2.0/PI)*255,0,(theta*PI/2.0/PI)*255);
- // fill(255-(theta+PI/2.0/PI)*255,0,(theta*PI/2.0/PI)*255);
- float sin = sin(phi);//sine of x,y angle
- float cos = cos(phi);//cosine of x,y angle
- float sin1 = sinz;//redeclare
- float cos1 = cosz;
- x1 = cos1*cos*size;//scale x to z position
- y1 = cos1*sin*size;//repeat
- z1 = sin1*size;//z
- point(x1+x,y1+y,z1+z);
- }
- }
- }
-
-
- }
it uses spherical coordinats and peasy cam control