Go Down

Topic: Emergent pattern A.K.A. how to spy on your neighbor (Read 1 time) previous topic - next topic

SandyMa

Sep 05, 2011, 07:17 pm Last Edit: Sep 05, 2011, 07:21 pm by SandyMa Reason: 1
Hi all!

I've been working on this project for a while now after I read a book called Emergence: The Connected Lives of Ants, Brains, Cities, and Software... Super cool text...
Without going too much in details I want to create a series of identical objects that behave following few simple rules, while interacting with each other...A sort of interconnected frame of objs that observe and react on each other...To make the idea more clear I made a small viz of the logic behind the code...check the png i posted here...
If you look at my coding you'll see that I:
1) created an array of objects called lampList
2) told to two of them to Display(): this means thy will simply see the dist() btw center & mouseX/Y and use that to determine the transparency.
3)assigned the third obj the doOpposite(): it will see what is the condition of the first obj and do the opposite!

The thing I can't seem to do is apply the same three behavior to ALL obj! All object should be able to:
1)read the distance to the mouseX/Y and behave consequently
2)see what is the closest obj doing, and do the opposite

I added some more comment to the coding to explain what I'm doing...

int lastMove;
float stealTransp;
float scaleRange = 255;
float diff;
ArrayList <Lamp> lampList;


void setup() {
 size(800, 600);
 smooth();
 
 //create the arrayList and create 3 Lamp OBJ...
 lampList = new ArrayList();
 lampList.add(new Lamp(200,150));
 lampList.add(new Lamp(500,300));
 lampList.add(new Lamp(300,350));
}

void draw() {
 background(0);
 //apply behaviours to each array obj
 for(int i=0;i<lampList.size();i++) {
   lampList.get(0).display();
   lampList.get(2).display();    
   lampList.get(1).doOpposite();
 }

}


void mouseMoved() {
 lastMove = millis();
}

class Lamp {
 float x;
 float y;
 int ellipseWidth;
 float transp;
 color c;

 Lamp(float tempx, float tempy) {
   x = tempx;
   y = tempy;
   ellipseWidth = 50;
   c = color(random(255),random(255),random(255));
 }

 void display() {
   ellipseMode(CENTER);
   /* here is the trick! calculate the dist between center of the obj
   and mouse X & Y. costrain the values between 0 and 250 and send it to
   the fill()  */
   transp = dist(x, y, mouseX, mouseY);
   transp = constrain(transp,0,255);
   fill (c,transp);
   ellipse(x, y, ellipseWidth, ellipseWidth);
 }
 
  void doOpposite() {
  /* here is the first probem which is that I managed to only follow a specific
     obj, and not the closest...So here I tell the second to check the first */  
  stealTransp = lampList.get(0).transp;
  diff = scaleRange - stealTransp;
  ellipseMode(CENTER);
  fill (c, diff);
  ellipse(x, y, ellipseWidth, ellipseWidth);  
     }

 }  
   

Hopefully if all works, strange cool things should happen...


AWOL

Looking at that "draw" method, I can't help thinking you're posting the wrong forum.

EmilyJane


Looking at that "draw" method, I can't help thinking you're posting the wrong forum.


I can't help but recall the scientist who is developing some mathematical theorem on the chalkboard and in the middle of his proof it says "...and then a miracle happens".

EmilyJane


CrossRoads

Yeah, nice job digging that up!

@SandyMa, you gonna get arduino's in therre somehow? Make them all cognizant of their neighors somehow?
Maybe using beacons & sensors or something?
http://www.dipmicro.com/store/SET-BEACON8.B
Something like this, but with IR LED & sensors?
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

CrossRoads

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

SandyMa


Looking at that "draw" method, I can't help thinking you're posting the wrong forum.


which one should it go to?

AWOL

Quote
which one should it go to?

Well, the code is Processing, so why not a Processing forum?

Go Up