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 write a tool to enjoy the moon with python

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article introduces you how to use python to write the moon appreciation tool, the content is very detailed, interested friends can refer to, hope to be helpful to you.

When you see the full moon again during the Mid-Autumn Festival

Introduction

Suppose that on August 15 of the lunar calendar, programmers miss this year's Mid-Autumn Festival full moon.

Only they know the suffering of programmers.

Bug,bug...

Change bug when eating, bug when walking, bug when dating, bug when getting married

Even the Mid-Autumn Festival! Yes! Change! Bug!

But as a programmer who knows the "border town" and knows the programming, nothing can stop him.

"isn't it the full moon of the Mid-Autumn Festival?" Three minutes later... The programmer drew one himself with Python.

Python version of the Mid-Autumn Festival full moon! Even if I can, I can enjoy the Mid-Autumn Festival every day.

Text

Environment installation: use turtle to draw, game module pygame module as usual.

(1) draw the full moon first. Def drawMoon (): turtle.penup () # Brush pick up turtle.goto (- 150,0) turtle.fillcolor ((255,215) 0) # Color of the full moon turtle.pendown () # Brush put down turtle.begin_fill () turtle.circle (112) turtle.end_fill () # turtle.begin_fill () to turtle.end_fill () Color fill (2) and then draw the clouds.

It's a little complicated, because the clouds are fluttering, so it's a little more difficult than the moon.

Def drawCloud (): turtle.penup () turtle.goto (- 500,200) turtle.fillcolor ((245,245,245)) turtle.pencolor ((255,255) Turtle.pensize (5) turtle.pendown () turtle.forward (250,250) def cloud (mode='right'): for i in range (90): turtle.pensize ((item1) * 0.2 / 5) turtle.right (1) if mode= = 'right' else turtle.left (1) turtle.forward (0.5) for i in range (90): turtle.pensize (90 / 0.2 / 5- 0.2 * (left') turtle.right (1) if mode = = 'right' else turtle.left (1) turtle.forward (0.5) cloud () turtle.forward (100) cloud (' left') turtle.forward (6) (3) draw mountains and rivers. Def drawMountain (): turtle.penup () turtle.goto (- 500,250) turtle.pensize (4) turtle.fillcolor ((36,36,36)) turtle.pencolor ((31,28) 24) turtle.pendown () turtle.begin_fill () turtle.left (20) turtle.forward (400) turtle.right (45) turtle.forward (60) turtle.forward (300) turtle.right (70) turtle.forward (300) turtle.goto (500,300) turtle.goto (- 500,300) turtle.end_fill () (4) setup interface Music will be played when you enter the interface. Def initTurtle (): pygame.mixer.init () pygame.mixer.music.load ('bgm.mp3') pygame.mixer.music.play (- 1,20.0) turtle.hideturtle () turtle.setup (1000) turtle.title (' Mid-Autumn Festival') turtle.colormode (255) turtle.bgcolor ((193,210,240)) turtle.speed (10) (5) draw verses. Def writePoetry (): turtle.penup () turtle.goto (400,150) turtle.pencolor ((250,240,230)) # verse potery = ["\ nMing\ nmonth\ nA few days\ nYou\ n", "ask for wine\ n green\ nSky\ n"] # verse position (can be designed and added by yourself) Coordinates = [(300,150,200,150)] for I, p in enumerate (potery): turtle.write (p, align= "center", font= ("STXingkai", 50) "bold") if (I + 1)! = len (potery): time.sleep (2) turtle.goto (coincidences [I])

Effect picture:

On how to use python to write and appreciate the moon tool to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

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