//// 만들어 둔 Class를 그대로 쓴다//classCircleArrow{floatx;// 원의 x 좌표floaty;// 원의 y 좌표floatr;// 원의 반지름floattx;// 마우스 방향 원 위의 점 x 좌표, target xfloatty;// 마우스 방향 원 위의 점 y 좌표, target yfloatta;// 원의 원점에서 마우스 방향 각도, target angle// 클라스 변수를 생성하고 초기화 한다.CircleArrow(floatposX,floatposY,floatdiameter){x=posX;y=posY;r=diameter/2;tx=0;ty=0;ta=0;}// 목표 지점으로 방향을 찾고, 원과 만나는 좌표를 계산해 저장한다.voidshow(floattargetX,floattargetY){ta=atan2(targetY-y,targetX-x);tx=x+cos(ta)*r;ty=y+sin(ta)*r;circle(x,y,r*2);line(x,y,tx,ty);}}
importprocessing.serial.*;Serialport;CircleArrowca1,ca2;voidsetup(){size(640,480);port=newSerial(this,"COM3",115200);ca1=newCircleArrow((width/2)-100,height/2,150);ca2=newCircleArrow((width/2)+100,height/2,150);}voiddraw(){background(255);ca1.show(mouseX,mouseY);ca2.show(mouseX,mouseY);intdeg1=getDeg(ca1.ta)/2;intdeg2=getDeg(ca2.ta)/2;port.write(deg1+", "+deg2+'\n');line(0,mouseY,width,mouseY);line(mouseX,0,mouseX,height);}intgetDeg(floatangle){floatdeg=degrees(angle)+90;if(deg<0)deg=map(deg,-89,-1,271,359);return(int)deg;}//// 여기에 Class 코드를 넣으세요 !!//