Posted on March 22nd, 2007 by Ryan Varga.
Categories: Interconnected.
We covered some major ground today. We have merged JMyron blobDetection with our code, and have a functioning emergent system influenced by network data and controlled via FTIR interface.
see comment for code
Comment on March 22nd, 2007.
//MindeHIVE 1.0 by MindHaus: Andre, Ryan, Peter, Tobin
//An interactive, interconnected emergent experience
import processing.net.*;
import JMyron.*;
// blobCenters
int[][] c;
float nosePosX, nosePosY;
// server variables
int holdtext;
int port = 31337;
boolean myServerRunning = true;
Server myServer;
JMyron m;
// life variables
bug[] b;
food[] f;
int num_bugs=5000;
int num_food=0;
void setup(){
size(600,600,P3D);
background(0);
//setup JMyron
m = new JMyron();//make a new instance of the object
m.start(width,height);//start a capture
m.trackNotColor(0,0,0,200);//R, G, B, and range of similarity
m.minDensity(10); //minimum pixels in the glob required to result in a box
noFill();
// starts a server on port 31337
myServer = new Server(this, port);
// setup bugs
f=new food[5000];
b=new bug[50000];
for(int i=0;i
}
}
void keyPressed(){
if(keyCode==ENTER){
saveFrame();
}
}
void draw(){
camJM();
// server
if (myServerRunning == true) {
Client thisClient = myServer.available();
if (thisClient != null) {
if (thisClient.available() > 0) {
// var from client
holdtext = thisClient.read();
// create effect of bug with fading tail
noStroke();
fill(0,1);
rect(0,0,width,height);
println(thisClient.ip() + “: ” + holdtext);
}
}
// food
for(int i=0;i
}
// bugs
for(int i=0;i
}
}
}
//setup blob detection
void camJM() {
m.update();//update the camera view
drawCamera();//draw the camera to the screen
}
//globs
void drawCamera(){
c = m.globCenters();//get the center points
for(int i=0;i
nosePosX = c[0][0];
nosePosY = c[0][1];
println("X :" + nosePosX + " Y: " + nosePosY);
}
//set globCenters to food
f[num_food]=new food(nosePosX,nosePosY);
num_food++;
}
}
// the bugs
class bug{
float x,y,vx,vy,energy,rr,gg,bb;
int target;
float de=.00000000000000015;
float foodEnergy=.001;
float maxEnergy=.75;
float hungryState=6.5;
boolean hungry;
boolean die=false;
boolean eating=false;
boolean hasTarget=false;
public bug(){
x=random(width);
y=random(height);
vx=0;
vy=0;
rr=0;
gg=255;
bb=255;
energy=random(.2,maxEnergy);
hungry=(energy<=hungryState)?true:false;
}
void lookForFood(){
float tdist=9999999;
float d;
// look for the closest food
for(int i=0;i
d=dist(f[i].x,f[i].y,x,y);
if(d
tdist=d;
hasTarget=true;
}
}
}
}
void move(){
float tx,ty,dx,dy,a;
float k=.06;
// move to food
if(hasTarget){
a=atan2(y-f[target].y,x-f[target].x);
tx=f[target].x+f[target].r*cos(a);
ty=f[target].y+f[target].r*sin(a);
vx+=(tx-x)*k;
vy+=(ty-y)*k;
}
vx+=random(-1.6,1.6);
vy+=random(-1.6,1.6);
vx*=energy;
vy*=energy;
x+=vx;
y+=vy;
if(x<0){
x=0;
}
else if(x>width){
x=width;
}
if(y<0){
y=0;
}
else if(y>height){
y=height;
}
if(energy<=0){
die=true;
}
else{
energy-=de;
}
}
void checkEatingStatus(){
// when bug is eating, eat till it is full of energy
if(hasTarget){
if (energy
}
else if(energy>=maxEnergy){
hungry=false;
eating=false;
hasTarget=false;
}
}
// after bug gains full energy, it will eat again when energy decrease below ‘hungryState’
if(!hasTarget && energy<=hungryState){
hungry=true;
}
// it eats if it is near enough to the food
if(hasTarget){
if (dist(f[target].x,f[target].y,x,y)
energy+=foodEnergy;
f[target].remain-=foodEnergy;
}
else{
eating=false;
}
}
// leave the food if it is finished
if(hasTarget && f[target].remain<0){
hasTarget=false;
eating=false;
}
// reproduce if not yet hungry
if(!hasTarget && !hungry && !eating){
if(random(1)>.99995){
b[holdtext]=new bug();
energy=energy/2;
b[holdtext].energy=energy;
b[holdtext].x=x;
b[holdtext].y=y;
b[holdtext].bb=0;
holdtext++;
}
}
}
void render(){
// turns more red if hungry
if(energy
}
else{
rr=0;
}
stroke(rr,gg*energy,bb*energy);
point(x,y);
}
void run(){
if(!die){
checkEatingStatus();
if(!eating && hungry){
lookForFood();
}
move();
render();
}
}
}
// appearance and characteristics of food
class food{
float x,y,r,remain;
public food(float xx, float yy){
x=xx;
y=yy;
r=10;
remain=2;
}
void render(){
stroke(30*remain,30*remain,0);
ellipse(x,y,r*1,r*1);
}
void run(){
if(remain>0){
render();
}
}
}
Comment on March 22nd, 2007.
you guys never cese to amaze me. i can’t wait to see it all rocking out. Tobin and i got video talking to ableton, in addition to adding 2 more sound elements. things are coming together.
Comments can contain some xhtml. Names and emails are required (emails aren't displayed), url's are optional.