Sunday, January 8, 2023

Python Turtle Graphics Drawing - Batman Logo

Python Turtle Graphics Drawing - Batman Logo

Youtube

Featuring: 

Bézier curve



Source code:

from turtle import *
from math import atan2,degrees
setup(750,450)

YEL = '#FFF800'
BLK = '#000000'

def cbezto(b,c,d):
    a=pos()
    t = 0.0
    while t <= 1.0:
        t3 = t**3
        t2 = t**2
        f1 = -t3+3*t2-3*t+1
        f2 = 3*t3-6*t2+3*t
        f3 = -3*t3+3*t2
        f4 = t3
        x = a[0]*f1 + b[0]*f2 + c[0]*f3 + d[0]*f4
        y = a[1]*f1 + b[1]*f2 + c[1]*f3 + d[1]*f4
        d1 = -3*t2+6*t-3
        d2 = 9*t2-12*t+3
        d3 = -9*t2+6*t
        d4 = 3*t2
        dx = a[0]*d1 + b[0]*d2 + c[0]*d3 + d[0]*d4
        dy = a[1]*d1 + b[1]*d2 + c[1]*d3 + d[1]*d4
        angr = atan2(dy, dx)
        seth(degrees(angr))
        goto(x, y)
        t += 0.05
    goto(d)


up()
lt(90)
fd(200)
down()
color(BLK)
begin_fill()
cbezto((203,198),(350,107),(350,0))
cbezto((350,-107),(203,-198),(0,-200))
cbezto((-203,-198),(-350,-107),(-350,0))
cbezto((-350,107),(-203,198),(0,200))
end_fill()

color(YEL)
up()
rt(93.1)
fd(10)
down()
begin_fill()
cbezto((208,188),(339,99),(340,0))
cbezto((339,-99),(208,-188),(0,-190))
cbezto((-208,-188),(-339,-99),(-340,0))
cbezto((-339,99),(-208,188),(0,190))
end_fill()

color(BLK)
up()
rt(93)
fd(331)
down()
begin_fill()
cbezto((21,-55),(81,-38),(107,-85))
cbezto((166,-17),(242,-75),(185,-129))
cbezto((391,-47),(323,106),(131,149))
cbezto((194,65),(91,23),(48,64))
cbezto((39,94),(36,127),(36,166))
lt(150.8)
fd(47.9)
rt(61.3)
fd(26)
rt(61.3)
fd(47.9)
cbezto((-36,127),(-39,94),(-48,64))
cbezto((-91,23),(-194,65),(-131,149))
cbezto((-323,106),(-391,-47),(-185,-129))
cbezto((-242,-75),(-166,-17),(-107,-85))
cbezto((-81,-38),(-21,-55),(0,-141))
end_fill()
hideturtle()
done()

No comments:

Post a Comment

Python Turtle Graphics Drawing - Gigabyte

 Python Turtle Graphics Drawing - Gigabyte Youtube Source code: from turtle import * setup ( 600 , 600 ) color ( '#2D68AE' ) up (...