from turtle import * from random import * from math import sin, cos, pi, sqrt D = -108 speed(0) def melange(n): return sorted(list(range(n)), key=lambda _: random()) def dispo(x,y,r,k,n): #return [x + r * cos(2*k*pi/n), y + r * sin(2*k*pi/n)] return [x + r * (k % n), y + r * int(k / n)] def molnar1(N): for j in range(N*N): color(randint(0,255), randint(0,255),randint(0,255)) l = melange(N*N) [x,y] = dispo(-247,-240,50,j,N) for i in range(N): [x2,y2] = dispo(x,y,12,l[i],N) penup() if i == 0 else pendown() goto(x2, y2) def molnar2(): pensize(3) d = 6 for y in range(30): penup() goto(-160, -200 + 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) setheading(a) pendown() forward(2 * d) penup() goto(x + 2 * co, y) pendown() else: setheading(0) forward(2 * d) def sss(n): #trace =[-90,32,0,4,90,16,0,4,-90,32] trace =[-45,32,-135,20,0,16,-90,4,-135,32] pendown() pensize(n) for i in range(5): setheading(trace[2 * i]) forward(trace[2 * i + 1]) def molnar3(): for x in range(15): l = melange(3) u, v = -150 + 20 * x, -40 + randint(1,48) for y in range(3): penup() goto(u, v + 48 * y) sss(l[y] + 1) def molnar4(): pensize(1) for y in range(15): #15 penup() goto(-200, 95 - 14 * y) pendown() while position()[0] < 200: [x,y] = position() setheading(randint(10,60)) forward(3 + randint(0,int((x + 200) // 10))) goto(x + randint(3,7), y) def molnar5(): v = 3 for y in range(60): penup() goto(-160, -260 + 8 * y) pendown() while position()[0] < 160: if random() < .01: v += 0.1 pensize(v) forward(6) def carre(d, c): pendown() a = random()<c if a: [x,y] = position() penup() setheading(randint(0,10)) forward(randint(1,10)) pendown() for i in range(4): forward(d) right(90) if a: penup() goto(x,y) setheading(0) def molnar6(): d = 6 for k in range(40): penup() goto(-200 + 5 * k, 200 - 5 * k) pensize(2) carre(400 - 10 * k, .01) hideturtle()