Пример #1
0
class Repeller:
    def __init__(self,x=400,y=400):
        self.loc=Pvector(x,y)
        self.dir=None
    def calculateForce(self,location):
        self.dir=Pvector(location.x,location.y)
        self.dir.sub(self.loc)
        self.dir.mult(150/(self.dir.magnitude()**3))
    def display(self):
        no_stroke()
        fill(0)
        ellipse(self.loc.x,self.loc.y,70,70)
 def seek(self,target):
     desired=Pvector(target.x,target.y)
     desired.sub(self.location)        
     mag=desired.magnitude()
     if mag<100:
         setmag=mag*self.maxspeed/100
         desired.setMag(setmag)
     else:
         desired.setMag(self.maxspeed)
     desired.sub(self.velocity)
     desired.limit(self.maxforce)
     return desired
 def seek_flow(self):
     if self.location.x<0:
         self.location.x=799
     if self.location.x>799:
         self.location.x=0
     if self.location.y<0:
         self.location.y=799
     if self.location.y>799:
         self.location.y=0
     desired=Pvector(self.lookup(self.location).x,self.lookup(self.location).y)
     desired.setMag(self.maxspeed)
     desired.sub(self.velocity)
     desired.limit(self.maxforce)
     self.applyForce(desired)
 def seperate(self,others):
     sum=Pvector(0,0)
     count=0
     for v in others:
         loc=self.location.get()
         loc.sub(v.location)
         d=loc.magnitude()
         if d>0 and d<50:
             loc.mult(1/d)
             sum.add(loc)
             count=count+1
     if count!=0:    
         sum.mult(1/count)
         sum.norm()
         sum.mult(self.maxspeed)
         sum.sub(self.velocity)
         sum.limit(self.maxforce)
     return sum