Line theLines[];
int numLines = 100;
boolean looping = true;
void setup() {
size(1000, 800);
theLines = new Line[numLines];
for (int i = 0; i < numLines; ++i) {
float LineSize = constrain(20 + (randomGaussian() * 50), 1, 300);
theLines[i] = new Line(random(width), random(height), LineSize);
theLines[i].randomiseDirection();
}
background(#FFFFFF);
}
void draw() {
//background(0);
for (int i = 0; i < numLines; i++) {
for (int j = i+1; j < numLines; j++) {
if (theLines[i].intersect(theLines[j])) {
theLines[i].display(theLines[j]);
theLines[i].direction += mouseX;
theLines[j].direction -= mouseY;
}
}
theLines[i].move();
}
}
class Line {
float x;
float y;
float size;
float speed;
float direction;
float omega;
Line(float x_, float y_, float size_) {
x = x_;
y = y_;
size = size_;
speed = 10;
direction = 0;
omega = 0;
}
void randomiseDirection() {
speed = random(10, mouseY);
direction = random(80);
omega = randomGaussian() * 1;
}
void move() {
float dx, dy;
dx = cos(radians(direction)) * speed;
dy = sin(radians(direction)) * speed;
x += dx;
y += dy;
direction += omega;
checkBounds();
}
void checkBounds() {
if (x <= 0 || x >= width || y <= 0 || y >= height) {
direction += 90;
direction = direction % 180;
}
}
void display(Line anotherLine) {
float c;
float d = dist(x, y, anotherLine.x, anotherLine.y);
c = map(d, 0, size*2 + anotherLine.size*2, 255, 0);
stroke(c);
line(x, y, anotherLine.x, anotherLine.y);
}
boolean intersect(Line anotherLine) {
return dist(x, y, anotherLine.x, anotherLine.y) < (size*2 + anotherLine.size*2);
}
}
0 comments:
Post a Comment