In the past two days, with the opening of the Beijing Winter Olympics, the mascot "Bing Dun Dun" has become popular, and many people queuing up to buy it. It is said that some people have even raised the price to several thousand yuan.
Even under yesterday's "Tigers and Tigers" article, some classmates asked for Bingdundun
In order to help everyone realize "one household, one pier" as soon as possible, Crossin worked overtime all night and came up with this:
Python version of Bingdundun
Not much to say, directly to the effect
Drawing process:
https://www.bilibili.com/video/BV1u5411f71L/?aid=466259912&cid=503909643&page=1
into a picture:
To be honest, this has no technical content, it is just hard "liver" and constantly adjusts the details of the curve.
The turtle library that comes with Python is used. This library has been introduced many times before, so I won't be verbose. Search for "turtle" or "turtle mapping" in historical articles and you can see it.
Talk about a little trick for drawing with turtle: you can pass
turtle.bgpic(r'bg.png')
This statement draws the picture you want to refer to in the window first, and then draws and adjusts it according to it, which is much more convenient.
Since the code is relatively long, here is a short snippet for reference:
# 爱心
turtle.penup()
turtle.goto(220, 115)
turtle.pencolor("brown")
turtle.pensize(1)
turtle.fillcolor("brown")
turtle.begin_fill()
turtle.pendown()
turtle.setheading(36)
turtle.circle(-8, 180)
turtle.circle(-60, 24)
turtle.setheading(110)
turtle.circle(-60, 24)
turtle.circle(-8, 180)
turtle.end_fill()
# 五环
turtle.penup()
turtle.goto(-5, -170)
turtle.pendown()
turtle.pencolor("blue")
turtle.circle(6)
turtle.penup()
turtle.goto(10, -170)
turtle.pendown()
turtle.pencolor("black")
turtle.circle(6)
turtle.penup()
turtle.goto(25, -170)
turtle.pendown()
turtle.pencolor("brown")
turtle.circle(6)
turtle.penup()
turtle.goto(2, -175)
turtle.pendown()
turtle.pencolor("lightgoldenrod")
turtle.circle(6)
turtle.penup()
turtle.goto(16, -175)
turtle.pendown()
turtle.pencolor("green")
turtle.circle(6)
turtle.penup()
turtle.pencolor("black")
turtle.goto(-16, -160)
turtle.write("BEIJING 2022", font=('Arial', 10, 'bold italic'))
turtle.hideturtle()
turtle.done()
The complete code is open source on github:
https://github.com/crossin/snippet/tree/master/BingDwenDwen
If it is helpful to you, please like and forward it to support it~
For more tutorials and cases,
Welcome to search and follow: Crossin's programming classroom
5 minutes a day, easy to learn programming.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。