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 make a unique confession Picture by Python+Turtle

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how to make a unique confession map by Python+Turtle". In daily operation, I believe many people have doubts about how to make a unique confession map by Python+Turtle. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to make a unique confession map by Python+Turtle". Next, please follow the editor to study!

Before you start, let's take a look at the effect picture, and enter the corresponding parameter settings in the console to generate your own unique confession picture.

What kind of information you want to write on the picture depends on your performance, ha ~

Import turtle as tle # Little Turtle Picture Gallery

Before using turtle tortoise to draw, initialize the global parameters first, and make the global initialization function global_init dynamically pass parameters for later convenient call.

Def global_init (width=w 900, hobby 600, psize=15, sp=0):''global brush attribute initialization function: param w: canvas width: param h: canvas height: param psize: brush size: param sp: painting speed: return:' 'tle.setup (width=w, height=h) tle.color (' red', 'pink') tle.pensize (psize) tle.speed (sp)

After setting the above properties, you can officially start drawing, here in order to make the code structure clear or to create a heart-to-heart function draw_red_heart.

Def draw_red_heart (confession=' I love you, confession_h=30, sign=' admirer from afar, sign_w=20 Sign_h=25):''draw confession Hearts: param confession: confession statement: param confession_h: confession statement size: param sign: signature: param sign_w: signature width: param sign_h: signature height: return:' 'tle.up () tle.hideturtle () tle.goto (0 Tle.showturtle () tle.down () tle.speed (500) tle.begin_fill () tle.left (140) tle.forward (224,200) for n in range: tle.right (1) tle.forward (2) tle.left (120,120) for n in range Tle.forward 224 tle.end_fill () tle.pensize (12) tle.up () tle.hideturtle () tle.goto (0 -20) tle.showturtle () tle.color ('# CD5C5C', 'pink') tle.write (confession, font= (' gungsuh', confession_h), align= "center") tle.up () tle.hideturtle () tle.color ('black',' pink') tle.goto (180,180) tle.showturtle () tle.write (sign, font= (sign_w, sign_h), align= "center", move=True)

Write the main business function main, call the whole drawing program to run.

Def main (): print ('enter the following drawing parameters as required.') Width = int (input ('Please enter canvas width:\ n') height = int (input (' Please enter canvas height:\ n') psize = int (input ('Please enter Brush size:\ n') speed = int (input (' Please enter Brush Speed:\ n') confession = input ('Please enter confession statement:\ N') confession_h = int (input (' Please enter the table White sentence font size:\ n') sign = input ('Please enter signature:\ n') sign_w = int (input (' Please enter signature width:\ n') sign_h = int ('Please enter signature height:\ n') print (' parameter input completed Start drawing.') Global_init (w=width, h=height, psize=psize, sp=speed) draw_red_heart (confession=confession, confession_h=confession_h, sign=sign, sign_w=sign_w, sign_h=sign_h) print ('drawing complete!') # Save the drawing result in eps format eps = tle.getscreen () eps.getcanvas (). Postscript (file=r ". / confession .eps") # Save JPG format picture from PIL import Image im = Image.open (". / confession .eps") im.save ("confession .jpg") print ("drawing saved successfully, default in the current path!') # keep the window open after the drawing is completed screen = tle.Screen () screen.exitonclick ()

Note: the following error is thrown when saving the confession .eps file to a file in JPG format.

Raise OSError ("Unable to locate Ghostscript on paths")

Do not worry at this time, of course, there is a solution, to the ghostscript official website to download the components you need on OK.

Then, install the downloaded gs9561w64.exe executable application.

Remember that after the installation is complete, the path is in this place, and you can uninstall it at any time if you don't need it.

Finally, add the path to the path property of the environment variable and you are done. Restart the development tool so that the environment variable will actually take effect.

Once again, remember to restart IDE after configuring the environment variables.

Main () at this point, the study of "how to make a unique confession map by Python+Turtle" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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