Wednesday, November 30, 2022

Python Turtle Graphics Drawing - Pepsi Logo

 Python Turtle Graphics Drawing - Pepsi Logo

Youtube



Bézier curve algorithm is from wikipedia


Source code:
from turtle import *
from math import atan2,degrees

D = 0.1 #bezier step
R = '#ED1B38'
B = '#005993'
W = '#FFFFFF'
K = '#000000'
def Bez(a,b,c,d):
    up()
    goto(a)
    down()
    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+=D
    goto(d)

def Pepsi(sz):
    color(W)
    up()
    seth(0)
    fd(sz)
    lt(90)
    down()
    begin_fill()
    circle(sz)
    end_fill()
    up()
    color(R)
    lt(90)
    fd(sz)
    rt(126.7)
    fd(sz*0.95)
    lt(90)
    down()
    begin_fill()
    circle(sz*0.95,163.1)
    p = pos()
    pts = [p,p+(sz*0.74275,sz*0.2308),p+(sz*1.14545,sz*0.74895),p+(sz*1.33245,sz*1.32555)]
    Bez(*pts)
    end_fill()
    up()
    color(B)
    seth(233.3)
    fd(sz*0.95)
    rt(13.3)
    fd(sz*0.95)
    lt(90)
    down()
    begin_fill()
    circle(sz*0.95,173)
    p = pos()
    pts = [p,p+(sz*0.10705,sz*-0.35325),p+(sz*-0.0774,sz*-0.6761),p+(sz*-0.38725,sz*-0.8211)]
    Bez(*pts)
    p = pos()
    pts = [p,p+(sz*-0.23155,sz*-0.10975),p+(sz*-0.70985,sz*-0.1699),p+(sz*-1.138,sz*-0.30585)]
    Bez(*pts)
    end_fill()
    up()


setup(640,650)
bgcolor(K)
Pepsi(300)
hideturtle()
done()

Python Turtle Graphics Drawing - Superman Logo

 Python Turtle Graphics Drawing - Superman Logo

Youtube


Bézier curve algorithm is from wikipedia


Source code:

from turtle import *
from math import atan2, degrees

D = 0.1  # bezier step
R = '#C80000'
Y = '#FFEB00'
K = '#000000'


def drawPt(ar): #not used
    p = pos()
    h = heading()
    up()
    color('lime')
    for a in ar:
        goto(a)
        seth(0)
        fd(5)
        lt(90)
        begin_fill()
        circle(5)
        end_fill()
    goto(p)
    seth(h)


def Bez(a, b, c, d):
    up()
    goto(a)
    down()
    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 += D
    goto(d)


