1
$\begingroup$

Can I use mathematica to show an animation of

  1. A 2x2 square
  2. ..with its lower left quadrant colored
  3. ..then with all of the square colored ?
$\endgroup$
  • 2
    $\begingroup$ What have you tried so far? Have you looked at ListAnimate, at Rectangle, etc? Where are you stuck? $\endgroup$ – Carl Lange Aug 2 '19 at 17:21
3
$\begingroup$

There are many ways to do this in Mathematica. Here's one example:

ListAnimate[{
  ArrayPlot[{{0, 0}, {0, 0}}],
  ArrayPlot[{{0, 0}, {1, 0}}],
  ArrayPlot[{{1, 1}, {1, 1}}]
  }]
$\endgroup$
2
$\begingroup$

Here is another way:

frames = Table[
   Graphics[{EdgeForm[Thick], White, Rectangle[{0, 0}, {2, 2}], Black,
      Rectangle[{0, 0}, p]}],
   {p, {{0, 0}, {1, 1}, {2, 2}}}];

ListAnimate[frames]

enter image description here

$\endgroup$
1
$\begingroup$
n = 5;
array = ConstantArray[0, {n, n}];

frames = Table[ArrayPlot[MapAt[Red &, array, {;; k, ;; k}],
      DataReversed -> True, Mesh -> All], {k, Range[0, n]}];

Export["arrayplot.gif", frames, "DisplayDurations" -> 1];

enter image description here

ListAnimate[frames]

enter image description here

Alternatively, using Rectangles as in MelaGo's answer:

frames = Table[Graphics[{Red, Rectangle[{0, 0}, {k, k}]}, 
   Frame -> True, 
   FrameTicks -> False, PlotRange -> {{0, n}, {0, n}}, 
   GridLines -> Automatic, 
   Method -> {"GridLinesInFront" -> True}], {k, 0, n}];

ListAnimate @ frames

same picture

$\endgroup$

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