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 pmLast 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();
}

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

#1
Sep 05, 2011, 07:23 pm
Looking at that "draw" method, I can't help thinking you're posting the wrong forum.

EmilyJane

#2
Sep 05, 2011, 07:47 pm

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

#3
Sep 05, 2011, 10:14 pm
Yep, that's the one!

#4
Sep 05, 2011, 10:33 pm
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.

#5
Sep 05, 2011, 11:02 pm
Wow, bet all those bowls cost a bunch!
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

#6
Sep 06, 2011, 01:34 pm

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

which one should it go to?

AWOL

#7
Sep 06, 2011, 01:39 pm
Quote
which one should it go to?

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

Go Up