Manipulate
Manipulate
Make anything interactive.
This draws a polygon with five corners:
In[]:=
Graphics[Polygon[CirclePoints[5]]]
Out[]=
Make the number of corners interactive with . Replace the fixed number 5 with the variable n, wrap the expression with , and
specify that n ranges from 3 to 12 in steps of 1, with an initial value of 5. Drag the slider to change the number of corners:
In[]:=
Manipulate[
Graphics[Polygon[CirclePoints[n]]],
{{n,5},3,12,1}
]
Out[]=
1.
Add as many controls as you want:
Add a control for the size of the polygon:
In[]:=
Manipulate[
Graphics[Polygon[CirclePoints[s,n]],PlotRange2],
{{n,5},3,12,1},
{{s,1},0,2}
]
Out[]=
Add a control for the color:
In[]:=
Manipulate[
Graphics[{c,Polygon[CirclePoints[s,n]]},PlotRange2],
{{n,5},3,12,1},
{{s,1},0,2},
{c,Red}
]
Out[]=
2.
Add labels to the controls:
Add labels to the controls after the initial values:
In[]:=
Manipulate[
Graphics[{c,Polygon[CirclePoints[s,n]]},PlotRange2],
{{n,5,"corners"},3,12,1},
{{s,1,"size"},0,2},
{{c,Red,"color"},Red}
]
Out[]=