def Superman(sz):
    global D
    seth(270)
    up()
    fd(sz*0.5)
    down()
    color(K)
    begin_fill()  # 1
    rt(139.36)
    fd(sz*1.0245)
    rt(86.68)
    fd(sz*0.3208)
    rt(43.96)
    fd(sz*0.8727)
    rt(43.96)
    fd(sz*0.3208)
    rt(86.68)
    fd(sz*1.0245)
    end_fill()
    up()
    rt(139.36)
    fd(sz*0.0319)
    lt(40.645)
    down()
    begin_fill()  # 2
    color(R)
    fd(sz*0.9807)
    rt(86.68)
    fd(sz*0.2928)
    rt(43.96)
    fd(sz*0.8559)
    rt(43.96)
    fd(sz*0.2928)
    rt(86.68)
    fd(sz*0.9807)
    end_fill()
    up()
    rt(139.36)
    fd(sz*0.0759)
    lt(40.645)
    down()
    color('black')
    begin_fill()  # 3
    fd(sz*0.2833)
    rt(148.07)
    circle(sz*0.6521, 32.31)
    rt(145.63)
    fd(sz*0.2732)
    rt(139.36)
    end_fill()
    up()
    fd(sz*0.0329)
    down()
    begin_fill()  # 4
    color(Y)
    lt(40.645)
    fd(sz*0.1939)
    rt(144.16)
    circle(sz*0.6061, 23.52)
    rt(140.84)
    fd(sz*0.1845)
    lt(40.75)
    end_fill()
    up()
    fd(sz*0.0329)
    rt(139.36)
    fd(sz*0.7272)
    down()
    color(K)
    begin_fill()  # 5
    fd(sz*0.1478)
    rt(86.68)
    fd(sz*0.2315)
    rt(43.96)
    fd(sz*0.1107)
    lt(35.03)
    circle(-sz*0.4476, -42.87)
    end_fill()
    up()
    rt(127.21)
    fd(sz*0.7272)
    lt(139.25)
    fd(sz*0.0329)
    lt(40.75)
    fd(sz*0.7421)
    down()
    color(Y)
    begin_fill()  # 6
    fd(sz*0.0884)
    rt(86.51)
    fd(sz*0.2034)
    rt(44.19)
    fd(sz*0.0442)
    lt(42.32)
    circle(-sz*0.4684, -30.60)
    end_fill()
    up()
    color('black')
    rt(122.19)
    fd(sz*0.7421)
    rt(40.69)
    fd(sz*0.0329)
    rt(139.31)
    fd(sz*0.4045)
    down()
    begin_fill()  # 7
    fd(sz*0.2127)
    pt = pos()
    pts = [pt, pt+(sz*0.156, sz*-0.029), pt +
           (sz*0.269, sz*-0.037), pt+(sz*0.385, sz*-0.043)]
    Bez(*pts)
    pt = pos()
    pts = [pt, pt+(sz*0.091, sz*-0.005), pt +
           (sz*0.249, sz*-0.008), pt+(sz*0.283, sz*-0.044)]
    Bez(*pts)
    pt = pos()
    pts = [pt, pt+(sz*0.016, sz*-0.017), pt +
           (sz*0.016, sz*-0.038), pt+(sz*-0.006, sz*-0.066)]
    Bez(*pts)
    pt = pos()
    pts = [pt, pt+(sz*-0.015, sz*-0.018), pt+(sz*-0.056,
           sz*-0.047), pt+(sz*-0.279, sz*-0.039)]
    Bez(*pts)
    seth(36.58+90)
    circle(sz*0.1705, 92.21)
    end_fill()
    up()
    lt(91.91)
    color(Y)
    fd(sz*0.4045)

    lt(139.25)
    fd(sz*0.0329)
    lt(40.75)
    fd(sz*0.5322)
    lt(180)

    down()
    begin_fill()  # 8
    fd(sz*0.1313)
    rt(99.58)
    circle(sz*0.1997, -80.15)
    rt(131.48)
    fd(sz*0.1140)
    pt = pos()
    pts = [pt, pt+(sz*0.0598, sz*0), pt+(sz*0.1222, sz*0.0099),
           pt+(sz*0.1441, sz*0.0418)]
    Bez(*pts)
    pt = pos()
    pts = [pt, pt+(sz*0.0118, sz*0.0225), pt+(sz*0.0054,
                                              sz*0.0308), pt+(-sz*0.0348, sz*0.0423)]
    Bez(*pts)
    pt = pos()
    pts = [pt, pt+(sz*-0.099, sz*0.029), pt+(sz*-0.311,
           sz*0.012), pt+(sz*-0.563, sz*0.056)]
    Bez(*pts)
    end_fill()
    goto(0, 0)
    color(K)
    seth(270)
    up()
    fd(sz*0.5-sz*0.1079)
    lt(139.355)
    fd(sz*0.6199)
    down()
    begin_fill()  # 9
    fd(sz*0.2542)
    lt(85.82)
    fd(sz*0.1851)
    lt(134.83)
    fd(sz*0.1337)
    rt(90)
    fd(sz*0.1994)
    pt = pos()
    pts = [pt, pt+(sz*-0.013, sz*0.132), pt+(sz*-0.163,
           sz*0.166), pt+(sz*-0.275, sz*0.162)]
    Bez(*pts)
    pt = pos()
    pts = [pt, pt+(sz*-0.183, sz*-0.003), pt+(sz*-0.276,
           sz*-0.08), pt+(sz*-0.224, sz*-0.162)]
    Bez(*pts)
    pt = pos()
    pts = [pt, pt+(sz*0.06, sz*-0.116), pt +
           (sz*0.555, sz*0.037), pt+(sz*0.664, sz*-0.19)]
    D = 0.05
    Bez(*pts)
    D = 0.1
    end_fill()
    up()
    seth(79.76)
    fd(sz*0.0362)
    color(Y)
    down()
    begin_fill()  # 10
    rt(29.69)
    fd(sz*0.2031)
    lt(85.18)
    fd(sz*0.1147)
    lt(134.74)
    fd(sz*0.1036)
    rt(90)
    fd(sz*0.2401)

    pt = pos()
    pts = [pt, pt+(sz*0.002, sz*0.159), pt+(sz*-0.208,
                                            sz*0.175), pt+(sz*-0.346, sz*0.154)]
    Bez(*pts)
    pt = pos()
    pts = [pt, pt+(sz*-0.132, sz*-0.017), pt+(sz*-0.183,
           sz*-0.123), pt+(sz*-0.05, sz*-0.151)]
    Bez(*pts)
    pt = pos()
    pts = [pt, pt+(sz*0.14, sz*-0.039), pt+(sz*0.46, sz*0.041),
           pt+(sz*0.587, sz*-0.134)]
    D = 0.05
    Bez(*pts)
    end_fill()
    up()
    seth(119.09)
    fd(sz*0.2790)
    down()
    begin_fill()  # 11
    color(K)
    rt(81.13)
    circle(sz*0.0769, 62.33)
    lt(79.71)
    fd(sz*0.1135)
    rt(23.66)
    circle(sz*0.1918, -34.43)
    end_fill()
    up()
    color(Y)
    seth(87.68)
    fd(sz*0.0347)
    down()
    begin_fill()  # 12
    rt(30.36)
    circle(sz*0.0391, 29.17)
    lt(93.51)
    fd(sz*0.0242)
    rt(43.96)
    circle(sz*0.3790, -3.94)
    end_fill()
    up()
    goto(0, 0)


