Фонтан

Фонтан
from random import randrange as rnd
from tkinter import *
import time

root= Tk()
canv = Canvas(root,width = 800,height = 600, bg = 'white')
canv.pack()

class ball():
    def __init__(self):
        self.x = 400
        self.y = 450
        self.r = 2.4
        self.vx = 6
        self.vy = -6
        self.color = 'orange'
        self.live = 50
        self.id = canv.create_oval(self.x-self.r,self.y-self.r,self.x+self.r,self.y+self.r, fill = self.color, width = 0)
        
    def set_coords(self):
        canv.coords(self.id, self.x-self.r,self.y-self.r,self.x+self.r,self.y+self.r)

    def set_minus_r(self):
        self.r -= 0.04
        if self.r <= 0.1:
            self.kill()
        canv.coords(self.id, self.x-self.r,self.y-self.r,self.x+self.r,self.y+self.r)
        
    def kill(self):
        global balls
        balls.pop(balls.index(self))
        canv.delete(self.id)        
        
    def move(self):
        if self.vy > 0 and self.y > rnd(300,500):
            self.kill()
        else:
            if self.vy > 0:
                self.set_minus_r()
                
            self.y += self.vy
            self.vy += 0.25
            self.x += self.vx
            if self.x > (800-self.r):
                self.vx = -self.vx//2
                self.x = 800-self.r-1
            self.set_coords()
        

balls = []

k1 = k2 = k = 0 
vy = 0
vx = 0
d = 30
dd = 30
ddd = 2
while 1:
    if k > d:
        vy = rnd(3)
        d = rnd(40,50)
        k = 0
    k += 1
    
    if k1 > dd:
        vx = rnd(-5,5)
        dd = rnd(30,60)
        k1 = 0
    k1 += 1

    if k2 > ddd:
        for zz in range(rnd(-10,0),rnd(11),2):
            balls += [ball()]
            balls[-1].vx = (zz+vx)/8
            balls[-1].vy = -12+vy+rnd(20)/12
        k2 = 0
    k2 += 1
        
    
    

    for b in balls:
        b.move()
        
    #time.sleep(0.00)
    canv.update()   


root.mainloop()


Добавить комментарий

Ваш e-mail не будет опубликован. Обязательные поля помечены *