Tuesday, January 10, 2023

Python Turtle Graphics Drawing - React JS Logo

Python Turtle Graphics Drawing - React JS Logo

Youtube


Source code:

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

'''
Draw Bezier Curve
'''
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)

'''
Rotate Point
'''
def rot(p, a):
    ang = radians(a)
    x = p[0] * cos(ang) - p[1] * sin(ang)
    y = p[0] * sin(ang) + p[1] * cos(ang)
    return (x, y)

setup(560, 560)
bgcolor('black')
color("#61DBFB")
up()
pensize(22)
#Bezier points
PTS = [
    [(242, 38),(172, 92),(-0, 92)],
    [(-172, 92),(-242, 38),(-242, 0)],
    [(-242, -38),(-172, -92),(0, -92)],
    [(172, -92),(242, -38),(242, -0)]
]
for i in range(3):
    ang = i * 60
    goto(rot((242, 0), ang))
    down()
    for j in range(4):
        p1 = rot(PTS[j][0],ang)
        p2 = rot(PTS[j][1],ang)
        p3 = rot(PTS[j][2],ang)
        cbezto(p1,p2,p3)
    up()

goto(45, 0)
seth(90)
down()
pensize(0)
begin_fill()
circle(45)
end_fill()
hideturtle()
bgcolor('white')
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 (...