Network Code
Project: Emergence and Navigating Space
Project: Emergence and Navigating Space
// This is general, simple code for each element to be "aware"
// of every other element. Specifically, it draws a line from each
// node to every other node.
Node[] nodes;
void setup() {
size(600, 600);
nodes = new Node[6];
for (int i = 0; i < nodes.length; i++) {
nodes[i] = new Node(random(width), random(height), 10, nodes, i);
}
}
void draw() {
for (int i=0; i < nodes.length; i++) {
nodes[i].connect();
nodes[i].display();
}
}
class Node {
float x;
float y;
float diameter;
Node[] otherNodes;
int id;
Node (float xin, float yin, float din, Node[] others, int idin) {
x = xin;
y = yin;
diameter = din;
otherNodes = others;
id = idin;
}
void connect() {
for (int i=id; i < nodes.length; i++) {
line(x, y, otherNodes[i].x, otherNodes[i].y);
}
}
void display() {
ellipse(x, y, diameter, diameter);
}
}
// of every other element. Specifically, it draws a line from each
// node to every other node.
Node[] nodes;
void setup() {
size(600, 600);
nodes = new Node[6];
for (int i = 0; i < nodes.length; i++) {
nodes[i] = new Node(random(width), random(height), 10, nodes, i);
}
}
void draw() {
for (int i=0; i < nodes.length; i++) {
nodes[i].connect();
nodes[i].display();
}
}
class Node {
float x;
float y;
float diameter;
Node[] otherNodes;
int id;
Node (float xin, float yin, float din, Node[] others, int idin) {
x = xin;
y = yin;
diameter = din;
otherNodes = others;
id = idin;
}
void connect() {
for (int i=id; i < nodes.length; i++) {
line(x, y, otherNodes[i].x, otherNodes[i].y);
}
}
void display() {
ellipse(x, y, diameter, diameter);
}
}
Thu, Jan 17, 2008 Permanent link
Categories: code
Sent to project: Emergence and Navigating Space
Categories: code
Sent to project: Emergence and Navigating Space
![]() |
RSS for this post |