Jordan kanter + darien williams

From KokkugiaWiki

Quorum Sensing

Image:450px-Bioluminescence bacteria vibrio bioglyphs.jpg

Image:Bobtail squid.jpg

“Quorum sensing is the process by which many bacteria coordinate their gene expression according to the local density of their population by producing signaling molecules.

The consequence of quorum sensing is the coordination of certain behavior or actions between bacteria, based on the local density of the bacterial population. Quorum sensing can occur within a single bacterial species as well as between diverse species, and can regulate a host of different processes, essentially serving as a simple communication network."

- wikipedia, quorum sensing, 01/29/2008


Vibrio fischeri

“Vibrio fischeri is a rod-shaped bacterium found globally in the marine environments. It has bioluminescent properties, and is found predominantly in symbiosis with various marine animals, such as the bobtail squid. It is heterotrophic and moves by means of flagella. Free living V. fischeri survive on decaying organic matter (see saprotroph). The bacterium is a key research organism for examination of microbial fluorescence, quorum sensing, and bacterial-animal symbiosis.

The bioluminescence of V. fischeri is caused by transcription induced by population-dependent quorum sensing. The luminescence is only seen when population density reaches a certain level. The luminescence appears to follow a circadian rhythm, that is, it is brighter during the nighttime than daytime.

Sepolid squids expel 90% of the symbiotic bacteria in its light organ each morning in process known as “venting”. Venting is hypothesised to provide the free-living inoculum source for newly hatched squids.”

- wikipedia, vibrio fischeri, 01/29/2008


Maya Geometry Test 1 03-25-2008

[[Image:Progress2.jpg]]


Maya Geometry Test 1 03-25-2008


Image:GeometryTest1sml.jpg


Current Python Code 04-08-2008

import maya.cmds as mc import string import math

  1. vector class

class kVec:

   def __init__(self, x, y, z):
       self.x = float(x)
       self.y = float(y)
       self.z = float(z)
   
   # represent as a string
   def __repr__(self):
       return 'kVec(%s, %s, %s)' % (self.x, self.y, self.z)
   
   #####################################################################
   # Constructors!!!
   # There are no constructors in python, therefore we use additional functions
   # Create vector to 0,0,0
   def origin(self):
       self.x = 0.0
       self.y = 0.0
       self.z = 0.0
   # Create clone
   def clone(self):
       return kVec(self.x, self.y, self.z)
   #####################################################################
   # Vector Methods
   def normalize(self):
       norm = float (1.0 / math.sqrt(self.x*self.x + self.y*self.y + self.z*self.z))
       self.x *= norm
       self.y *= norm
       self.z *= norm
       return self
   def invert(self):
       self.x = -self.x
       self.y = -self.y
       self.z = -self.z
   def resize(self, size):
       self.normalize
       self.scale(size)
   
   def minus(self, t):
       self.x -= t.x
       self.y -= t.y
       self.z -= t.z
       return self
   
   def plus(self, t):
       self.x += t.x
       self.y += t.y
       self.z += t.z
       return self
   
   def roundToInt(self):
       self.x = int(x)
       self.y = int(y)
       self.z = int(z)
       return self
   
   #####################################################################
   # Returns the squared length of this vector.
   def lengthSquared(self):
       return (self.x*self.x + self.y*self.y + self.z*self.z)
   
   # Returns the length of this vector.
   def length(self):
       return float(math.sqrt(self.x*self.x + self.y*self.y + self.z*self.z))
   
   # Returns a new vector defined to be the vector cross product of current vector and v2
   def cross(self, v2):
       x = float(self.y * v2.z - self.z * v2.y)
       y = float(v2.x * self.z - v2.z * self.x)
       z = float(self.x * v2.y - self.y * v2.x)
       return kVec(x,y,z)
   # Computes the dot product of this vector and vector v2
   def dot(self, v2):
       return (self.x * v2.x + self.y * v2.y + self.z * v2.z)
   
   # Linearly interpolates between vectors v1 and v2 and returns the result point = (1-alpha)*v1 + alpha*v2.
   def interpolate(self, v2):
       x = float((1 - alpha) * self.x + alpha * v2.x)
       y = float((1 - alpha) * self.y + alpha * v2.y)
       z = float((1 - alpha) * self.z + alpha * v2.z)
       return kVec(x,y,z)
   # Returns the angle in radians between this vector and the vector parameter; 
   # the return value is constrained to the range [0,PI].
   def angle(self, v2):
       vDot = self.dot(v2) / (self.length() * v2.length())
       if vDot < -1.0 : vDot = -1.0
       if vDot > 1.0 : vDot = 1.0
       return float(math.acos(vDot))
   
   # Returns the vector which results from the projection of the source vector onto the destination vector
   def project(self, srcVec, destVec):
       return resize(destVec, projectedLength(srcVec, destVec))
   # Returns the length of the vector which results from the projection of the source vector onto the destination vector
   def projectedLength(self, srcVec, destVec):
       return srcVec.dot(normalize(destVec))
   # Limits this vector to a given size.
   def limit(self, size):
       if (self.length() > size):
           self.normalize()
           self.scale(size)
           
   #####################################################################
   # Point Methods
   
   # Returns the square of the distance between this tuple and tuple t1.
   def distanceSquared(self, t1):
       dx = self.x - t1.x
       dy = self.y - t1.y
       dz = self.z - t1.z
       return (dx * dx + dy * dy + dz * dz)
       
   def scale(self, s):
       self.x *= s
       self.y *= s
       self.z *= s
       return self
   def translate(self, vec):
       self.plus(vec)
       
   def translate(self, vec, dist):
       v = kVec.resize(vec, dist)
       translate(v)
       
   def distance(self, pt):
       dx = self.x - pt.x
       dy = self.y - pt.y
       dz = self.z - pt.z
       return float(math.sqrt(dx * dx + dy * dy + dz * dz))



