In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces Python how to use turtle module to draw love pattern, the article is very detailed, has a certain reference value, interested friends must read it!
Use python small turtles to achieve the love pattern drawing, the code is as follows:
Import turtleimport time # screen clearing function def clear_all (): turtle.penup () turtle.goto (0,0) turtle.color ('white') turtle.pensize (800000) turtle.pendown () turtle.setheading (0) turtle.fd (300) turtle.bk (600) # relocate the turtle's position def go_to (x, y, state): turtle.pendown () if state else turtle.penup () turtle.goto (x Y) # draw lines # Turtles return to origin when state is true Do not return to the original starting point for the holiday def draw_line (length, angle) State): turtle.pensize (1) turtle.pendown () turtle.setheading (angle) turtle.fd (length) turtle.bk (length) if state else turtle.penup () turtle.penup () # draw Arrow feather def draw_feather (size): angle = 30 # Angle of Arrow feather_num = size//6 # number of feathers Feather_length = size// 3 # length of feathers feather_gap = size//10 # interval of feathers for i in range (feather_num): draw_line (feather_gap Angle+180, False) # Arrow handle Do not turn back draw_line (feather_length, angle+ 145, True) # wings, to turn back draw_line (feather_length, angle+ 145, False) draw_line (feather_num*feather_gap, angle, False) draw_line (feather_length, angle+ 145 + 180, False) for i in range (feather_num): draw_line (feather_gap, angle+180, False) # arrow handle Do not turn back draw_line (feather_length, angle-145, True) # wings To turn back draw_line (feather_length, angle-145, False) draw_line (feather_num*feather_gap, angle, False) draw_line (feather_length, angle-145180, False) # draw def draw_heart (size): turtle.color ('red' 'pink') turtle.pensize (2) turtle.pendown () turtle.setheading (150) turtle.begin_fill () turtle.fd (size) turtle.circle (size *-3.745, 45) turtle.circle (size *-1.431) turtle.left (120) turtle.circle (size *-1.431) turtle.circle (size *-3.745 45) turtle.fd (size) turtle.end_fill () # Arrow def draw_arrow (size): angle = 30 turtle.color ('black') draw_feather (size) turtle.pensize (4) turtle.setheading (angle) turtle.pendown () turtle.fd (size*2) # one arrow through the heart # the head of the arrow is not drawn Instead of using sea turtles, def arrow_heart (x, y, size): go_to (x, y) False) draw_heart (size*1.15) turtle.setheading (- 150) turtle.penup () turtle.fd (size*2.2) draw_heart (size) turtle.penup () turtle.setheading (150) turtle.fd (size*2.2) draw_arrow (size) # draw the villain def draw_people (x, y): turtle.penup () turtle.goto (x Y) turtle.pendown () turtle.pensize (2) turtle.color ('black') turtle.setheading (0) turtle.circle (60360) turtle.penup () turtle.setheading (90) turtle.fd (75) turtle.setheading (180) turtle.fd (20) turtle.pensize (4) turtle.pendown () turtle.circle (2 Turtle.setheading (0) turtle.penup () turtle.fd (40) turtle.pensize (4) turtle.pendown () turtle.circle (- 2,360) turtle.penup () turtle.goto (x Y) turtle.setheading (- 90) turtle.pendown () turtle.fd (20) turtle.setheading (0) turtle.fd (35) turtle.setheading (60) turtle.fd (10) turtle.penup () turtle.goto (x Y) turtle.setheading (- 90) turtle.pendown () turtle.fd (40) turtle.setheading (0) turtle.fd (35) turtle.setheading (- 60) turtle.fd (10) turtle.penup () turtle.goto (x Y) turtle.setheading (- 90) turtle.pendown () turtle.fd (60) turtle.setheading (- 135) turtle.fd (60) turtle.bk (60) turtle.setheading (- 45) turtle.fd (30) turtle.setheading (- 35) turtle.fd (35) turtle.penup () # first screen Display text def page0 (): turtle.penup () turtle.goto (- 350,0) turtle.color ('black') turtle.write (' our Valentine's Day', font= ('Verdana', 60, 'normal')) time.sleep (3) # second picture Def page1 (): turtle.speed (10) draw_people (- 250,20) turtle.penup () turtle.goto (- 150,- 30) draw_heart (14) turtle.penup () turtle.goto (- 20,-60) draw_heart (25) turtle.penup () turtle.goto Draw_heart (45) turtle.hideturtle () time.sleep (3) # Last screen Def page2 (): turtle.speed (1) turtle.penup () turtle.goto (- 200,200) turtle.color ('blue') turtle.pendown () turtle.write (' ZBT CJH', font= ('wisdom', 50,' normal')) turtle.penup () turtle.goto (0,180) draw_heart (10) arrow_heart (20,-60) 51) turtle.showturtle () def main (): turtle.setup (900500) page0 () clear_all () page1 () clear_all () page2 () turtle.done () main ()
The running screenshot is shown in the following figure, in which the initials can be modified by yourself.
The above is all the contents of the article "how to draw Love patterns with turtle Module in Python". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.