5
$\begingroup$

enter image description here I need to make an animation like this, start with a table at first, then each element filled from left to right, top to bottom, instead of dynamically generating grid, the current code can only generate tables line by line, do you have a good way?

list = Table[Row@{b, " \[Times] ", a, " \[LongEqual] ", b a}, {a, 9}, {b, a}];
Grid[list]
Manipulate[Grid[list[[1 ;; n]], BaseStyle -> "Text", Frame -> All,
  FrameStyle -> GrayLevel[0.9]], {n, 1, 9, 1}]

More general, if it works for other irregular lists would be better

list=RandomInteger[10,#]&/@RandomInteger[{3,9},{9}]
Grid[list, Frame->All]
$\endgroup$
6
$\begingroup$

enter image description here

A function that shows the data with a limited number:

ClearAll[limit];
limit[data_, limit_] := 
 Module[{counter = 1}, 
  MapIndexed[If[counter <= limit, counter++; #1, ""] &, data, {2}]]

Generate all the frames:

Table[Grid[
   limit[Table[
     Row@{b, " \[Times] ", a, " \[LongEqual] ", b a}, {a, 9}, {b, a}],
     i], BaseStyle -> "Text", Frame -> All, 
   FrameStyle -> GrayLevel[0.9], ItemSize -> {6, 1}], {i, 1, 45, 1}]
$\endgroup$
5
$\begingroup$

enter image description here

size = 9;
list = Table[
   Row[{b, " \[Times] ", a, " \[LongEqual] ", b a}], {a, size}, {b, 
    a}];
g = Table[Spacer[70], {size}, {size}];
Manipulate[
 tick;
 Module[{},
  g[[n, 1 ;; m]] = list[[n, 1 ;; m]];
  If[m < size,
   tick = Not[tick];
   If[m == n, m = 1; n++, m++];
   ];
  Pause[.5];
  Grid[g, BaseStyle -> "Text", Frame -> All, 
   FrameStyle -> GrayLevel[0.9]]
  ],
 Grid[{{Button[
     "Play again", {g = Table[Spacer[70], {size}, {size}];; n = 1; 
      m = 1; tick = Not[tick]}]}}]
 ,
 {{tick, False}, None},
 {{n, 1}, None},(*row number*)
 {{m, 1}, None},(*column number*)
 TrackedSymbols :> {tick}
 ]

To change speed, just change the Pause amount. It is left as an exercise to add a stop and rewind buttons.

$\endgroup$
2
  • $\begingroup$ Thank you. Maybe I didn't say it clearly, I hope the grid is 9 by 9 at first, then each element filled from left to right, top to bottom $\endgroup$
    – matrix89
    Oct 27 at 11:36
  • $\begingroup$ @matrix89 changed it so it shows each entry at a time. $\endgroup$
    – Nasser
    Oct 27 at 12:18
3
$\begingroup$

Start with a grid with all elements styled White:

grid = Grid[Table[Style[Row[{Row@{i, "×", j}, i j},"="], 14, White], 
    {i, 1, 9}, {j, 1, i}], Alignment -> "=", Dividers -> All];

indices = Position[grid, _Style];

We can use Clock

enter image description here

to replace the style of one additional element from White to Black every 1/3 second:

clock := Clock[{0, 45, 1}, 45/3, 2]

Dynamic @ MapAt[# /. White -> Black &, indices[[;; clock]]] @ grid

enter image description here

Use Clock[{0, 45, 1}, 45, 2] to make a new element appear every second:

enter image description here

A similar approach is to wrap each grid element with Invisible and replace Invisible with Identity one cell at a time using Clock:

invisiblegrid = Grid[Table[Invisible @ Row[{Row@{i, "×", j}, i j}, "="], 
     {i, 1, 9}, {j, 1, i}], 
   Alignment -> "=", Dividers -> All, ItemStyle -> FontSize -> 14];

indexlist = Position[grid, _Invisible];

Dynamic @ MapAt[# /. Invisible -> Identity &, invisiblegrid, 
  indexlist[[;; Clock[{0, 45, 1}, 45, 2]]]]

same picture as above

$\endgroup$

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.