class kAgentEnv:

   def __init__(self, pos, history):
       self.pos = kVec.clone(pos);
       self.history = int(history);
       self.loc = mc.spaceLocator(p=(pos.x,pos.y,pos.z));

class kAgentFace:

   def __init__(self, pos, ID):
       self.pos = kVec.clone(pos);
       self.ID = ID;
       self.loc = mc.spaceLocator(p=(pos.x,pos.y,pos.z));



env1 = kAgentEnv(kVec(5,10,50),100)

faces = [] env = []


  1. AgentFaces Setup


  1. count faces on polygon

mc.select('pPlane1') faceCount=mc.polyEvaluate(f=True) faceCount = faceCount


  1. loop through each face and assign an AgentFace

for i in range(0,faceCount,1): mc.select('pPlane1') mc.select('.f[%d]' %i) VertexList=mc.polyInfo(fv = True) Agents=string.split(VertexList[0])

SumList = [0,0,0,0]

# loop through vertexes, average their position for j in range(3,(len(Agents)+1),1): SumList[3]=SumList[3]+1 IDnum = int(Agents[j-1]) mc.select('pPlane1')

mc.select('.vtx[%d]' %IDnum) Location=mc.pointPosition()

Xpos = Location[0] SumList[0]=(Xpos + SumList[0])

Ypos = Location[1] SumList[1]=(Ypos + SumList[1])

Zpos = Location[2] SumList[2]=(Zpos + SumList[2])


SumList[0]=(SumList[0]/SumList[3]) SumList[1]=(SumList[1]/SumList[3]) SumList[2]=(SumList[2]/SumList[3]) print SumList

# append new AgentFace to faces List faces.append(kAgentFace(kVec(SumList[0], SumList[1], SumList[2]), Agents[1]))



  1. identify and manipulate closest face
  1. find closest face

closestDist = 1000000000000.0 faceLoc = 5

for i in range (0,len(faces),1):

