Creating an Animation of a 2D Polygon

You will need the following functions:

	Map		maps a function over a list
	Table		generates a list
	Do		executes a command as a variable goes from start to finish in step sizes
	AppendTo	appends an object to a list
	Polygon	generates a closed, filled polygon 
	Graphics	represents its input s a 2D graphical image

1. Define a function that creates a unit vector with the given angle

	Name: UnitVectorAtAngle
	Input: t (angle)
	Result: unit vector with the given angle
	
Test function by generating a unit vector with angle Pi/4.

UnitVectorAtAngle[t_]:={Cos[t],Sin[t]}

UnitVectorAtAngle[Pi/4]

2. Define a function that creates a list of n unit vectors with angles 2 Pi / n

	Name: UnitVectorList
	Input: n (number of vertices of polygon)
	Result: a list of n vectors forming a regular n polygon
	
Test function by generating a list representing a square

UnitVectorList[n_]:= Map[UnitVectorAtAngle, Table[i,{i,2 Pi/n,2 Pi, 2 Pi / n}]]

UnitVectorList[4]

3. Define a function that creates and draws a polygon made out of a list of points

	Name: DrawPolygon
	Input: list (of points to draw)
	Result: image of polygon
	
Test function by drawing a square

DrawPolygon[list_]:=Graphics[Polygon[list]]

DrawPolygon[UnitVectorList[8]]

4. Define a function that generates a 2D rotational matrix

	Name: RotateMatrix
	Input: t (angle)
	Result: rotational matrix by angle t

Test function by generating a rotation by Pi/2 and applying it to the vector {0, 1}

RotateMatrix[t_]:={{Cos[t], Sin[t]}, {-Sin[t],Cos[t]}}

RotateMatrix[Pi/2].{0,1}

5. Define a function that rotates a single vector by a given angle

	Name: RotateVector
	Input:t (angle), v (vector)
	Result: the rotated vector
	
Test function by rotating {0, 1} by Pi/2

RotateVector[t_, v_]:=RotateMatrix[t].v

RotateVector[Pi/2,{0,1}]

6. Define a function that rotates a list of vectors, each by the same given angle

	Name: RotateListOfVectors
	Input: t (angle), list (of vectors)
	Result: list of rotated vectors

Test function by showing a square rotated by Pi/4

RotListOfVectors[t_, list_] := Map[RotateVector[t, #] &, list]

DrawPolygon[RotListOfVectors[Pi/40,UnitVectorList[4]]]

7. Generate a list of polygons rotated by 0, 0.1, 0.2, 0.3, ... 2 Pi degrees as follows:

	Set variable list to an empty list
	Setup a Do loop that runs for an angle t from 0 to 2 Pi in 
	step of 0.1
		In the Do loop, call AppendTo to append a new 
		regular polygon to the list, where the new regular 
		Polygon is generated from a list of 6 points, rotated 
		by angle t 

Test this code by creating a list of squares rotatd in steps of 0.5

list = {};
Do[
AppendTo[list,DrawPolygon[RotListOfVectors[t,UnitVectorList[7]]]],
{t,0,2Pi,0.02}]

list

8. Feed that list of polygons from (7) into the function ListAnimate. Adjust the step size for t to get a smooth animation

ListAnimate[list]