Python fish simulation?

Tim Chase python.list at tim.thechases.com
Mon Nov 10 10:15:02 EST 2008


> Is there any Python-based fish simulation project?  I've tried  
> searching google and pypi, but no luck.  No burning need, just seems  
> like it'd be fun.

Without much detail on what you want to simulate...

class Fish:
   LITTLE, HUGE = range(2)
   def __init__(self, name, size=None):
     self.name = name
     self.size = size
   def swim(self):
     print "blub..."
   def slap(self, who):
     "see here[2]"
     if self.size:
       if self.size == Fish.LITTLE:
         print "slap"
       else:
         print "SLAP"
     else:
       print "Slap"
class Halibut(Fish):
   def license(self, owner):
     "See here[1]"
     raise YoureALoonyException(owner)

john = Person("John")
michael = Person("Michael")
michael.hands.left = Fish(None, size=Fish.LITTLE)
michael.hands.right = Fish(None, size=Fish.LITTLE)
john.fish = Fish(None, size=Fish.HUGE)
michael.hands.left.slap(john)
sleep(1)
michael.hands.right.slap(john)
for _ in range(2):
   sleep(1)
   michael.hands.left.slap(john)
   michael.hands.right.slap(john)
sleep(3)
john.fish.slap(michael)

pet = Halibut("Eric")
pet.license(john)


Hope this fish simulation meets your needs...

-tkc


[1]
http://www.youtube.com/watch?v=pnq96W9jtuw

[2]
http://www.youtube.com/watch?v=i9SSOWORzw4









More information about the Python-list mailing list