# veramolnar.py

Created by schraf

Created on May 08, 2021

1.78 KB

# Utilisation

Lancez le script puis `molnar(1)` pour l’exercice 1, `molnar(2)` pour l’exercice 2 etc.

```from turtle import *
from random import *
from math import sin, cos, pi
from kandinsky import fill_rect

speed(0)
hideturtle()

def melange(v):
return sorted(v, key=lambda _: random())

def forme(n):
trace=[127,25,45,14,346,21,113,38]
pensize(n)
pendown()
for i in range(len(trace)/2):
forward(trace[2*i+1])

def molnar1():
for c in range(15):
l = melange(list(range(3)))
u, v = -140 + 20 * c, -100 + randint(1,48)
for y in range(3):
penup()
goto(u, v + 48 * y)
forme(l[y]+1)

def case(k,n,d):
return [d * (k % n), d * int(k / n)]

def molnar2(N = 8):
x, y = -130,-110
for j in range(N*N):
l = melange(list(range(N*N)))
[x1,y1] = case(j,N,30)
color((randint(0,255),randint(0,255),randint(0,255)))
for i in range(N*N):
[x2,y2] = case(l[i],N,5)
penup() if i == 0 else pendown()
goto(x + x1 + x2, y + y1 + y2)

def molnar3(d = 6):
pensize(2)
for y in range(16):
penup()
goto(-160, -110 + 15 * y)
pendown()
while position()[0] < 160:
if random() < .1:
[x,y] = position()
a = randint(0,90)
co, si = d * cos(pi * a / 180), d * sin(pi * a / 180)
penup()
goto(x, y - si)
pendown()
forward(2 * d)
penup()
goto(min(160,x + 2 * co), y)
pendown()
else:
forward(2 * d)

def molnar4():
pensize(1)
for y in range(20):
penup()
goto(-150, 90 - 10 * y)
pendown()
while position()[0] < 130:
[x,y] = position()
a = randint(10,60)
d = randint(3, 3 + int((x + 150) / 10))