banc.py

Created by schraf

Created on September 02, 2022

902 Bytes


from kandinsky import get_pixel, set_pixel, fill_rect
from random import random, randint, choice
from math import sin
import turtle

t = turtle
t.hideturtle()

# Le fond marin
fill_rect(0, 0, 320, 222, (0,90,90))

for l in range(130):
  y = 222 - l
  for x in range(320):
    y += 2*random()-1
    c = min(205, get_pixel(x,int(y))[1] + 130 - l)
    set_pixel(x,int(y),(0,c,c))

def poisson(x,y,d):
  # couleur et position
  c = 30 * d
  t.color((c,c//randint(1,3), 0))
  t.penup()
  t.goto(x,y)
  t.pendown()
  t.setheading(randint(-40,40))
  # son corps
  for i in range(d):
    t.pensize(i+1)
    t.fd(1)
  # son oeil
  if d > 4:    
    t.color(choice(((255,255,255),(50,50,50)))) 
    t.pensize(1)
    t.circle(1)     

# qq poissons
for l in range(8):
  x = -160
  while x < 160:
    x += 30 * random()
    if random() < .7:
      poisson(x, -60 + 14*l + 20 * sin(x), randint(2,8))