Can someone help me to create a function. The truth I'm new in Mathematica and I don't understand well the way functions work in I. I need a function that animate some rectangles according to a curve that I introduce as a vector depending on time. I already did this, but I don't want to do for every curve. The animation that I have is the next:
{Animate[Graphics[ {{Red,
Polygon[{{0 , 0}, {1, 0}, {Flatten[a[t]][[1]] + 1,
1}, {Flatten[a[t]][[1]], 1}}]}, {Blue,
Polygon[{{Flatten[a[t]][[1]] + 1, 1}, {Flatten[a[t]][[1]],
1}, {Flatten[a[t]][[2]], 2}, {Flatten[a[t]][[2]] + 1, 2}}]},
{Green,
Polygon[{{Flatten[a[t]][[2]] + 1, 2}, {Flatten[a[t]][[2]],
2}, {Flatten[a[t]][[3]], 3}, {Flatten[a[t]][[3]] + 1, 3}}]},
{Black,
Polygon[{{Flatten[a[t]][[3]] + 1, 3}, {Flatten[a[t]][[3]],
3}, {Flatten[a[t]][[4]], 4}, {Flatten[a[t]][[4]] + 1, 4}}]},
{Orange,
Polygon[{{Flatten[a[t]][[4]] + 1, 4}, {Flatten[a[t]][[4]],
4}, {Flatten[a[t]][[5]], 5}, {Flatten[a[t]][[5]] + 1, 5}}]},
{Blue,
Polygon[{{Flatten[a[t]][[5]] + 1, 5}, {Flatten[a[t]][[5]],
5}, {Flatten[a[t]][[6]], 6}, {Flatten[a[t]][[6]] + 1, 6}}]},
{Pink,
Polygon[{{Flatten[a[t]][[6]], 6}, {Flatten[a[t]][[6]] + 1,
6}, {Flatten[a[t]][[7]] + 1, 7}, {Flatten[a[t]][[7]], 7}}]}},
PlotRange -> {{-2, 2}, {0, 8}}] , {t , 0, 2 Pi} ,
AnimationRunning -> False]}
I was wondering if there is a way to transform this code into a function so I just call the function with a different vector and get the animation?
a[t]
. $\endgroup$