Cells for Matthew

I have been asked repeatedly.
Hounded really. ;) To write the outline for a
python program that splits cells or any
other entity for that matter.
The fellow was rather persistant. So something
finally had to be done. And very early in the morning
I wrote the rough draft for this....
""" Cells for Matthew My gosh, I suppose if you hound me enough I'll do anything. But then that teaches the wrong thing to people. Because pretty soon... everyone will ask me for things... And that's when I'll start charging! ;) My Example would use Meta spheres because they interact nicely without any special effort. A collection of objects in the scene Cells = [] Each cell can split Will do so after a set time interval. And construct a new cell to add to the Cells list This way cells will multiple in step. Any more complex interaction can be programed into the move method and more complixed spliting can be written and flagged in split. But this is the basic framework that gets cell objects multiplying and moving about. Log May 31, 2008 8:04 AM 1 hour for basic working theory May 31, 2008 10:56 PM .5 hours clean up and fixing errors Total Time Thus Far: 1.5 hours """ class Cell(): """ Generic Cell class Version 0.1 Alpha to demonstrate cell spliting behavior Direction should be an arbitary vector so cells can move opposite to any way they were pointing. This example only uses the X dimension for simplicity. """ cell_count = 0 def __init__(self,name,loc,direction,cell_number): Cell.cell_count += 1 self.loc = loc self.name = name self.direction = direction # Must move in the direction # Direction is a velocity self.delta = 0.1*self.direction self.id = cell_number def split(self): # Note the Direction Reverse (in one dimension it's just a -direction) return Cell(self.name+'X',self.loc,-self.direction,self.id+1) def draw(self): # should have a way to draw in simple view # And swap complex figures in it's place # with interaction # if text_mode: print "%3d: name:%-10s loc:%-10f dir:%-10f" % (self.id,self.name,self.loc,self.direction) def move(self): # we need to move away from our original init location # that locationis prob right on top of the previous cell # So we move until the next split is called # This is where all the interaction is. # direction cells shoud init with direction self.loc += self.delta # Since each cell is in step we can split on the same time interval # Marching in step #later staggered split times might yield narly results. ### # Main Program ### cells = [] # Every great journey begins with a single cell cells.append(Cell("cell_",0.0,1.0,1)) SPLIT_INTERVAL = 5 # every x frames print "Cell Simulation Begins" for time in range(15): # Time Line Range #print "time:",time for cell in cells: #cell.draw() cell.move() if time%SPLIT_INTERVAL == 0: new_cells = [cell.split() for cell in cells] cells += new_cells #print print "Cell Chart" for cell in cells: cell.draw() print "Total Cells",Cell.cell_count print "End of Cell Simulation" print "I bet all simulation programs start as print statements ;)" exit # exit before my notes print """ NOTES I had a bug with an infintie loop because I keep wanting to add a cell to the list on split but I still walk through that list so split keeps getting called on more and more cells in the list"""
Outputs...
snail$ python cells.py Cell Simulation Begins Cell Chart 1: name:cell_ loc:1.500000 dir:1.000000 2: name:cell_X loc:-1.300000 dir:-1.000000 2: name:cell_X loc:-0.300000 dir:-1.000000 3: name:cell_XX loc:0.500000 dir:1.000000 2: name:cell_X loc:0.700000 dir:-1.000000 3: name:cell_XX loc:-0.500000 dir:1.000000 3: name:cell_XX loc:0.500000 dir:1.000000 4: name:cell_XXX loc:-0.300000 dir:-1.000000 Total Cells 8 End of Cell Simulation I bet all simulation programs start as print statements ;) snail$
Notes
I hate the way people only see sides, but not the truth.
I hate certain things about the social world so much.
I hate the way people watch the world through their own colored glasses.
And I hate the fact I can't get away from it.
SIRC Guide
I’m so glad you did this! Well, actually, I feel a little confused because at the end I was going to do it myself and just wanted some confirmation if what I’m thinking is right. Still, my thoughts confirmed. So I’m glad. :)
By the way, don’t know what you mean by “never got a response” - I did respond 20080531 0603am GMT with a description of a class very similar to the one you’ve used and after that I didn’t get any further message from you until now.