반응형
[python] Code: Turtle Yellow Heart on Black Background
import turtle
def draw_heart():
# Setup the screen
screen = turtle.Screen()
screen.bgcolor("black") # Set background color to black
screen.title("Yellow Heart")
# Setup the turtle
heart = turtle.Turtle()
heart.shape("turtle")
heart.speed(10) # Set drawing speed
heart.color("yellow") # Set the pen color to yellow
heart.fillcolor("yellow") # Set the fill color to yellow
# Start drawing the heart
heart.begin_fill()
heart.left(50) # Tilt left to start the heart shape
heart.forward(133) # Draw the left curve
# Left curve
heart.circle(50, 200) # Radius 50, 200 degrees
# Right curve
heart.right(140) # Turn right to align for the other half
heart.circle(50, 200) # Radius 50, 200 degrees
heart.forward(133) # Complete the right curve
heart.end_fill() # Fill the shape with the selected color
# Finish up
heart.hideturtle() # Hide the turtle pointer
screen.mainloop() # Keep the window open
# Call the function
if __name__ == "__main__":
draw_heart()
반응형
'프로그래밍 > Python' 카테고리의 다른 글
[python] Generate OTP using python (1) | 2024.12.13 |
---|---|
[python] Rich is a Python library for rich text and beautiful formatting in the terminal. (0) | 2024.12.11 |
[python] Spiral Web using Matplotlib and NumPy (0) | 2024.12.03 |
[python] 초를 입력 받으면 카운트다운 하는 간단한 타이머 (0) | 2024.12.02 |
[python] pip install wifi-qrcode-generator (0) | 2024.11.27 |