This tutorial will create a cartoon-style computer design using the Python turtle library. The design will include a monitor, a keyboard, and some details to make it visually appealing. So guys let's have some fun by making some excellent graphics in Python turtle.
Complete code:
import turtle
# Set up the screen
screen = turtle.Screen()
screen.setup(800, 600)
screen.bgcolor("lightblue")
screen.title("Cartoon Computer Design")
# Create a turtle for drawing
artist = turtle.Turtle()
artist.speed(3)
# Function to draw a rectangle
def draw_rectangle(t, x, y, width, height, color):
t.penup()
t.goto(x, y)
t.pendown()
t.fillcolor(color)
t.begin_fill()
for _ in range(2):
t.forward(width)
t.left(90)
t.forward(height)
t.left(90)
t.end_fill()
# Function to draw a screen (monitor)
def draw_monitor():
# Monitor body
draw_rectangle(artist, -150, 50, 300, 200, "grey")
# Screen
draw_rectangle(artist, -140, 60, 280, 180, "black")
# Function to draw a stand
def draw_stand():
# Stand base
draw_rectangle(artist, -50, -50, 100, 20, "darkgrey")
# Stand neck
draw_rectangle(artist, -20, 0, 40, 50, "darkgrey")
# Function to draw a keyboard
def draw_keyboard():
# Keyboard body
draw_rectangle(artist, -200, -100, 400, 50, "grey")
# Keys (simple lines)
artist.penup()
artist.goto(-180, -90)
artist.pendown()
artist.width(2)
for row in range(4):
for col in range(10):
artist.penup()
artist.goto(-180 + col * 40, -90 - row * 10)
artist.pendown()
draw_rectangle(artist, artist.xcor(), artist.ycor(), 30, 8, "lightgrey")
# Draw the computer
draw_monitor()
draw_stand()
draw_keyboard()
# Hide the turtle and display the design
artist.hideturtle()
screen.mainloop()