vacances.py

Created by schraf

Created on July 30, 2021

2.67 KB


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

NB = 10

svg=['M',-5,56,'C',0,55,9,53,15,57,21,61,31,68,37,67,43,65,41,60,47,59,52,58,52,62,57,61,63,61,68,52,77,50,85,49,87,54,93,52,100,50,97,44,103,44,110,43,118,43,128,44,137,44,145,39,150,37,155,35,160,38,165,36,170,35,168,32,172,29,177,26,181,30,192,30,203,30,211,27,220,27,228,27,242,30,252,34,261,38,283,46,289,43,295,41,300,34,304,29,308,25,317,24,323,24,'M',159,95,'C',165,93,177,95,179,98,181,101,179,113,165,115,151,118,148,119,146,112,144,104,152,97,159,95,'Z','M',189,106,'C',190,106,216,111,216,111,'M',185,87,'C',185,87,196,80,196,80,'M',159,81,'C',159,81,156,74,156,74,'M',138,95,'C',138,95,126,85,126,85,'M',176,120,'C',176,120,188,136,188,136,'M',14,187,'C',14,187,27,163,32,162,36,160,37,177,45,188,50,189,67,160,67,160,'M',80,155,'C',77,159,64,180,72,181,87,185,99,166,105,158,'M',94,189,'C',94,189,108,165,111,164,114,164,109,175,113,175,117,175,129,164,133,164,137,165,118,188,115,190,'M',149,160,'C',149,160,138,181,141,183,143,186,151,174,154,173,158,172,153,183,157,184,160,185,180,164,182,161,'M',205,159,'C',210,161,211,171,202,178,194,185,187,189,183,185,179,182,182,172,186,168,190,164,201,157,205,159,'Z','M',206,191,'C',206,191,216,170,221,166,227,162,240,163,242,166,244,169,238,178,232,180,225,181,216,179,216,179,216,179,227,185,227,190,'M',241,188,'C',241,188,261,163,262,161,'M',274,166,'C',274,166,256,172,253,177,250,181,251,183,256,189,'M',306,165,'C',301,165,282,167,282,171,282,175,295,177,295,181,295,185,280,188,275,189,'M',142,120,'C',142,120,131,129,131,129]

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*c*t*t*(1-t)+d*t**3

def bezier(l,d):
  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+d,y)
    t += 1/NB

speed(1)

def dessin(ep,d=0):
    i = 0
    while i<len(svg):
        pensize(randint(ep,2*ep))
        if svg[i] == "M":
            l = [svg[i+1],svg[i+2]]
            penup()
            move(l[0]-randint(0,d), 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,d)
            l = [svg[i+4],svg[i+5]]
            i += 6

def go():
  while True:
    fill_rect(0,0,320,222,(237,219,179))
    color(250,240,250)
    dessin(3)
    speed(0)
    hideturtle()
    sleep(2)
    for y in range(100):
        penup()
        goto(randint(-200,140),110-y)
        pensize(randint(40,80))
        color(55,200,230+randint(-20,20))
        setheading(-35)
        pendown()
        forward(randint(40,90))
    sleep(3) 
   
go()