アニメーション(with Arduino)

(*Arduino設定*)
Needs["NETLink`"]
InstallNet[];
ser=NETNew["System.IO.Ports.SerialPort","COM3",9600]
ser@Open[]

Animate[
(*ボールの座標*)
x=If[t<25*2Pi/100,v0*t,If[25*2Pi/100≤t,v*ct*t]]; (*等速直線運動*)
y=If[t<25*2Pi/100,-(1/2)*g*t*t+12.5,If[25*2Pi/100≤t<72*2Pi/100,v*st*(t-25*2Pi/100)-(1/2)*g*(t-25*2Pi/100)*(t-25*2Pi/100)+0.5,If[72*2Pi/100≤t<111*2Pi/100,(4/5)*v*st*(t-72*2Pi/100)-(1/2)*g*(t-72*2Pi/100)*(t-72*2Pi/100)+0.5,If[111*2Pi/100≤t<144*2Pi/100,(2/3)*v*st*(t-111*2Pi/100)-(1/2)*g*(t-111*2Pi/100)*(t-111*2Pi/100)+0.5,If[144*2Pi/100≤t<168*2Pi/100,(1/2)*v*st*(t-144*2Pi/100)-(1/2)*g*(t-144*2Pi/100)*(t-144*2Pi/100)+0.5,If[168*2Pi/100≤t<181*2Pi/100,(1/4)*v*st*(t-168*2Pi/100)-(1/2)*g*(t-168*2Pi/100)*(t-168*2Pi/100)+0.5,If[181*2Pi/100≤t,0.5]]]]]]];(*自由落下＋α*)
g=9.8; (*重力加速度*)

(*以下「斜方投射」に使用する情報*)
v=If[v0==0,15,If[v0≠0,Sqrt[(v0*v0)+(g*t*g*t)]]];
ct=v0/v;
st=If[v0==0,Sin[theta],If[(v0≠0)&&(0<t<25*2Pi/100),(g*t)/v,If[(v0≠0)&&(25*2Pi/100≤t),Sin[theta]]]];
theta=If[v0≤0,Pi/2,If[0<v0,ArcTan[(g*(25*2Pi/100))/v]]];


(*地面*)
baseline=Line[{{-2,0},{18,0}}];

(*モンスターボール*)
ballR=If[t==0,{White,Disk[{x,y},0.5,{(Pi-30t)/4,(5Pi-30t)/4}]},If[t>0,{Red,Disk[{x,y},0.5,{(Pi-30t)/4,(5Pi-30t)/4}]}]];
ballW=If[t==0,{White,Disk[{x,y},0.5,{(5Pi-30t)/4,(9Pi-30t)/4}]},If[t>0,{RGBColor[255,255,255],Disk[{x,y},0.5,{(5Pi-30t)/4,(9Pi-30t)/4}]}]];
balline1=If[t==0,{White,Circle[{x,y},0.5]},If[t>0,{Circle[{x,y},0.5]}]];
ballC=If[t==0,{White,Disk[{x,y},0.1]},If[t>0,{RGBColor[255,255,255],Disk[{x,y},0.1]}]];
balline2=If[t==0,{White,Circle[{x,y},0.1]},If[t>0,{RGBColor[0,0,0],Circle[{x,y},0.1]}]];
ball={ballR,ballW,balline1,ballC,balline2};

(*ボールの影*)
shadow=If[t<25*2Pi/100,Disk[{x,0.0},{0.3*t,0.1}],If[25*2Pi/100≤t<48.5*2Pi/100,Disk[{x,0.0},{0.3-0.1*(t-25*2Pi/100),0.1}],If[48.5*2Pi/100≤t<72*2Pi/100,Disk[{x,0.0},{0.4*(t-48.5*2Pi/100),0.1}],
If[72*2Pi/100≤t<91.5*2Pi/100,Disk[{x,0.0},{0.3-0.1*(t-72*2Pi/100),0.1}],If[91.5*2Pi/100≤t<111*2Pi/100,Disk[{x,0.0},{0.5*(t-91.5*2Pi/100),0.1}],If[111*2Pi/100≤t<127.5*2Pi/100,Disk[{x,0.0},{0.4-0.1*(t-111*2Pi/100),0.1}],If[127.5*2Pi/100≤t<144*2Pi/100,Disk[{x,0.0},{0.5*(t-127.5*2Pi/100),0.1}],If[144*2Pi/100≤t<156*2Pi/100,Disk[{x,0.0},{0.4-0.1*(t-144*2Pi/100),0.1}],If[156*2Pi/100≤t<168*2Pi/100,Disk[{x,0.0},{0.5*(t-156*2Pi/100),0.1}],If[168*2Pi/100≤t<181*2Pi/100,Disk[{x,0.0},{0.5-0.1*(t-168*2Pi/100),0.1}],If[181*2Pi/100≤t,Disk[{x,0.0},{0.5,0.1}]]]]]]]]]]]];

(*ピカチュウ*)
pika1={Yellow,Disk[{14.0,0.8},{1.1,0.9}]};
pika2={Circle[{14.0,0.8},{1.1,0.9}]};
pika3={Yellow,Disk[{14.0,2.1},{1.0,0.85}]};
pika4={Circle[{14.0,2.1},{1.0,0.85}]};
body={pika1,pika2,pika3,pika4};
cheek1={Red,Disk[{13.2,1.85},0.25]};
cheek2={Red,Disk[{14.8,1.85},0.25]};
eye1={RGBColor[0,0,0],Disk[{13.5,2.2},0.2]};
eye2={RGBColor[0,0,0],Disk[{14.5,2.2},0.2]};
eye3={RGBColor[255,255,255],Disk[{13.55,2.25},0.075]};
eye4={RGBColor[255,255,255],Disk[{14.45,2.25},0.075]};
nose={RGBColor[0,0,0],Disk[{14,1.99},0.05]};
mouse1={Circle[{13.9,1.8},0.08,{7Pi/6,2Pi}]};
mouse2={Circle[{14.1,1.8},0.08,{Pi,11Pi/6}]};
face={cheek1,cheek2,eye1,eye2,eye3,eye4,nose,mouse1,mouse2};
e1={12.6,3.85};
e2={13.2,2.4};
e3={13.7,2.9};
e4={15.4,3.85};
e5={14.8,2.4};
e6={14.3,2.9};
e7={12.9,3.64};
e8={12.9,3.19};
e9={15.1,3.64};
e10={15.1,3.19};
ear1={Yellow,Polygon[{e1,e2,e3}]};
ear2={Yellow,Polygon[{e4,e5,e6}]};
ear3={Line[{e1,e2}],Line[{e1,e3}]};
ear4={Line[{e4,e5}],Line[{e4,e6}]};
ear5={Polygon[{e1,e7,e8}]};
ear6={Polygon[{e4,e9,e10}]};
ear={ear1,ear2,ear3,ear4,ear5,ear6};
pika={ear,body,face};
pikachu=Mouseover[pika,Text[Style["Pika!!",FontColor->RGBColor[0,0,0],FontFamily->"Helvetica",FontSize->12],{14.5,4.5}]];

(*コマンド*)
word1=Text[Style["　いし",FontFamily->"Helvetica",FontSize->12],{13.5,13}];
word2=Text[Style["　エサ",FontFamily->"Helvetica",FontSize->12],{13.5,12}];
word3=Text[Style["ボール",FontFamily->"Helvetica",FontSize->12],{16.3,13}];
word4=Text[Style["にげる",FontFamily->"Helvetica",FontSize->12],{16.3,12}];
v1=Mouseover[Text[Style["→",FontColor->RGBColor[255,255,255],FontFamily->"Helvetica",FontSize->12],{12.7,13}],Text[Style["→",FontColor->RGBColor[0,0,0],FontFamily->"Helvetica",FontSize->12],{12.7,13}]];
v2=Mouseover[Text[Style["→",FontColor->RGBColor[255,255,255],FontFamily->"Helvetica",FontSize->12],{12.7,12}],Text[Style["→",FontColor->RGBColor[0,0,0],FontFamily->"Helvetica",FontSize->12],{12.7,12}]];
v3=Dynamic[Button[Mouseover[Text[Style["→",FontColor->RGBColor[255,255,255],FontFamily->"Helvetica",FontSize->12],{15,13}],Text[Style["→",FontColor->RGBColor[0,0,0],FontFamily->"Helvetica",FontSize->12],{15,13}]],{ser@Write["S"],ser@Write["A"]}]];
v4=Mouseover[Text[Style["→",FontColor->RGBColor[255,255,255],FontFamily->"Helvetica",FontSize->12],{15,12}],Text[Style["→",FontColor->RGBColor[0,0,0],FontFamily->"Helvetica",FontSize->12],{15,12}]];
cm1={12.0,13.8};
cm4={12.0,11.3};
cm2={17.5,13.8};
cm3={17.5,11.3};
cm={Line[{cm1,cm2}],Line[{cm2,cm3}],Line[{cm3,cm4}],Line[{cm4,cm1}]};
word={word1,word2,word3,word4,v1,v2,v3,v4};

(*ゲットだぜ！*)
get=If[(0.98≤(((x-14)*(x-14))/((1.5)*(1.5)))+(((y-2.1)*(y-2.1))/((1.35)*(1.35)))≤1.2)&&(2.1<y),{ser@Write["G"],Pause[4],ser@Write["A"],ser@Close[]}];

(*Graphicsのオプション*)
options={PlotRange->{{-0.5,18},{0,15}}};

Graphics[{shadow,pika,pikachu,ball,get,baseline,word,cm},options],{t,0,4Pi,4Pi/1000},{v0,0,10,Pi/100},AnimationRunning->False]