setup(600, 600)
bgcolor('white')
Superman(400)
hideturtle()
done()

Sunday, November 27, 2022

Python Turtle Graphics Drawing - Spotify Logo

 Python Turtle Graphics Drawing - Spotify Logo

Youtube


Source code:

from turtle import *
M = [ # radius, pensize, x,y, start angle, angle
    [1.804, 0.0935, -0.15023, -1.42915, 64, 40],
    [1.3955, 0.0775, -0.16654, -1.34771, 62, 44],
    [1.2295, 0.0615, -0.1843, -1.48902, 61, 44],
]


def spotify(sz):
    up()
    seth(0)
    goto(0, 0)
    fd(sz)
    lt(90)
    begin_fill()
    circle(sz)
    end_fill()
    up()
    color('white')
    for m in M:
        goto(sz*m[2], sz*m[3])
        seth(m[4])
        fd(sz*m[0])
        lt(90)
        pensize(sz*m[1]*2)
        down()
        circle(sz*m[0], m[5])
        up()


setup(800, 800)
bgcolor('white')
color('#1AB26B')
spotify(100)


done()

Friday, November 25, 2022

Python Turtle Graphics Drawing - Mitubishi Logo

 Python Turtle Graphics Drawing - Mitubishi Logo

Youtube




Source code:

from turtle import *
from math import cos,radians
setup(640,640)

bgcolor('white')
color('red')

R = 300 #Logo Radius
r = R*cos(radians(30))*2/3
for i in range(3):
    begin_fill()
    fd(r)
    rt(60)
    fd(r)
    lt(60)
    bk(r)
    rt(60)
    bk(r)
    rt(60)
    end_fill()
hideturtle()
done()

Tuesday, November 22, 2022

Python Turtle Graphics Drawing - Adobe Logo

 Python Turtle Graphics Drawing - Adobe Logo

Youtube


Source code:

from turtle import *

