In this recipe we will construct a five-pointed star.
As shown in the example designs, a star is best defined by the polar coordinates of its points:
Between the points of the star there are 360/5 = 72º or 72xπ/180 = 1.256637 radians. If we start from the x-axis and move around the origin counterclockwise, the first point we encounter is 18º up (90º-72º = 18º or, obviously, 0.3141592653 radians (π/10)). The next ones are each time 1.256637 radians further around, but each of these points is at the same distance from the origin. We take this distance to be 30.
The five inner points are similarly spaced and each at a distance of 11.46 (by choice).
We have a list of r-theta values:
30,0.314159
11.46,0.942478
30,1.570796
11.46,2.199115
30,2.827433
11.46,3.455752
30,4.084070
11.46,4.712389
30,5.340708
11.46,5.969026
30,0.314159
Note that we repeat the first pair at the end, to ensure the polygon is closed. We could have generated this list by:
put pi/10 into l18
put 2*pi/5 into l72
put 0 into lline
put empty into lrthetas
repeat with i=1 to 5
add 1 to lline
put "30,"&(l18+(i-1)*l72) into line lline of lrthetas
add 1 to lline
put "11.46,"&(3*l18+(i-1)*l72) into line lline of lrthetas
end repeat
put line 1 of lrthetas into line 11 of lrthetas
The next thing to do is to create a polygon and set its design:
create graphic "Star"
set the style of graphic "Star" to "polygon"
set the pRThetas of graphic "Star" to lrthetas
set the pAngle of graphic "Star" to 0
set the pLoc of graphic "Star" to 200,200
set the opaque of graphic "Star" to true
set the textcolor of graphic "Star" to red
set the script of graphic "Star" to "on mousedown"&CR&"MoveRotate me"&CR&"end mousedown"
And that is it!
Note that it is good practice to set the angle and the loc before trying to do interactive manipulation.
Copyright R. Cailliau (robert at robertcailliau dot eu)
next planned revision: 2009-11