ArrayList<Line> lines;
void setup(){
size(500, 500);
frameRate(30);
lines = new ArrayList<Line>();
for(int i = 0; i < 300; i++){
float s1 = random(width);
float s2 = random(width);
float t = random(width);
if(random(1) < 0.5){
lines.add(new Line(new PVector(s1, t), new PVector(s2, t)));
} else {
lines.add(new Line(new PVector(t, s1), new PVector(t, s2)));
}
}
}
void draw(){
background(0);
for(Line l: lines){
l.display();
}
}
class Line {
PVector p1, p2, center;
float offset;
Line(PVector p1, PVector p2){
this.p1 = p1;
this.p2 = p2;
center = PVector.add(p1, p2);
center.div(2);
offset = random(100);
}
void display(){
PVector mouse = new PVector(mouseX, mouseY);
float dis = PVector.dist(mouse, center);
if(dis < 100){
stroke(255, map(sin(frameCount * 0.05 + offset), 0, 1, 0, 255));
strokeWeight(1);
line(p1.x, p1.y, p2.x, p2.y);
}
}
}