figure.py

Created by airopi

Created on March 22, 2022

624 Bytes


import turtle as t
import random as r
import time as ti

SPEED=10
MAX_PEN_SIZE=3
MAX_DRAW_TIME=17
INFINITE_DELAY=3


t.speed(SPEED)

def figure():
  start=ti.monotonic()
  while 1:
    _r=r.randint(0,255)
    g=r.randint(0,255)
    b=r.randint(0,255)
    if _r+g+b<500:
      break

  t.color(_r,g,b)
  t.pensize(r.randint(1,MAX_PEN_SIZE))

  avance=0
  rotation=r.randint(0,180)

  x,y=0,0
  while -111<y<111 and ti.monotonic()-start<MAX_DRAW_TIME:
    t.left(rotation)
    t.forward(avance)
    avance+=1

    x,y=t.position()

def infini():
  while 1:
    figure()
    ti.sleep(INFINITE_DELAY)
    t.reset()