fougere.py

Created by schraf

Created on October 05, 2022

545 Bytes

Fougère de Barnsley

https://en.wikipedia.org/wiki/Barnsley_fern


from random import *
from kandinsky import *

# Lancer par exemple foug(200000)

def foug(n):
  x, y = 0,0
  for _ in range(n):
    r = random()
    if r<0.01:
      nx= 0
      ny = 0.16 * y
    elif r<0.86:
      nx = 0.85 * x + 0.04 * y
      ny = -0.04 * x + 0.85 * y + 1.6
    elif r<0.93:  
      nx = 0.2 * x - 0.26 * y
      ny = 0.23 * x + 0.22 * y + 1.6
    else:
      nx = -0.15 * x + 0.28 * y
      ny = 0.26 * x + 0.24 * y + 0.44
    x = nx
    y = ny
    set_pixel(int(35*x+143),int(-20*y+210),(30,170,50))