def adobe(s):
    up()
    goto(-20*s,17.5*s)
    down()
    begin_fill()
    goto(-5.2*s,17.5*s)
    goto(-20*s,-17.5*s)
    goto(-20*s,17.5*s)
    end_fill()
    up()
    goto(0,4.7*s)
    down()
    begin_fill()
    goto(9.2*s,-17.5*s)
    goto(3.1*s,-17.5*s)
    goto(0.3*s,-10.5*s)
    goto(-6.5*s,-10.5*s)
    goto(0,4.7*s)
    end_fill()
    up()
    goto(5.1*s,17.5*s)
    down()
    begin_fill()
    goto(20*s,17.5*s)
    goto(20*s,-17.5*s)
    goto(5.1*s,17.5*s)
    end_fill()
    up()

setup(640,640)
color('#FA0F00')
adobe(12)
hideturtle()
done()

Sunday, November 20, 2022

Python Turtle Graphics Drawing - Twitter Logo

 Python Turtle Graphics Drawing - Twitter Logo

Youtube



Soure code:
from turtle import *

setup(720, 640)
BLUE = '#3C96D1'
WHITE = 'white'
bgcolor(WHITE)


def circ(x, y, r, c, sa=0, se=360):
    up()
    goto(x, -y)
    seth(sa)
    fd(r)
    lt(90)
    down()
    color(c)
    begin_fill()
    circle(r, se-sa)
    end_fill()


R1 = 276.38
R2 = 195.40
R3 = 97.12

circ(-86.07, -83.12, R1, BLUE, 210, 385)
circ(-213.20, -46.26, R2, WHITE, 180, 330)

circ(-91.53, 10.89, R3, BLUE, 180, 360)
circ(-165.43, -54.50, R3, WHITE, 200, 360)
circ(-121.10, -57.10, R3, BLUE, 170, 370)
circ(-170.23, -141.70, R3, WHITE, 210, 360)
circ(-118.86, -126.53, R3, BLUE, 135, 360)

circ(74.28, -255.43, R2, BLUE, 210, 330)
circ(158.28, -327.35, R2, WHITE, 210, 330)

circ(11.54, -350.11, R1, WHITE, 210, 330)

circ(131.58, -215.44, R3, BLUE, 180, 360)
circ(123.87, -351.55, R2, WHITE, 210, 330)

circ(92.11, -96.20, R3, BLUE, 0, 220)

hideturtle()
done()

Thursday, November 17, 2022

Python Turtle Graphics Drawing - Android Logo

 Python Turtle Graphics Drawing - Android Logo

Youtube


Source code:

from turtle import *
from math import radians,sin,cos

col='#3ADC87'

def drawantenna(sz):
    color('red')
    up()
    fd(sz*0.8)
    down()
    color(col)
    begin_fill()
    rt(90)
    fd(sz*0.03)
    lt(90)
    fd(sz*0.45)
    circle(sz*0.03,180)
    fd(sz*0.45)
    lt(90)
    fd(sz*0.03)
    end_fill()
    color('red')
    up()
    rt(90)
    fd(sz*0.8)


def draweye(sz):
    color('red')
    up()
    fd(0.65*sz)
    rt(90)
    fd(0.08*sz)
    lt(90)
    down()
    color('white')
    begin_fill()
    circle(0.08*sz)
    end_fill()
    color('red')
    up()
    lt(90)
    fd(0.08*sz)
    lt(90)
    fd(0.65*sz)


def drawlogo(sz):
    up()
    x = cos(radians(6))*sz
    y = sin(radians(6))*sz
    rt(90)
    fd(0.25*sz)
    lt(180)
    fd(y)
    rt(90)
    down()
    begin_fill()
    fd(x)
    lt(96)
    circle(sz,180-12)
    lt(96)
    fd(x)
    end_fill()
    lt(60)
    drawantenna(sz)
    lt(180+60)
    drawantenna(sz)
    rt(30)
    fd(y)
    lt(90+45)
    color('white')
    draweye(sz)
    rt(90)
    draweye(sz)
    color('black')
    rt(45)
    fd(0.5*sz+y)
    fnt = ('Century Gothic', round(sz*0.4),'bold')
    write('android', align='center', font=fnt)

setup(640, 640)
bgcolor('white')
color(col)
drawlogo(250)
hideturtle()
done()

Python Turtle Graphics Drawing - Gigabyte

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