Wednesday, December 7, 2022

Cardioid Animation - Python Turtle Graphics

 Cardioid Animation - Python Turtle Graphics

Youtube


Source code:

from turtle import *
from math import sin,cos,radians
import colorsys as cs

setup(500,500)
bgcolor('black')
R = 200
def getpt(n):
    n = (360/N*n)%360
    a=radians(n)
    x = -cos(a)*R
    y = sin(a)*R
    return (x,y)

tracer(0,0)
hideturtle()
F = 1
for N in range(4,300):
    clear()
    up()
    goto(R,0)
    seth(90)
    down()
    color('white')
    circle(R)
    up()
    h=0
    for i in range(N):
        h = i/(N*3)
        color(cs.hsv_to_rgb(h,1,1))
        c = getpt(i)
        d = getpt(i*F)
        goto(c)
        down()
        goto(d)
        up()
    update()
    F = F+1/295

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 (...