// lines_9f // 10/08/2005 Thing[] myThings; int type = 2; int max_types = 2; int count = 200; color my_bg = color(30); int range = 33; int buffer = 1900; float friction = 1.1; int timer = 0; void setup() { size(580, 500); background(my_bg); rectMode(CORNER); ellipseMode(CENTER); strokeWeight(2); smooth(); myThings = new Thing[count]; for (int i = 0; i < count; i++) { myThings[i] = new Thing(random(0, width), random(0, height), i); } } void draw() { timer++; if (type == 1) { background(my_bg); } else if (type == 2) { if (timer >= 25) { noStroke(); fill (my_bg, 4); rect (0,0,width,height); timer = 0; } } for (int i = 0; i < count; i++) { myThings[i].run(); } } class Thing { Thing (float myX, float myY, int myI) { x = init_x = x2 = x3 = myX; y = init_y = y2 = y3 = myY; make_color(); this_thing = myI; } boolean pulled; float x_grav = random(-0.1, 0.1); float y_grav = random(-0.1, 0.1); float x_vel = random(-.5,.5); float y_vel = random(-.5,.5); float x, y, x2, y2, x3, y3, init_x, init_y; float circle, mass; float d, closest; int r, g, b; int col; int this_thing; int j, closest_j; void run() { x3 = x2; y3 = y2; x2 = x; y2 = y; find_closest(); draw_shape(); x_vel += x_grav; y_vel += y_grav; x += x_vel; y += y_vel; adjust_gravity(); keep_inside_frame(); } void find_closest() { d = closest = width; pulled = false; for (j = 0; j < count; j++) { if (j != this_thing) { d = dist (x,y, myThings[j].x, myThings[j].y); if (d < closest && d <= range) { closest = d; closest_j = j; pulled = true; } } } if (pulled == true) { init_x = myThings[closest_j].x; init_y = myThings[closest_j].y; x_vel = ((x_vel * 99) + myThings[closest_j].x_vel) / 100; y_vel = ((y_vel * 99) + myThings[closest_j].y_vel) / 100; } } void draw_shape() { if (type == 1) { if (pulled) { stroke (r,g,b,80); noFill(); line (x2, y2, init_x, init_y); } fill (r,g,b,100); noStroke(); ellipse (x2, y2, 3, 3); } else if (type == 2) { noStroke(); fill (r,g,b); mass = 1.5 + ((abs(x_vel) + abs(y_vel)) * 3); if (mass > 2) { ellipse (x2, y2, mass, mass); } fill (my_bg,25); ellipse (x2, y2, mass + 2.5, mass + 2.5); } } void keep_inside_frame() { if (x < 0) { x = width - 2; } else if (x >= width) { x = 1; } if (y < 0) { y = height - 2; } else if (y >= height) { y = 1; } } void adjust_gravity() { if (pulled == true) { if (x > init_x) { x_grav = ((x - init_x) + range) / buffer; } else { x_grav = ((x - init_x) - range) / buffer; } if (y > init_y) { y_grav = ((y - init_y) + range) / buffer; } else { y_grav = ((y - init_y) - range) / buffer; } } else { x_grav /= 1.13; y_grav /= 1.13; x_vel = x_vel / friction; y_vel = y_vel / friction; } } void make_color() { col = int(random (0,8)); if (col == 0) { // white r = 245 + int (random(-10,10)); g = 245 + int (random(-10,10)); b = 220 + int (random(-10,10)); } else if (col == 1) { // yellow r = 235 + int (random(-10,10)); g = 200 + int (random(-10,10)); b = 15 + int (random(-10,10)); } else if (col == 2) { // red r = 240 + int (random(-10,10)); g = 50 + int (random(-10,10)); b = 20 + int (random(-10,10)); } else if (col >= 3) { // off-white r = 240 + int (random(-15,15)); g = 225 + int (random(-15,15)); b = 150 + int (random(-15,15)); } } } void mousePressed() { background(my_bg); type++; if (type > max_types) { type = 1; } }