cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
331
Views
1
Helpful
0
Replies

Meme Monday: Carving pumpkin with code

yawming
Cisco Employee
Cisco Employee

It's October, and Halloween is just around the corner. Would you like to carve a virtual pumpkin? You can use the Python Turtle module to do it.

Just like carving a real pumpkin, if you haven't done it before, you can learn from someone with experience or search online for instructions on how to carve a pumpkin. Similarly, when it comes to virtual carving,I know we can use Turtle module, but I don't know how to do it exactly, so I searched online for how people have done it, and this is my version. It might look a bit silly, doesn't it?

yawming_0-1696258676329.png

 

Tools:
    Mac pro terminal
    Python 3.11
    Python turtle module


Codes:

 

import turtle as t

# Set up the screen with black background
t.speed(0)
t.bgcolor("black")
t.title("Jack-o'-Lantern")

# Draw the pumpkin body
t.penup()
t.goto(0, -200)
t.pendown()
t.color("orange") #of cause
t.begin_fill()
t.circle(200)
t.end_fill()

# Draw the eyes
t.penup()
t.goto(-80, 100)
t.pendown()
t.color("black")
t.begin_fill()
t.circle(30)
t.end_fill()

t.penup()
t.goto(80, 100)
t.pendown()
t.color("black")
t.begin_fill()
t.circle(30)
t.end_fill()

# Draw the nose
t.penup()
t.goto(0, 50)
t.pendown()
t.color("purple")
t.begin_fill()
t.goto(30, -20)
t.goto(-30, -20)
t.goto(0, 50)
t.end_fill()

# Draw the mouth to be saw-like
t.penup()
t.goto(-60, -80)
t.pendown()
t.color("red")
t.width(5)
t.setheading(45)  # Set the Turtle's heading to 45 degrees
for _ in range(6):
    t.forward(15)
    t.right(90)
    t.forward(15)
    t.left(90)
t.hideturtle()
# Close the Turtle graphics window when clicked
t.exitonclick()

 



 

 

0 Replies 0