Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Python+Turtle to draw Navigation King Straw Hat Lufei

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article "how to use Python+Turtle to draw the sea king straw hat Lufei" article most people do not understand, so the editor summarized the following content, detailed, clear steps, with a certain reference value, I hope you can get something after reading this article, let's take a look at this "how to use Python+Turtle to draw the nautical king straw hat Lufei" article.

First, the program runs 1. Effect display-outline drawing

Look at the outline drawing effect:

two。 Effect display-Color fill

Color filling effect of clothes and trousers:

Second, the realization process 1. Drawing data download

Get the address

Content Preview:

two。 Sea turtle drawing configuration item

Reducing the refresh rate can improve the drawing speed, the higher the value, the lower the refresh frequency, the faster the speed.

T.tracer (5000)

Def set_trutle ():''function: sea turtle drawing configuration parameter: no return: no''# default color range is [0Power1], switch to [0255] t.Screen () .colormode (255i) # set the starting size t.setup (width=x, height=y) # adjust coordinates T.setworldcoordinates (0jinyjingxjing0) t.pen () # sets the drawing speed, 0 is the fastest t.speed (0) # disables delay speed t.delay (0) # increases speed, the higher the value, the faster the t.tracer (5000) # sets the default brush color to white t.pencolor ((255255255)) # lift brush t.penup () 3. Outline drawing

By dropping the brush t.pendown ()

And lift the brush t.penup ()

To avoid connection problems.

Def draw_lufei_outline ():''function: draw Lufei profile parameters: no return: no''# data file read f=open ("lufei.txt" "r") bigmom_date = f.read (). Split (") for i in bigmom_date: try: # data separation and transformation j = i.split (" _ ") x1 = round (float (j [0])) y1 = round (float (j [1])) color = j [2] [1mur1] .split (" ") color [0] = int (color [0]) color [1] = int (color [1]) color [2] = int (color [2]) if ((color [0] * 0.299 + color [1] * 0.587 + color [2] * 0.114) > 50): color = (255255255) # falling brush t.pendown () # solves the problem of drawing only half of the image t.sety (y1) # trajectory tracking and painting t.goto (x1) Y1) t.color (color) # lift brush t.penup () except Exception as e: print () f.close () print ("outline drawing complete")

Effect illustration:

4. Color filling: clothes, trousers

Draw the red and blue of clothes and trousers.

Def draw_lufei_tintage1 ():''function: Luffy color fill: clothes, hat parameters: no return: no''# data file read f=open ("lufei.txt" "r") bigmom_date = f.read (). Split (") for i in bigmom_date: try: # data separation and transformation j = i.split (" _ ") x1 = int (j [0]) y1 = int (j [1]) color = j [2] [1MAV 1] .split (" ") color [0] = int (color [0]) color [1] = int (color [1]) color [2] = int (color [2]) if ((color [0] * 0.299 + color [1] * 0.587 + color [2] * 0.114) > 150): color = (255255255) # falling brush t.pendown () # solves the problem of drawing only half of the image t.sety (y1) # trajectory tracking and painting t.goto (x1) Y1) t.color (color) # lift brush t.penup () except Exception as e: print () f.close () print ("painting done")

Effect illustration:

5. Color filling: straw hat, belt

Draw the yellow of the straw hat and belt.

Def draw_lufei_tintage2 ():''function: Luffy color fill: straw hat, belt parameters: no return: no''# data file read f=open ("lufei.txt" "r") bigmom_date = f.read (). Split (") for i in bigmom_date: try: # data separation and transformation j = i.split (" _ ") x1 = int (j [0]) y1 = int (j [1]) color = j [2] [1MAV 1] .split (" ") color [0] = int (color [0]) color [1] = int (color [1]) color [2] = int (color [2]) if ((color [0] * 0.299 + color [1] * 0.587 + color [2] * 0.114) > 215): color = (255255255) # falling brush t.pendown () # solves the problem of drawing only half of the image t.sety (y1) # trajectory tracking and painting t.goto (x1) Y1) t.color (color) # lift brush t.penup () except Exception as e: print () f.close () print ("painting done")

Effect illustration:

6. Complete source code #-*-coding:utf-8-*-# 2022-3-author: blue jujube # Image drawing: Luffy import turtle as timport timex = 224y = 345def set_trutle ():''function: sea turtle drawing configuration parameter: no return: no' # default color range is [0Magin1] Switch to [0255] t.Screen (). Colormode (0255) # set the starting size t.setup (width=x, height=y) # adjust the coordinates, t.setworldcoordinates (0meme yjournal 0) t.pen () # set the drawing speed, 0 is the fastest t.speed (0) # disable delay speed t.delay (0) # speed up The higher the value, the faster the t.tracer (5000) # set the default brush color to white t.pencolor ((255255255)) # lift the brush t.penup () def draw_lufei_outline ():''function: draw the flying outline parameter: no return: no''# data file read f=open ("lufei.txt") "r") bigmom_date = f.read (). Split (") for i in bigmom_date: try: # data separation and transformation j = i.split (" _ ") x1 = round (float (j [0])) y1 = round (float (j [1])) color = j [2] [1mur1] .split (" ") color [0] = int (color [0]) color [1] = int (color [1]) color [2] = int (color [2]) if ((color [0] * 0.299 + color [1] * 0.587 + color [2] * 0.114) > 50): color = (255255255) # falling brush t.pendown () # solves the problem of drawing only half of the image t.sety (y1) # trajectory tracking and painting t.goto (x1) Y1) t.color (color) # lift brush t.penup () except Exception as e: print () f.close () print ("outline drawn") def draw_lufei_tintage1 ():''function: Lufei color filling: clothes, Hat parameter: no return: no''# data file read f=open ("lufei.txt" "r") bigmom_date = f.read (). Split (") for i in bigmom_date: try: # data separation and transformation j = i.split (" _ ") x1 = int (j [0]) y1 = int (j [1]) color = j [2] [1MAV 1] .split (" ") color [0] = int (color [0]) color [1] = int (color [1]) color [2] = int (color [2]) if ((color [0] * 0.299 + color [1] * 0.587 + color [2] * 0.114) > 150): color = (255255255) # falling brush t.pendown () # solves the problem of drawing only half of the image t.sety (y1) # trajectory tracking and painting t.goto (x1) Y1) t.color (color) # lift brush t.penup () except Exception as e: print () f.close () print ("painting done") def draw_lufei_tintage2 ():''function: Lufei color filling: straw hat, Belt parameter: no return: no''# data file read f=open ("lufei.txt" "r") bigmom_date = f.read (). Split (") for i in bigmom_date: try: # data separation and transformation j = i.split (" _ ") x1 = int (j [0]) y1 = int (j [1]) color = j [2] [1MAV 1] .split (" ") color [0] = int (color [0]) color [1] = int (color [1]) color [2] = int (color [2]) if ((color [0] * 0.299 + color [1] * 0.587 + color [2] * 0.114) > 215): color = (255255255) # falling brush t.pendown () # solves the problem of drawing only half of the image t.sety (y1) # trajectory tracking and painting t.goto (x1) Y1) t.color (color) # lift brush t.penup () except Exception as e: print () f.close () print ("painting done") set_trutle () draw_lufei_outline () draw_lufei_tintage1 () draw_lufei_tintage2 () time.sleep (10000) above is about "how to" Use Python+Turtle to draw the content of the article "Navigation King Straw Hat Lufei" I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report