Jump to content
Sign in to follow this  
lennart

Drawing a star with outline and fill at any angle

Recommended Posts

 
procedure drawStar(const aCanvas:TW3Canvas; 
          center_x, 
          center_y, 
          aRadius, 
          aCoreSize, 
          aAngle:float; 
          aPoints:integer; 
          aOutlineColor, 
          aFillColor:TColor); 
var 
  angle: float; 
  i:  Integer; 
  rr: float; 
  px,py:  float; 
Begin 
  angle:=PI/aPoints; 

  aCanvas.strokestyle:=ColorToWebStr(aOutLineColor); 
  aCanvas.fillstyle:=ColorToWebStr(aFillColor); 
  acanvas.lineWidth:=8; 
  aCanvas.beginpath; 

  for i:=0 to (aPoints*2)-1 do 
  Begin 
    if (i and 1)=0  then 
    rr:=aRadius else 
    rr:=aCoreSize; 

    px:= center_x + cos ( i * angle - pi/2 + aAngle) * rr; 
    py:= center_y + sin ( i * angle - PI/2 + aAngle) * rr; 
    if i=0 then 
    aCanvas.movetoF(px,py) else 
    aCanvas.linetoF(px,py); 
  end; 

  acanvas.closepath; 
  aCanvas.fill; 
  aCanvas.stroke; 
end; 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×