Python draws a pointed star such as a pentagram

Source: Internet
Author: User

Only the odd and 4 integer multiples of the angle star can be drawn out, see Programs and notes:

ImportMathImportTurtle as T#This method can only be drawn at the sharp corner of the angle to draw the star, \#that is, you can use the long line segment (the longest segment length is not the turn) without mentioning the angle star of the stroke#If the note hanging 28, 29 lines, then the number of even angle to twice times, proving that this method can only draw odd and 4 integer multiples of the angle star \#that is, only the odd and 4 integer multiples of the angle star can be a stroke outdefLoop (r,n): T.FD (OL (R,n)) T.right (180-360/(N))defol (r,n): NA= (360/(4*n))/180 *Math.PI ol= R * Math.Cos (NA) * 2ol=Int (round (OL))returnoldefRelocation (r,n): T.penup () T.left (90) T.FD (R) t.right (180-360/(TheN)) T.pendown ()defMain (r,n): times=NifNinch(1,2,3,4,8):        Print('cannot make a stroke out of {0:.0f} angle star'. Format (times) exit ()ifn%2==0:n/=2ifN%2==1:            Print('cannot make a stroke out of {0:.0f} angle star'. Format (times) exit () relocation (r,n) forIinchRange (Times): Loop (r,n) T.penup () T.goto (0,0) t.seth (0) T.pendown () R=200N=eval (Input ('Please enter the corner number of the corner star to be drawn N:'))#eval () function is important, do not always forget to add!!!T.pensize (8)#Note that t.pensize (20) is not t.pensize=20, variable assignment takes =, property changes with T.pensize (T.color ('Green') T.speed (10) T.setup (450,450) Main (r,n) T.done ()

Pentagram and 16 Point star:

Python draws a pointed star such as a pentagram

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.