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))

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.