int N = 100; int[] x1, y1, x2, y2; int dx1, dy1, dx2, dy2; int sx1, sy1, sx2, sy2; void setup() { size(800,600); background(0); x1 = new int[N]; y1 = new int[N]; x2 = new int[N]; y2 = new int[N]; x1[0] = int(random(width)); y1[0] = int(random(height)); x2[0] = int(random(width)); y2[0] = int(random(height)); for( int i = 1 ; i < N ; i++ ) { x1[i] = x1[0]; y1[i] = y1[0]; x2[i] = x2[0]; y2[i] = y2[0]; } setVelocity(); } void draw() { clearToBlack(); updatePos(); drawLines(); if( frameCount % 1000 == 0 ) { setVelocity(); } } void clearToBlack() { noStroke(); fill(0, 90); rect(0,0,width,height); } void setVelocity() { dx1 = int(random(8)) * 3; dy1 = int(random(8)) * 3; dx2 = int(random(8)) * 3; dy2 = int(random(8)) * 3; sx1 = 1 - 2 * int(random(2)); sy1 = 1 - 2 * int(random(2)); sx2 = 1 - 2 * int(random(2)); sy2 = 1 - 2 * int(random(2)); } void updatePos() { for( int i = N-1 ; 0 < i ; i-- ) { x1[i] = x1[i-1]; y1[i] = y1[i-1]; x2[i] = x2[i-1]; y2[i] = y2[i-1]; } x1[0] += sx1 * dx1; y1[0] += sy1 * dy1; x2[0] += sx2 * dx2; y2[0] += sy2 * dy2; if( x1[0] < 0 ) { sx1 = 1; } else if( width < x1[0] ) { sx1 = -1; } if( y1[0] < 0 ) { sy1 = 1; } else if( height < y1[0] ) { sy1 = -1; } if( x2[0] < 0 ) { sx2 = 1; } else if( width < x2[0] ) { sx2 = -1; } if( y2[0] < 0 ) { sy2 = 1; } else if( height < y2[0] ) { sy2 = -1; } } void drawLines() { float alphaStep = 100 / (N - 1); for( int i = 0 ; i < N ; i++ ) { strokeWeight(3); stroke(255, 100 - alphaStep * i); line(x1[i],y1[i],x2[i],y2[i]); } }