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 Christmas Tree and Christmas Tree word Cloud by Python

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

Share

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

This article will explain in detail how Python makes Christmas trees and Christmas tree word clouds. Xiaobian thinks it is quite practical, so share it with you for reference. I hope you can gain something after reading this article.

I. Foreword

Christmas celebrations and gift-giving seem to have become a popular habit around the world.

This article uses Python to make Christmas trees and word clouds, teach you a variety of methods, code can be run directly, learn to give it to those you want to bless ~~

Python draws Christmas trees 1. Christmas Tree No.1 # -*- coding: UTF-8-*-""@Author: Ye Tingyun @ Wechat Official Account : AI Tingyunjun @CSDN :https://yetingyun.blog.csdn.net/"""import turtlescreen = turtle.Screen()screen.setup(800, 600)circle = turtle.Turtle()circle.shape('circle')circle.color('red')circle.speed('fastest')circle.up()square = turtle.Turtle()square.shape('square')square.color('green')square.speed('fastest')square.up()circle.goto(0, 280)circle.stamp()k, j = 0, 0for i in range(1, 17): y = 30 * i for j in range(i - k): x = 30 * j square.goto(x, -y + 280) square.stamp() square.goto(-x, -y + 280) square.stamp() if i % 4 == 0: x = 30 * (j + 1) circle.color('red') circle.goto(-x, -y + 280) circle.stamp() circle.goto(x, -y + 280) circle.stamp() k += 2 if i % 4 == 3: x = 30 * (j + 1) circle.color('yellow') circle.goto(-x, -y + 280) circle.stamp() circle.goto(x, -y + 280) circle.stamp()square.color('brown')for i in range(17, 20): y = 30 * i for j in range(3): x = 30 * j square.goto(x, -y + 280) square.stamp() square.goto(-x, -y + 280) square.stamp() turtle.mainloop()

The effects are as follows:

2. Christmas Tree No.2 # -*- coding: UTF-8-*-""@Author: Ye Tingyun @ Public Number: AI Tingyun @CSDN yetingyun.blog.csdn.net/ ""from turtle import *import turtle import randomn = 100.0speed(96)turtle.setup(width=800, height=720)#screensize is the canvas size and background colorscreensize (800, 800, "White")left(90)forward(3 * n)color("red", "yellow") #pentagram begin_fill()left(126)for i in range(5): forward(n / 5) right(144) forward(n / 5) left(72)end_fill()right(126)#Christmas tree color("#00CC00")backward(n * 4.8)def tree(d, s): if d 1]print(result_list)#Personally recommended palette color scheme works well Other tests have been done and feel average ~~# colorbrewer.qualitative.Dark2_7# cartocolors.qualitative.Bold_5# colorbrewer.qualitative.Set1_8gen_stylecloud( text=' '.join(result_list), #Text data size=600, #word cloud size font_path=r'./ font/Cat Chews Net Candy Round Body. ttf', #Chinese word cloud display needs to set font icon_name = "fas fa-tree", #icon output_name='./ results/Christmas tree 06.png', #Output word cloud name palette='cartocolors.qualitative.Bold_5', #Choose a color scheme)

The effect is as follows:

IV. Egg

On Gitee, I also found that someone uploaded exe that can directly generate Christmas trees (seems to be C#?), The effect is as follows:

About "Python how to make Christmas tree and Christmas tree word cloud" this article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people 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