bouquet_colore.py

Created by dgilleitao

Created on June 02, 2024

884 Bytes

Ce script Python a été réalisé dans le cadre du DM 11 de Maths Expertes et représente un feu d’artifice au dessus d’une ville.


from math import *
from kandinsky import *
from random import *

# Background
fill_rect(0,0,320,222,color(0,0,0))

def explosion(a,b,r,e):
  for x in range(320):
    for y in range(222):
      d = (x-a)**2 + (y-b)** 2   
      if d < (r-randint(0,r))** 2:
        set_pixel(x,y,e)

explosion(20,38,48,color(0,0,210))
explosion(95,90,42,color(20,255,210))
explosion(140,30,26,color(0,255,0))
explosion(200,70,42,color(250,0,0))
explosion(280,45,40,color(242,210,207))
explosion(245,130,32,color(255,0,255))

# Stars
for i in range(120):
  set_pixel(randint(0,320),randint(0,222),color(255,255,255))

# City
r = g = b = randint(21,124)
x = y = xl = randint
for _ in range(360):
  fill_rect( x(-10,320), y(140,222), xl(5,10), 62, color(r, g, b))

fill_rect(160,219,3,4,color(255,255,0))

for l in range(142):
  fill_rect(x(-10,320),y(155,222),2,2,color(255,255,0))

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 cookies policy.