distFLT = 0 dist = kVec.clone(env1.pos) dist = dist.minus(faces[i].pos) distFLT=float(dist.length()) #print distFLT

if (distFLT < closestDist): closestDist = distFLT print closestDist faceLoc = i print faceLoc

  1. identify closest face

faceID = faces[faceLoc] mc.select('pPlane1') print faceID.ID

  1. strip faceID.ID of ':' character, make int

faceIDstrip=int(faceID.ID[:-1])

  1. select closest face

mc.select('.f[%d]' %faceIDstrip)


  1. perform geometric manipulation on closest face
  1. calculate face extrude scale value from env.history

chg = float(env1.history) chg = chg/4000 chg = pow(chg,.2) scl = (chg) print scl

  1. extrude face, scale down, delete middle faces to create appature

mc.polyExtrudeFacet(kft=False, ls=(scl,scl,scl)) vtxIDmove=mc.polyInfo(fv = True) mc.delete()

vtxSplit = string.split(vtxIDmove[0]) vtxA = int(vtxSplit[2]) vtxB = int(vtxSplit[3]) vtxC = int(vtxSplit[4]) vtxD = int(vtxSplit[5])

mc.select('pPlane1.vtx[%d]' %vtxA) mc.select('pPlane1.vtx[%d]' %vtxB, tgl=True) mc.select('pPlane1.vtx[%d]' %vtxC, tgl=True) mc.select('pPlane1.vtx[%d]' %vtxD, tgl=True)

moveDist = closestDist/5 mc.move(0,0,moveDist, r=True)


  1. delete locators to prep for next iteration






Current Processing Code 03-25-2008

import kGeom.*; import kRender.*;

kWorld world1; int mouseToggle; int maxlifeCount = 2500; int pauseToggle; PrintWriter output;

void setup(){

 mouseToggle = 0;
 pauseToggle = 0;
 size(500,500);
 frameRate(30);
 smooth();
 world1 = new kWorld();
 for (int i = 0; i < 20; i++) {
   world1.addBac(new kAgent_bac(new kVec(random(width), random(height)),new kVec (random(500),random(500)), new kVec(random(500),random(500)),10));
 } //add a new agent with values relative to its cloning parent
 for(int j=10; j<width; j+=20){
   for(int k = 10; k < height; k += 20){
     world1.addEnv(new kAgent_env(new kVec(j,k), new kVec(random(-3,3),random(-3,3)), 1, 600, 0)); 
   }
 }



}



void draw () {

 background (5);
 world1.runEnv();
 world1.runBac();


}


void mousePressed(){

 if (mouseToggle == 0){
   mouseToggle = 1;
 } 
 else if (mouseToggle == 1){
   mouseToggle = 2;
 }
 else {
   mouseToggle = 0;
 }

}

void keyPressed() {

 // save env position/attribute information to a text file
 world1.extractEnv();



}

class kAgent_bac{

 //variables
 //position
 kVec         pos;
 kVec         acc;
 kVec         vel;
 float        maxVel;
 float        rad = 5;
 int          aggCount = 0;
 float        proxRange = 80;
 int          killTest;
 int          swarmThresh = 5;
 //constructor
 kAgent_bac (kVec _pos, kVec _acc, kVec _vel, float _maxVel) {
   pos = kVec.clone(_pos);
   acc = new kVec(0,0);
   vel = new kVec(0,0); 
   maxVel = _maxVel;
 }


 //functions
 void modeChange(ArrayList pop, ArrayList env, int id){
   killTest = 0;
   aggCount(pop);
   if (mouseToggle == 0){
     render();
   }
   borders();
   killBac();
   // Death function - runs as part of update
   if(killTest == 1){
     world1.removeBac(id);
   }


   // Routing Switch
   if(aggCount < swarmThresh){
     update_N(pop, env, id); 
   }
   /*if (aggCount > 15) {
    update_T(pop, env, id); 
    }*/
   if ((aggCount == swarmThresh)||(aggCount > swarmThresh)){
     update_S(pop, env, id);
   }


 }


