How To Draw A Hat In Python
0 the surroundings
Python version :iii.6.6
the operating organisation :Mac OS Mojave 10.xiv.2
one the introduction
recently, my girl-in-law has been looking at her cell phone and the toilet every dark when she has dinner 。
watching and laughing ?WTF? what are you doing ?
yeah, she's watching captain america ……
this man is more than handsome than me ?……
than i have money ?……
still better than me ?……
the answer is obvious, and i'm sure your optics are wide open 。
that's the problem, as a man , how can i endure ? it's a star, it's a fake , there is no turning back …… i'll give you a cap ……
this article is not an introduction to turtle , therefore, the basic brush employ of xiao pang is not redundant in this article. interested can leave a message , i'll write i or a series based on your feedback.
2 in bodily combat
allow's wait at a rendering first :
anybody who's used turtle knows this , a brush needs to be lifted and drawn. this is of import to understand , because computers are rigid, you have to tell them everything yous do , including the gc.
so as presently as your brush drops, it leaves a mark everywhere it goes 。 if you want a distance you have to go through 「 pen upward 」->「 move the brush 」->「 put pen to paper 」。
so let'southward first encapsulate this action as a function :
def setpen(x, y): # pen up t.penup() # permit's motion the castor to (x, y) t.goto(ten, y) # put pen to paper t.pendown() t.setheading(0)
at present let'southward depict the shield. if the shield , watch for the u.s. shield. color is 「 red 」->「 white 」->「 reddish 」->「 bluish 」。
now, at that place'south a fob here, which is that the background color of the filled circle in the back is going to overwrite the groundwork color of the previously drawn circle 。
def circumvolve(ten, y, r, color): # to make sure we draw a circle that is round enough, nosotros set the edges of the circle a lilliputian bit more n = 36 angle = 360 / north pi = three.1415926 # the perimeter c = 2 * pi * r # the length of each side l = c / north # the starting position start_x = ten - fifty / 2 start_y = y + r # motion the brush setpen(start_x, start_y) # i'm gonna go alee and select the brush color t.pencolor(color) # select groundwork colour t.fillcolor(color) # make full t.begin_fill() for i in range(northward): t.forrard(l) t.right(angle) t.end_fill()
and then there'due south the white star in the flick, so i won't comment on that , because information technology's the same process as drawing circles.
def five_star(l): setpen(0, 0) t.setheading(162) t.forward(150) t.setheading(0) t.fillcolor('WhiteSmoke') t.begin_fill() t.hideturtle() t.penup() for i in range(5): t.forward(fifty) t.right(144) t.end_fill()
the main office :
def sheild(): circumvolve(0, 0, 300, 'cherry-red') circle(0, 0, 250, 'white') circle(0, 0, 200, 'cerise') circle(0, 0, 150, 'blue') five_star(284) if __name__ == '__main__': sheild() # stop turtle turtle.done()
3 conclusion
this is an article on drawing in python , more than interesting 、 fun python app 、 combat is on the planet of knowledge 「 everyone is a pythonista 」。
follow public business relationship 「Python column 」, answer : the team the shield , get the total lawmaking !
Source: http://www.codestudyblog.com/cnb/0420201545.html
Posted by: garciawhar1968.blogspot.com
0 Response to "How To Draw A Hat In Python"
Post a Comment