view tk1.py @ 2:02609649d88b
Bacteria.py module 0.1
author |
Smirnova Victoria |
date |
Tue, 07 Dec 2010 21:26:34 +0300 |
parents |
|
children |
|
line source
7 def __init__(self,x,y):
11 return sqrt(self.x**2+self.y**2)
12 def __add__(self,other):
13 return Vector(self.x+other.x,self.y+other.y)
14 def __mul__(self,digit):
15 return Vector(digit*self.x,digit*self.y)
28 if acos(self.x/m)>pi/2 or (acos(self.x/m)>pi/2 and asin(self.y/m)<0):
29 return atan(self.y/self.x)-pi
31 return atan(self.y/self.x)
32 def angleToCoord(self,angle):
34 self.x=magn*cos(angle)
35 self.y=magn*sin(angle)
37 def magnitToCoord(self,m):
44 def __init__(self,position,velocity):
45 self.position=position
46 self.velocity=velocity
48 if self.position.x>=595:
50 self.velocity=self.velocity.angleToCoord(pi-self.velocity.angle())
51 elif self.position.x<=2:
53 self.velocity=self.velocity.angleToCoord(pi-self.velocity.angle())
54 if self.position.y>=595:
56 self.velocity=self.velocity.angleToCoord(-self.velocity.angle())
57 elif self.position.y<=2:
59 self.velocity=self.velocity.angleToCoord(-self.velocity.angle())
60 def collision(self,other):
61 if abs(self.position.y-other.position.y)<70 and abs(self.position.x-other.position.x)<70:
62 self.velocity.angleToCoord(2*pi*random.random())
63 other.velocity.angleToCoord(2*pi*random.random())
65 c = Tkinter.Canvas( root, width = 670, height = 670 )
68 b1=Ball(Vector(440,100),Vector(5,7))
69 b2=Ball(Vector(40,90),Vector(-3,-1))
70 b3=Ball(Vector(100,250),Vector(0,5))
71 b4=Ball(Vector(150,250),Vector(-1,2))
72 ball1 = c.create_oval(0,0,0,0)
73 ball2 = c.create_oval(0,0,0,0)
74 ball3 = c.create_oval(0,0,0,0)
75 ball4 = c.create_oval(0,0,0,0)
82 ball1=c.create_oval(b1.position.x, b1.position.y, b1.position.x+75, b1.position.y+75,fill="blue" )
83 ball2=c.create_oval(b2.position.x, b2.position.y, b2.position.x+75, b2.position.y+75,fill="red")
84 ball3=c.create_oval(b3.position.x, b3.position.y, b3.position.x+75, b3.position.y+75,fill="yellow")
85 ball4=c.create_oval(b4.position.x, b4.position.y, b4.position.x+75