 void update_N (ArrayList pop, ArrayList env, int id){


   cloneBacN(pop);
   //steer
   kVec seek = steer(env);
   seek.scale(.01);
   acc.plus(seek);
   vel.plus(acc);
   vel.limit(5);
   pos.plus(vel);
   acc = new kVec(0,0);


   //separate
   kVec sep = separate(pop);   // Separation
   sep.scale(1);
   acc.plus(sep);
   vel.plus(acc);
   pos.plus(vel);
   acc = new kVec(0,0);


 }




 void update_S(ArrayList pop, ArrayList env, int id){
   cloneBacS(pop);


   //steer
   kVec seek = steer(env);
   //seek.scale(.01);
   acc.plus(seek);
   vel.plus(acc);
   vel.limit(5);
   pos.plus(vel);
   acc = new kVec(0,0);


   //separate
   kVec sep = separate(pop);   // Separation
   sep.scale(.001);
   acc.plus(sep);
   vel.plus(acc);
   pos.plus(vel);
   acc = new kVec(0,0);
   //cohesion
   kVec coh = cohesion(pop);
   coh.scale(5);
   acc.plus(coh);
   vel.plus(acc);
   pos.plus(vel);
   acc = new kVec(0,0);



 }




 // General Functions
 void render (){
   // draw agent nodes
   fill (200, 50);
   stroke (255);
   ellipse (pos.x, pos.y, rad, rad);


   // draw proxRange boundary, "luminesce" in response to proximity
   noFill();
   /*float lum = (aggCount * aggCount * sqrt(aggCount))+15;
    if (lum>255){
    lum = 255;
    }*/
   float lum;
   if (aggCount < swarmThresh){
     lum = 0;
   }
   else{
     lum = 150;
   } 
   stroke (255,0,0,lum);


   //ellipse (pos.x, pos.y, proxRange, proxRange);


 }
 int aggCount (ArrayList pop) {
   aggCount = 0;
   for (int i = 0 ; i < pop.size(); i++) {
     kAgent_bac other = (kAgent_bac) pop.get(i);
     float dist = pos.distance(other.pos); //what is distance between current agent and the agent its checking against
     // if dist is less than proximity range, add to aggCount
     if (dist < proxRange) {
       aggCount++;                  // keep track of how many
     }
   }
   return aggCount;
 }


 // Life related Functions
 void cloneBacN(ArrayList pop) {
   float cloneTest = random(100);
   float cloneRate = ((1/aggCount)*(1/aggCount))*90;
   if (pop.size() < 300){
     if (cloneTest < cloneRate){
       //call on the world to make a new agent with new position at diameter distance away cloning agent
       kVec child_pos = kVec.clone(pos);
       kVec child_acc = kVec.clone(acc);
       kVec child_vel = kVec.clone(vel);
       float child_maxVel = maxVel;
       float ranNum = random(10);
       if (ranNum > 5){
         child_pos.plus(new kVec(rad, 0));
       }
       else{
         child_pos.plus(new kVec(0, rad));
       } 
       world1.addBac(new kAgent_bac(child_pos, child_acc, child_vel, child_maxVel));
     }
   }
 }
 void cloneBacS(ArrayList pop) {
   float cloneTest = random(100);
   float cloneRate = (1/(sqrt(aggCount)))*90;
   if (pop.size() < 300){
     if (cloneTest < cloneRate){
       //call on the world to make a new agent with new position at diameter distance away cloning agent
       kVec child_pos = kVec.clone(pos);
       kVec child_acc = kVec.clone(acc);
       kVec child_vel = kVec.clone(vel);
       float child_maxVel = maxVel;
       float ranNum = random(10);
       if (ranNum > 5){
         child_pos.plus(new kVec(rad, 0));
       }
       else{
         child_pos.plus(new kVec(0, rad));
       } 
       world1.addBac(new kAgent_bac(child_pos, child_acc, child_vel, child_maxVel));
     }
   }
 }



