3

I am new to Mathematica, and I am trying to plot a sequence of 2D points so that the resulting video shows 1, then 2, then 3, ... points on the screen. Here is a simple minded version of what I am trying to do. It plots the first 3 points of the 20 points of an ellipse:

tab = Table[{4 Cos[t], 2 Sin[t]}, {t, 0, 2 \[Pi], 2 \[Pi]/20}]; 
pointTable = Table[Point[tab[[i]]], {i, 1, 20}]; 
Row[
 Show[Graphics[pointTable[[1]], PlotRange -> {{-5, 5}, {-3, 3}}, 
   Axes -> True, Ticks -> None]], 
 Show[Graphics[pointTable[[1 ;; 2]], PlotRange -> {{-5, 5}, {-3, 3}}, 
   Axes -> True, Ticks -> None]], 
 Show[Graphics[pointTable[[1 ;; 3]], PlotRange -> {{-5, 5}, {-3, 3}}, 
   Axes -> True, Ticks -> None]]
]

I haven't been able to use Do, or While or any other "loop" to generate an arbitrary number of points. I'll be most grateful for any help.

2 Answers2

6

I am trying to plot a sequence of 2D points so that the resulting video shows 1, then 2, then 3, ... points on the screen

enter image description here

ClearAll["Global`*"]
tab = Table[{4 Cos[t], 2 Sin[t]}, {t, 0, 2 π, 2 π/20}];
plot[lis_List] := 
  ListPlot[lis, PlotRange -> {{-4.5, 4.5}, {-4.5, 4.5}}, 
   PlotStyle -> Red, GridLines -> Automatic, 
   GridLinesStyle -> LightGray];
Animate[plot[tab[[1 ;; n]]], {n, 1, Length[tab], 1}]

To display the point number also

enter image description here

tab = Table[{4 Cos[t], 2 Sin[t]}, {t, 0, 2 \[Pi], 2 \[Pi]/20}];
plot[lis_List, n_?NumericQ] := Grid[{{Row[{" point ", n}]},
    {ListPlot[lis, PlotRange -> {{-4.5, 4.5}, {-4.5, 4.5}}, 
      PlotStyle -> Red, GridLines -> Automatic, 
      GridLinesStyle -> LightGray, ImageSize -> 400]
     }}];
Animate[plot[tab[[1 ;; n]], n], {n, 1, Length[tab], 1}]
Nasser
  • 143,286
  • 11
  • 154
  • 359
4

Welcome to mathematica.stackexchange.com

tab = Table[{4 Cos[t], 2 Sin[t]}, {t, 0, 2 \[Pi], 2 \[Pi]/20}];
pointTable = Table[Point[tab[[i]]], {i, 1, 20}];
Show[Graphics[pointTable[[1 ;; #]], PlotRange -> {{-5, 5}, {-3, 3}}, 
     Axes -> True, Ticks -> None]] & /@ Range[20] // Row

enter image description here

There may be a version with less code.

138 Aspen
  • 1,269
  • 3
  • 16