int mode=-1; float phi=0; float psi=0; float t=0; void setup (){ smooth(); size(500,500); frameRate(50); } void planetgear(float phi, float psi){ float theta=phi/3+2*psi/3; float alpha=(phi-psi)*4/3; ellipse(0,0,400,400); //outer circle ellipse(0,0,200,200); //inner circle pushMatrix(); rotate(theta); ellipse(150,0,100,100); //planetgear fill(255,0,0); ellipse(-50*cos(alpha)+150,50*sin(alpha),10,10); fill(0,255,0); ellipse(50*cos(-alpha)+150,50*sin(-alpha),10,10); fill(0,0,255); ellipse(150,0,10,10); //carrier center popMatrix(); fill(255,0,0); ellipse(100*cos(phi),100*sin(phi),10,10); //contact point fill(0,255,0); ellipse(200*cos(psi),200*sin(psi),10,10); //contact point } void draw (){ translate(250,250); fill(255); rect(-250,-250,500,500); //clear box fill(255,0,0); rect(-230,205,25,25); //mode0 box fill(0,255,0); rect(-180,205,25,25); //mode1 box fill(255,166,0); rect(155,205,25,25); //mode2 box fill(0,0,255); rect(205,205,25,25); //mode3 box fill(255); stroke(0); planetgear(phi,psi); if(mode==0){t+=1;phi=-PI*t/64;if(t>64*6){noLoop();}} if(mode==1){t+=1;psi=-PI*t/96;if(t>96*6){noLoop();}} if(mode==2) {t+=1; if(t<=64){phi=-PI*t/128;} if(64128*4){noLoop();}} } void mousePressed(){ int x=mouseX; int y=mouseY; mode=-1;phi=0;psi=0;t=0;noLoop(); if(20<=x && x<=45 && 455 <=y && y <= 480){mode=0;loop();} if(70<=x && x<=95 && 455 <=y && y <= 480){mode=1;loop();} if(405<=x && x<=430 && 455 <=y && y <= 480){mode=2;loop();} if(455<=x && x<=480 && 455 <=y && y <= 480){mode=3;loop();} println("mode="+mode); }