 void killBac (){
   float vel_length = vel.length();
   if (vel_length > 6){
     killTest = 1;


   }
 }


 // Movement Functions
 kVec separate (ArrayList pop) {
   float desiredseparation = 150.0;
   kVec sum = new kVec(0,0);
   int count = 0;
   for (int i = 0 ; i < pop.size(); i++) {
     kAgent_bac other = (kAgent_bac) pop.get(i);
     float dist = pos.distance(other.pos);
     // if the distance is greater than 0 and less than an arbitrary amount (0 when you are yourself)
     if ((dist > 0) && (dist < desiredseparation)) {
       // calculate vector pointing away from neighbor
       kVec diff = kVec.clone(pos); 
       diff.minus(other.pos);
       diff.normalize();
       diff.scale(1/dist);          // weight by distance
       sum.plus(diff);
       count++;                     // keep track of how many
     }
   }
   // average -- divide by how many
   if (count > 0) {
     sum.scale(1/(float)count);
   }
   return sum;
 }



 // steer function
 kVec steer (ArrayList env){
   float closestdist = 1000;
   // int vecID = 1;
   //float inv_dist = 1;
   //kVec target = new kVec (0,0);
   kVec sum = new kVec(0,0);
   int count = 0;
   int[] address = {
     0,0,0,0,0,0,0,0,0                };



   for (int i = 0 ; i < env.size(); i++) {
     kAgent_env other = (kAgent_env) env.get(i);
     float dist = pos.distance(other.pos); //what is distance between current agent and the agent its checking against
     // if dist is less than proximity range, add to aggCount
     if (dist < 20) {
       sum.plus(other.force);
       count++;
       address[count] = i;
     }                
   }
   /*if (count>0){
    float ave = 1/count;
    sum.scale(ave);
    }*/
   kVec target = kVec.clone(sum);
   //scale steer by velocity
   float velmag = vel.length();
   if (velmag != 0){
     velmag = sqrt(velmag);
     target.scale(velmag);
   }
   //target.scale(.01);
   kVec env_steer = kVec.clone(target);
   //env_steer.scale(.01);


   //scale steer and env_steer according to neutral/swarm mode
   if(aggCount < swarmThresh){
     target.scale(6);
     env_steer.scale(.01);
   }
   if((aggCount == swarmThresh)||(aggCount > swarmThresh)){
     target.scale (.1);
     env_steer.scale (.5);
   }
   kVec vel2 = kVec.clone(vel);
   vel2.scale(.5);
   env_steer.plus(vel2);


   for(int j=0 ; j<address.length; j++){
     if(address[j]>0){
       kAgent_env other2 = (kAgent_env) env.get(address[j]);
       kVec input1 = kVec.clone(other2.force);
       input1.minus(env_steer);
       input1.limit(15);
       kVec pos_input = kVec.clone(other2.pos); // get env pos vector
       int age = other2.lifeCount;
       age = age-5;
       println(age);
       


       // grow history circle
       int history_other = other2.history;
       history_other++;  


       // pivot env vector in response to agent effect
       if (other2.lockForce == 0){ 
         env.set(address[j], new kAgent_env(pos_input, input1, history_other, age, 0));  //loads new force vector to kAgent_env
       }  
     }
   }



   return target;
 }
 //borders
 void borders(){
   if (pos.x<0) {
     killTest = 1;
   }
   if (pos.y<0){
     killTest = 1;
   }
   if (pos.x>width){
     killTest = 1;
   }
   if (pos.y>height){
     killTest = 1;
   } 


   /*if (pos.x<0) pos.x = width;
    if (pos.y<0) pos.y = height;
    if (pos.x>width) pos.x = 0;
    if (pos.y>height) pos.y = 0;*/
 }
 //cohesion
 kVec cohesion (ArrayList pop){
   float neighbordist = 50;
   kVec sum = new kVec(0,0);
   int count = 0;
   for (int i = 0 ; i < pop.size(); i++) {
     kAgent_bac other = (kAgent_bac) pop.get(i);
     float dist = pos.distance(other.pos);
     if ((dist > 0) && (dist < neighbordist)) {
       sum.plus(other.pos); 
       count++;
     }
   }
   if (count > 0) {
     sum.scale(1/(float)count);


   }
   return sum;
 }


}

