Make a heart shape with Python turtle

Asked 2 years ago, Updated 2 years ago, 134 views

I have to make a heart shape with the one that's out here, but it's not working well. If there's anyone who's good at Python, please help me.

import turtle

turtle.colormode(255)
turtle.color(255, 255, 0)

tess = turtle.Turtle()
tess.shape("turtle")
tess.backward(100)

for i in range(0, 100, 5):
    tess.penup()
    tess.goto(i, 50)
    tess.pendown()
    tess.begin_fill()
    tess.color("yellow")
    tess.circle(i)
    tess.end_fill()

    tess.penup()
    tess.goto(-i, 50)
    tess.pendown()
    tess.begin_fill()
    tess.color("red")
    tess.circle(i)
    tess.end_fill()

I tried it, but the shape didn't come out. The red color on the bottom is for reference.

# A program that demonstrates the shaeds of red
# # Fall 2017

import turtle               # Import the turtle package

turtle.colormode(255)       # Allows colors to be given as 0..255
tess = turtle.Turtle()      # Create a turtle
tess.shape("turtle")        # Make it turtle shaped
tess.backward(100)          # Move her backwards, to give more space to draw

# # For 0, 10, 20, ..., 250
for i in range(0, 255, 10):
    tess.forward(10)        # Move forward
    tess.pensize(i)         # Set the drawing size to be i (larger each time)
    tess.color(i, 0, 0)     # Set the red channel to be i (brighter each time)

python turtle

2022-09-20 15:01

1 Answers

I did it because I was bored.

import turtle


def main():
    turtle.colormode(255)
    turtle.color(255, 255, 0)

    tess = turtle.Turtle()
    tess.shape("turtle")
    # # tess.backward(100)

    for i in range(0, 100, 4):
        c = i * 255 // 100
        y = i // 2
        tess.penup()
        tess.goto(4 + i, y)
        tess.pendown()
        tess.begin_fill()
        tess.color(c, c, 0)
        tess.circle(i)
        tess.end_fill()

        tess.penup()
        tess.goto(-i, y)
        tess.pendown()
        tess.begin_fill()
        tess.color(c, c, 0)
        tess.circle(i)
        tess.end_fill()

    input()


if __name__ == "__main__":
    main()
import turtle               # Import the turtle package

turtle.colormode(255)       # Allows colors to be given as 0..255
tess = turtle.Turtle()      # Create a turtle
tess.shape("turtle")        # Make it turtle shaped

tess.left(90)
tess.penup()
tess.backward(200) 
tess.pendown()
tess.right(30)

# # For 0, 10, 20, ..., 250
for i in range(0, 255, 10):
    tess.forward(10)        # Move forward
    tess.pensize(i)         # Set the drawing size to be i (larger each time)
    tess.color(i, i, 0)     # Set the red channel to be i (brighter each time)

tess.penup()
tess.pensize(0)
tess.color(0, 0, 0)
for i in range(0, 255, 10):
    tess.backward(10) 

tess.left(60)
tess.pendown()
for i in range(0, 255, 10):
    tess.forward(10)        
    tess.pensize(i)         
    tess.color(i, i, 0)  
input()    


2022-09-20 15:01

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.