Python Turtle Program To Make Iron Man


Hey there, welcome to a new post. In this post I am gonna talk about how to make the face of Iron Man using python turtle. It's a bit tricky yet simple. Many 11-12 class CS students find it very simple to make and learnt the whole program. It would be harder if you don't have some experience in python's turtle library. Without wasting your important time, let's just get to the code because, 

Talk is cheap. Show me the code 😎

The Code Is As Follows


from turtle import *

cords1 = [[(-40, 120), (-70, 260), (-130, 230), (-170, 200), (-170, 100), (-160, 40), (-170, 10), (-150, -10), (-140, 10),
           (-40, -20), (0, -20)],[(0, -20), (40, -20), (140, 10), (150, -10), (170, 10), (160, 40), (170, 100), (170, 200), (130, 230), (70, 260),
           (40, 120), (0, 120)]]
          
cords2 = [[(-40, -30), (-50, -40), (-100, -46), (-130, -40), (-176, 0), (-186, -30), (-186, -40), (-120, -170), (-110, -210),
           (-80, -230), (-64, -210), (0, -210)],
          [(0, -210), (64, -210), (80, -230), (110, -210), (120, -170), (186, -40), (186, -30), (176, 0), (130, -40),
           (100, -46), (50, -40), (40, -30), (0, -30)]]
cords3 = [[(-60, -220), (-80, -240), (-110, -220), (-120, -250), (-90, -280), (-60, -260), (-30, -260), (-20, -250),
           (0, -250)],
          [(0, -250), (20, -250), (30, -260), (60, -260), (90, -280), (120, -250), (110, -220), (80, -240), (60, -220),
           (0, -220)]]

hideturtle()
bgcolor("#a30d0d") # Dark Red
setup(500, 600)
title("I AM IRONMAN")
cords1Goto = (0, 120)
cords2Goto = (0, -30)
cords3Goto = (0, -220)
speed(4)


def logo(a, b):
    penup()
    goto(b)
    pendown()
    color("#fcb103") # Light Yellow
    begin_fill()

    for i in range(len(a[0])):
        x, y = a[0][i]
        goto(x, y)

    for i in range(len(a[1])):
        x, y = a[1][i]
        goto(x, y)
    end_fill()


logo(cords1, cords1Goto)
logo(cords2, cords2Goto)
logo(cords3, cords3Goto)
hideturtle()
done()

We will divide the Iron Man's face in three parts. In the variable 'cords1' I have included the coordinates for the upper part of the face, in the 'cords2' variable I have included the coordinates of the middle part of the face and in the 'cords3' variable I have included the coordinates of the bottom part of the face. 

I think my approach for making the face oc Iron Man's face was easy. If you have an easier approach for the same, tell me in the comments. See you in my next post. Ba-Bye.


1 Comments

  1. If you are a tech lover,
    Don't forget to reach out to "techbuddy2023"🤨😁

    ReplyDelete