class kAgent_env{

 // variables
 kVec      pos;
 kVec      force;
 int       history;
 int       lifeCount;
 int       lockForce;


 // constructor
 kAgent_env(kVec _pos, kVec _force, int _history, int _lifeCount, int _lockForce){
   pos = kVec.clone(_pos);
   force = kVec.clone(_force);
   history = _history;
   lifeCount = _lifeCount;
   lockForce = _lockForce;
 }
 // fuctions
 void update(ArrayList env, int N){
   age (N);
 }
 void age (int id1){
   lifeCount = lifeCount+1; 
   if (lifeCount < 0){
     world1.removeEnv(id1);
   }
   if(lifeCount > maxlifeCount){
     lockForce = 1;
   } 
 }


 void render(){
   
   kVec end = kVec.clone(force);
   end.plus(pos);
   if (lockForce == 1){
     stroke(255, 0, 255);
   }
   else if ((lifeCount/2) > 255){
     stroke(255,255,255);
   }
   else {
     stroke(255, lifeCount/2, lifeCount/2);
   }
   ellipse(pos.x, pos.y, 2, 2);


   if ((mouseToggle == 0) || (mouseToggle == 1)){
     line(pos.x, pos.y, end.x, end.y);
   }
   noFill();
   if ((lifeCount*2) > 255){
     stroke(255,255,255);
   }
   else {
     stroke(255, (lifeCount/2), (lifeCount/2));
   }



   //history circle
   stroke(150, 150);
   fill(150, 40);
   float rad = float(history);
   rad = rad/10;
   ellipse(pos.x, pos.y, rad, rad);
   //lock circle
   /*if (lockForce == 1){
    stroke(255, 0, 255);
    fill(150, 40);
    //rad = rad/10;
    ellipse(pos.x, pos.y, 2, 2);
    }*/
 }

}


class kWorld {

 ArrayList population_bac;
 ArrayList population_env;
 kWorld() {
   population_bac = new ArrayList(); // initialize the arraylist
   population_env = new ArrayList();
 }
 // bac functions
 // cycles through each agent passing the population to it
 void runBac(){
   for (int i = 0; i < population_bac.size(); i++) {
     kAgent_bac a = (kAgent_bac) population_bac.get(i);  
     a.modeChange(population_bac, population_env, i); 
   }
 }
 // add agent
 void addBac(kAgent_bac a) {
   population_bac.add(a);
 }
 // remove agent
 void removeBac(int id){
   population_bac.remove(id);
 }


 // env functions
 void runEnv(){
   int lockCount = 0;
   for (int i = 0; i < population_env.size(); i++) {
     kAgent_env b = (kAgent_env) population_env.get(i);  
     b.update(population_env, i);
     b.render(); 
     if(b.lockForce == 1){
       lockCount++;
     }
   }
   if (lockCount == population_env.size()){
     fill(255,0,0,50);
     noStroke();
     rect(25,25,50,25); 
   }
 }
 void addEnv(kAgent_env b){
   population_env.add(b);
 }
 // remove env
 void removeEnv(int id1){
   population_env.remove(id1);
 }
 // save env position/attribute information to a text file
 void extractEnv(){
   output = createWriter("EnvExport.txt");
   for (int i = 0; i < population_env.size(); i++) {
     kAgent_env c = (kAgent_env) population_env.get(i);
     output.println(c.pos.x + "/t" + c.pos.y + "/t" + 0 + "/t" + c.history);
   }
   output.flush();
   output.close();
 }


}

Views