2
$\begingroup$

I am trying to simulate three kind of points (different color) entering a 2D rectangular region from different sides with animation. Below is my code:

rPointList=Module[{t},Table[If[t<1,{x[0]=0,y[0]=RandomReal[{0,10}]},
{x[t]=RandomReal[{0,1}],y[t]=RandomReal[{0,1}]}],{t,0,10}]];
bPointList=Module[{t},Table[If[t<1,{x[0]=10,y[0]=RandomReal[{0,10}]},
{x[t]=RandomReal[{-1,0}],y[t]=RandomReal[{0,1}]}],{t,0,10}]];
rGraphicsList=Graphics[{Red,PointSize[0.03],Point[#]},AxesLabel->{"x","y"},
 PlotRange->{{0,10},{0,10}}]&/@rPointList;
bGraphicsLIst=Graphics[{Blue,PointSize[0.05],Point[#]},AxesLabel->{"x","y"},
 PlotRange->{{0,10},{0,10}}]&/@bPointList;
ListAnimate[Show[rGraphicsList,bGraphicsList]]

In the code, These points are moving with t. My code only shows me the result at finally time. How to show the points moving with t? Thanks.

$\endgroup$
3
$\begingroup$

Not sure about your strategy generating the data, but provided you have already defined {rGraphicsList, bGraphicsList, blGraphicsList}, then you can do

ListAnimate[
 Show @@@ Transpose[
   {rGraphicsList, bGraphicsList, blGraphicsList}
   ]
 ]

enter image description here

Here @@@ stands for Apply as in Apply[f,expr,{1}] or f@@@expr replaces heads at level 1 of expr by f. Effectively making

f @@@ {{a, b, c}, {d, e, f}, {g, h, i}}
{f[a, b, c], f[d, e, f], f[g, h, i]}
$\endgroup$
  • $\begingroup$ Great! Thanks a lot! $\endgroup$ – B.Bai Feb 8 '16 at 22:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.