Goal: Rotate a  Star or a regular polygon

1. Define a unit vector at an angle of t

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

Why is this a unit vector?

Now we can define a list of these vectors, wrap that list up in a Polygon, and draw the resulting object

l={VectorAtAngle[0],VectorAtAngle[2 Pi/4], VectorAtAngle[2* 2 Pi/4], VectorAtAngle[3*2 Pi/4]}

Graphics[{RGBColor[1,0,0],Polygon[l]}]

About Repetition

Functional programming language: applies functions to other functions, e.g Mathematics, Scheme, DrRacket
Procedural programming langugae: uses loops and procedures, e.g Java, C++, JavaScript.

Procedural language usually have a “do”, “while”, “repeat until”, or “for” loop, or combinations of them. Mathematica has, for example, a “do” loop:

   Do[ThisFunction[i],{i, iStart, iStop, iStep}]

For example:

Do[Print[VectorAtAngle[i * 2 Pi / 8]],{i,0,7,1}]

But functional languages usually prefer different mechanisms to handle repetition.

WANT: apply the function VectorAtAngle to list of angles {0, 2 Pi/n, 4 Pi/n, ... 2 Pi}. Some functions automatically apply to lists:

Sin[Pi]

Sin[{0, Pi/4, Pi/2, Pi/3}]

For everyone else, we can use Map function to apply a function to a list, or to “map a funcion over a list”:

Map[Sin,{0, Pi/2 , Pi/4, Pi/3}]

There are many ways to generate lists; we can use, or example, the Table function:

Table[i, {i,0, 2*Pi, 2*Pi/8}]

Then map our VectorAtAngle over this list of 8 numbers representing angles on the unit circle, and draw the point, wrapped up in a closed polygon with these vertices:

l=Map[VectorAtAngle, Table[i, {i,0, 2Pi, 2Pi/8}]]

Graphics[{RGBColor[1,0,0],Polygon[l]}]

Now we generate one function to compute and show a regular n polygon

RegPoly[n_] := Polygon[Map[VectorAtAngle, Table[i,{i,0,2 Pi, 2 Pi/n}]]]

Graphics[{RGBColor[1,0,0],RegPoly[6]}]