Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Anurag Rana
Anurag Rana

Posted on • Originally published atpythoncircle.com

     

Wishing Merry Christmas in Pythonic way

Merry Christmas everyone.

Since this is Christmas today, I thought of wishing everyone in a different way. I am python programmer and I love writing code so I decided to do something with python and after 1 hour I was ready with the below script to wish all of you Merry Christmas using python turtle.

Code is available onGithub as well.

fromturtleimport*fromrandomimportrandintdefcreate_rectangle(turtle,color,x,y,width,height):turtle.penup()turtle.color(color)turtle.fillcolor(color)turtle.goto(x,y)turtle.pendown()turtle.begin_fill()turtle.forward(width)turtle.left(90)turtle.forward(height)turtle.left(90)turtle.forward(width)turtle.left(90)turtle.forward(height)turtle.left(90)# fill the above shapeturtle.end_fill()# Reset the orientation of the turtleturtle.setheading(0)defcreate_circle(turtle,x,y,radius,color):oogway.penup()oogway.color(color)oogway.fillcolor(color)oogway.goto(x,y)oogway.pendown()oogway.begin_fill()oogway.circle(radius)oogway.end_fill()BG_COLOR="#0080ff"# "Yesterday is history, tomorrow is a mystery, but today is a gift. That is why it is called the present.”#                                                       — Oogway to Po under the peach tree, Kung Fu Pandaoogway=Turtle()# set turtle speedoogway.speed(2)screen=oogway.getscreen()# set background colorscreen.bgcolor(BG_COLOR)# set tile of screenscreen.title("Merry Christmas")# maximize the screenscreen.setup(width=1.0,height=1.0)y=-100# create tree trunkcreate_rectangle(oogway,"red",-15,y-60,30,60)# create treewidth=240oogway.speed(10)whilewidth>10:width=width-10height=10x=0-width/2create_rectangle(oogway,"green",x,y,width,height)y=y+height# create a star a top of treeoogway.speed(1)oogway.penup()oogway.color('yellow')oogway.goto(-20,y+10)oogway.begin_fill()oogway.pendown()foriinrange(5):oogway.forward(40)oogway.right(144)oogway.end_fill()tree_height=y+40# create moon in sky# create a full circlecreate_circle(oogway,230,180,60,"white")# overlap with full circle of BG color to make a crescent shapecreate_circle(oogway,220,180,60,BG_COLOR)# now add few stars in skyoogway.speed(10)number_of_stars=randint(20,30)# print(number_of_stars)for_inrange(0,number_of_stars):x_star=randint(-(screen.window_width()//2),screen.window_width()//2)y_star=randint(tree_height,screen.window_height()//2)size=randint(5,20)oogway.penup()oogway.color('white')oogway.goto(x_star,y_star)oogway.begin_fill()oogway.pendown()foriinrange(5):oogway.forward(size)oogway.right(144)oogway.end_fill()# print greeting messageoogway.speed(1)oogway.penup()msg="Merry Christmas from ThePythonDjango.Com"oogway.goto(0,-200)# y is in minus because tree trunk was below x axisoogway.color("white")oogway.pendown()oogway.write(msg,move=False,align="center",font=("Arial",15,"bold"))oogway.hideturtle()screen.mainloop()

Output Video:

https://youtu.be/mjhoQonjVDk

More fromhttps://www.pythoncircle.com

-How To Host Django App On Pythonanywhere For Free
-Difference Between List, Set And Tuples In Python And More Such Comparisons
-How To Create Completely Automated Telegram Channel With Python
-Elastic Search With Kibana And Django

Top comments(4)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
codemouse92 profile image
Jason C. McDonald
Author. Speaker. Time Lord. (Views are my own)
  • Email
  • Location
    Time Vortex
  • Pronouns
    he/him
  • Work
    Author of "Dead Simple Python" (No Starch Press)
  • Joined

Where in the world do you celebrate Christmas on June 26th? ;)

Fun post nonetheless!

P.S. Consider cross-posting your articles directly on DEV.to with a linkback. You'll get a lot more readership that way. :)

CollapseExpand
 
anuragrana profile image
Anurag Rana
Backend Developer. Working on Python and Java. Writes about Python and Django on https://www.pythoncircle.com
  • Joined

Hi Jason,

I wrote this article on Christmas last year. Copy pasted the same on dev.to few days back.

"Consider cross-posting your articles directly on DEV.to with a linkback." - So I just need to include a link to the original article at the top of the content. Is that all or something else needs to be done?

CollapseExpand
 
codemouse92 profile image
Jason C. McDonald
Author. Speaker. Time Lord. (Views are my own)
  • Email
  • Location
    Time Vortex
  • Pronouns
    he/him
  • Work
    Author of "Dead Simple Python" (No Starch Press)
  • Joined

The top or bottom, yes. You can also (optionally) use thecanonical_url = variable in the Front Matter variables (where title, tag, and description are set).

Just make sure you do indeed post thewhole article. We're trying to cut down on the recent influx of click-farming (as I call it), where people use DEV.to simply as a vehicle to promote their own websites. I know you're not doing this, but it's been a problem across the board.

Thanks for being here!

Thread Thread
 
anuragrana profile image
Anurag Rana
Backend Developer. Working on Python and Java. Writes about Python and Django on https://www.pythoncircle.com
  • Joined

Thanks Jason.

I will make sure I post the whole article every time.

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Backend Developer. Working on Python and Java. Writes about Python and Django on https://www.pythoncircle.com
  • Joined

More fromAnurag Rana

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp