import krister.Ess.*; /* Quételet Created by: Peter Chiocchetti (http://arton.cunst.net/) February-April 2006 Thomas Feuerstein (http://feuerstein.myzel.net/) based on a sketch by: Charles Hinshaw (http://www.everydayrevolution.com) and John Beech (http://www.mkv25.net/?item_id=74) April 2004 ----------------------------------------------------------- */ Channel fly; // very annoying PImage img; // image we want to track PImage sprites[]; // our pencils network n1; // having a ball (network) int qty = 800; // number of balls in network // -------------------------------------------------------- void setup() { framerate(20); noiseDetail(2, 0.99); img = loadImage("quetelet.png"); size (768, 576, P3D); n1 = new network(qty, width, height); /* Sprites */ sprites = new PImage[3]; sprites[0] = loadImage("01.png"); sprites[1] = loadImage("02.png"); sprites[2] = loadImage("03.png"); /* Sound */ Ess.start(this); fly = new Channel(); fly.initBuffer(fly.frames(1283)); fly.wave(Ess.SINE, 100, .25); fly.play(Ess.FOREVER); } public void stop () { Ess.stop(); super.stop(); } void draw() { if(keyPressed && keyCode == SHIFT) image(img, 0, 0); else background(255, 255, 255); n1.run(); } // -------------------------------------------------------- class network { int nodes; int[] noded; float[] nodex; float[] nodey; float[] noisex; float[] noisey; int[] neighbors; int x, y, w, h; int maxlength = 40; network(int nodes, int w, int h) { this.nodes = max(1, nodes); noded = new int[nodes]; // direction nodex = new float[nodes]; nodey = new float[nodes]; noisex = new float[nodes]; noisey = new float[nodes]; neighbors = new int[nodes]; this.w = w; this.h = h; for (int i = 0; i < nodes; i++) { noisex[i] = random(nodes); noisey[i] = random(nodes); nodex[i] = noise(noisex[i]) * w; nodey[i] = noise(noisey[i]) * h; } } void run() { network_noise(); create_connections(); show_nodes(); } void create_connections() { // find neighbors int[] newneighbors = new int[nodes]; float dist; for (int i = 0; i < nodes; i++) newneighbors[i] = 0; for (int i = 0; i < nodes; i++) { for(int j = 0; j < nodes; j++) { dist = dist(nodex[i], nodey[i], nodex[j], nodey[j]); if(dist < maxlength) { newneighbors[i]++; newneighbors[j]++; } } } neighbors = newneighbors; } void network_noise() // perlin noise for all nodes { color b, c; b = color(0, 0, 0); for (int i = 0; i < nodes; i++) { // different speed depending on bg color & no. of neighbors c = img.pixels[int(nodey[i])*img.width+int(nodex[i])]; if (c == b) { noisex[i] += (.00002 * neighbors[i]); noisey[i] += (.00002 * neighbors[i]); } else { noisex[i] += (.0002 * neighbors[i]); noisey[i] += (.0002 * neighbors[i]); } // different sprite depending on neighbor count nodex[i] = noise(noisex[i]) * w; nodey[i] = noise(noisey[i]) * h; if (neighbors[i] > 50) // lots noded[i] = 0; else if (neighbors[i] > 20) // many noded[i] = 1; else // few noded[i] = 2; } } void show_nodes() // draw all nodes to screen { for (int i = 0; i < nodes; i++) // subtract half a sprites width/heigth image(sprites[noded[i]], nodex[i] - 8, nodey[i] - 8); } }