PFont font; int whd=90,whb=0; int i=0; float alpha; float wha=radians(whd); float arm=185,ang=radians(55),r0=8,r1=55,r2=65,r3=50,r5=35; void wheel(int x, int y, int wh, int pinflag){ pushMatrix(); translate(x,y); if(pinflag==1){rotate(wha);} else{rotate(radians(whb));} ellipse(0,0,r2*2,r2*2); ellipse(0,0,r1*2,r1*2); ellipse(0,0,r0*2,r0*2); noFill(); arc(r2,0,r3*2,r3*2,PI-ang,PI+ang); rotate(TWO_PI/3); arc(r2,0,r3*2,r3*2,PI-ang,PI+ang); rotate(TWO_PI/3); arc(r2,0,r3*2,r3*2,PI-ang,PI+ang); rotate(TWO_PI/3); if(pinflag==0){ for(int i=0;i<10;i++){ellipse(60,0,6,6);rotate(TWO_PI/10);}} else{ pushMatrix(); rotate(-PI/3); ellipse(r5,0,6,6); rotate(-TWO_PI/3); ellipse(r5,0,6,6); popMatrix(); } popMatrix(); } float solve(float x,float y,float h){ float a=x*x+y*y; float b=y*h; float c=h*h-x*x; float cosalpha0=(sqrt(b*b-a*c)-b)/a; float cosalpha1=-(sqrt(b*b-a*c)+b)/a; float alpha=atan2(sqrt(1-cosalpha0*cosalpha0),cosalpha0); if(abs(y*cos(alpha)+h-x*sin(alpha))>0.01){ alpha=atan2(sqrt(1-cosalpha1*cosalpha1),cosalpha1); } if((alpha>0)&&(h*sin(alpha)+arm*cos(alpha)>x)){return alpha;} else{return 0;} } void setup(){ size(400,400); background(255); smooth(); font = loadFont("Courier-24.vlw"); textFont(font); frameRate(30); } void draw(){ fill(255); rect(0,0,width,height); fill(0); text(str(int(((whd+630)%360)/36)),width-105,120); text(str(int(whb/36)),95,120); noFill(); stroke(0); wheel(100,200,0,0); wheel(300,200,0,1); if(-150<=whd && whd<72){ float alpha0=solve(200-r5*cos(wha),r5*sin(wha),55); float alpha1=solve(200-r5*cos(wha+TWO_PI/3),r5*sin(wha+TWO_PI/3),10); alpha=max(alpha0,alpha1); } if(72<=whd && whd<90){ alpha=radians((35-(whb-1)%36)*26.5/36); } if(90<=whd){alpha=0;} translate(100,200); pushMatrix(); rotate(- alpha); line(0,0,0,10); line(0,10,arm,10); line(arm-60,10,arm-60,55); line(arm-60,55,arm,55); arc(0,0,160,160,radians(7),radians(45)); popMatrix(); float beta=alpha*36/26.5-radians(108); fill(255,0,0); ellipse(80*cos(-alpha+PI/4),80*sin(-alpha+PI/4),2,2); noFill(); line(80*cos(-alpha+PI/4),80*sin(-alpha+PI/4),60*cos(-beta),60*sin(-beta)); i=(i+1)%360; if(18<=i%36){ whd=whd+2; if(162<=whd){whd=whd-360;} wha=radians(whd); if(72<=whd&&whd<90)whb=whb+4;} } void mousePressed(){ whd=90; i=0; whb=0; loop(); }