visages.py

Created by schraf

Created on September 22, 2020

2.2 KB


from turtle import *
from kandinsky import fill_rect
from random import random, randint
from time import sleep

NB = 10
svg=['M',-4,62,'C',11,66,70,21,99,68,117,89,104,115,96,118,85,116,77,80,86,61,95,44,113,32,124,33,158,35,145,70,150,83,153,95,159,94,162,99,166,106,168,115,172,114,189,109,182,99,187,92,189,91,191,91,193,93,189,98,184,98,180,95,181,86,188,90,189,85,189,81,184,73,182,68,184,60,186,56,182,51,173,50,166,54,165,59,172,62,171,60,178,60,178,63,176,64,173,65,157,58,167,50,165,44,159,15,169,10,175,7,191,12,192,40,199,50,195,56,189,62,191,64,194,72,201,84,202,89,200,94,190,97,188,101,189,104,191,109,190,111,188,112,185,113,183,115,184,117,186,119,185,122,182,123,178,125,176,127,176,135,174,146,169,145,152,144,153,125,146,115,103,90,138,73,138,73,145,72,110,107,114,131,117,137,118,140,120,145,117,153,112,165,112,168,113,169,116,172,125,170,124,166,124,166,120,167,118,170,121,176,121,181,124,181,127,182,129,184,128,186,127,188,126,191,127,193,130,193,133,195,134,199,129,203,144,206,159,202,181,194,188,174,194,164,183,137,194,128,203,129,208,160,171,161,146,152,146,125,130,127,127,129,123,128,120,133,120,139,129,146,132,147,138,145,137,142,138,140,138,140,126,144,126,144,126,144,122,161,122,161,124,164,128,166,128,170,124,176,103,184,96,164,93,143,107,131,113,115,115,91,117,74,129,66,149,57,160,69,176,70,186,68,195,62,207,65,244,84,242,103,246,114,247,151,220,208,213,206,182,161,235,142,253,151,285,162,301,169,326,167]
hideturtle()

def move(x,y): 
  goto(x-160,110-y)

def coord(a,b,c,d,t):
  return a*(1-t)**3+3*b*t*(1-t)**2+3*t*c*t*(1-t)+d*t**3

def bezier(l):
  pendown()
  t = 0
  for i in range(NB+1):
    x = coord(l[0],l[2],l[4],l[6],t)
    y = coord(l[1],l[3],l[5],l[7],t)
    move(x,y)
    t += 1/NB

def dessin(svg):
  color(3*(randint(0,255),))
  i = 0
  e = 2
  while i<len(svg):
    if random()<.5:
      e = min(3,e+1)
    else:
      e = max(1,e-1)
    pensize(e)
    if svg[i] == "M":
      l = [svg[i+1],svg[i+2]]
      penup()
      move(l[0], l[1])
      i += 3
    elif svg[i] == "Z" or svg[i] == "C": i += 1
    else:  
      for j in range(6): l.append(svg[i+j])
      bezier(l)
      l = [svg[i+4],svg[i+5]]
      i += 6

fill_rect(0,0,320,222,(0,0,0))
for i in range(3):
 dessin(svg)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.