// Seung Joon Choi // http://epicure.graffity.net // epicure@hanmail.net // 2005.10.14. class PLife { PLife() { dt = 0.1; x = 0; y = 0; z = 0; r1 = 10; h0 = random(r1) - 2; h = (r1 + r1 * 0.5 + random(r1)) + h0; r2 = h * 2; r3 = h * 4; c = color(random(1), 1, 1); lover = null; turn = int(random(500)); type = int(random(3)); mental_barrier = random(1); } void Interact(PLife[] pls) { Fx = 0; Fy = 0; nF = 0; for(int i = 0; i < pls.length; i++) { PLife pl = pls[i]; if(pl != this) { float dx = x - pl.x; float dy = y - pl.y; float d = sqrt(dx*dx + dy*dy); float R2 = r2 + pl.r2; float R3 = r3 + pl.r3; if(d < R3) { // °ü°è Relation(pl, dx, dy); // ¾ÈƼÇʵå if(d < R2) { Ax += dx / d * 0.1; Ay += dy / d * 0.1; } } } } } void Relation(PLife pl, float dx, float dy) { if(iter < 100) return; float hue_diff = abs(hue(c) - hue(pl.c)); float h_diff = 0; float r = hue_diff + h_diff; if(mode_friendly && r < 0.2) { // °¡±î¿îµ¥·Î ¼­·Î ¸ðÀÓ Fx += -dx * 0.2; Fy += -dy * 0.2; nF++; if(show_line_black) { stroke(0, 0, 0, 0.2); line(x, y, 0, pl.x, pl.y, 0); noStroke(); } if(mode_intimate && r < 0.1) { // Á¤º¸°øÀ¯ boolean lifestyle = false; if(lifestyle1 && type == 0) { X = pl.x; Y = pl.y; lifestyle = true; } if(lifestyle2 && type == 1) { if(random(1) < mental_barrier) { X = pl.X; Y = pl.y; } lifestyle = true; } if(lifestyle3 && type == 2) { if(random(1) < mental_barrier) { float tempX = X; float tempY = Y; X = pl.X; Y = pl.y; pl.X = tempX; pl.Y = tempY; } lifestyle = true; } if(lifestyle) { float d_x = X - x; float d_y = Y - y; Fx += d_x * 0.3; Fy += d_y * 0.3; nF++; } if(show_line_red) { stroke(0, 1, 1, 0.2); line(x, y, 0, X, Y, 0); noStroke(); } } } } void Live() { if(iter > turn) { Ax += (1 - 2 * random(2)) * 20; Ay += (1 - 2 * random(2)) * 20; iter = 0; turn = 500 + int(random(500)); } if(nF > 0) { Fx = Fx / (float)nF; Fy = Fy / (float)nF; } ax = Ax + Fx; ay = Ay + Fy; vx += ax * dt; vy += ay * dt; x += vx * dt; y += vy * dt; vx *= 0.8; vy *= 0.8; Ax *= 0.995; Ay *= 0.995; int range = 1000; if(x > range) x = -range; if(x < -range) x = range; if(y > range) y = -range; if(y < -range) y = range; iter++; } void Render() { pushMatrix(); translate(x, y, z); rotateZ(atan2(vy, vx) + PI*0.5); Geometry(); popMatrix(); } void Geometry() { /* stroke(0, 0, 0, 0.2); noFill(); ellipse(0, 0, r2 * 2, r2 * 2); noStroke(); */ fill(c); pushMatrix(); translate(0, h0, h); box(5); popMatrix(); beginShape(TRIANGLES); /* vertex(0, -r1, 0); vertex(-r1, r1, 0); vertex(r1, r1, 0); */ vertex(0, -r1, 0); vertex(-r1, r1, 0); vertex(0, h0, h); vertex(0, -r1, 0); vertex(r1, r1, 0); vertex(0, h0, h); vertex(-r1, r1, 0); vertex(r1, r1, 0); vertex(0, h0, h); endShape(); } float dt; float x, y, z; float ax, ay; float vx, vy; float r1, r2, r3, h0, h; color c; int age = 0; int iter = 0; int turn = 100; float Ax, Ay; float Fx, Fy; int nF; float X, Y; PLife lover; int type = 0; float mental_barrier = 0; }