int WIDTH = 400; int HEIGHT = 400; int c1, c2, s1, s2; int RANGE = 1; int STILLRUNNING = 0; class Edge { Edge e1; Edge e2; int startx, starty, endx, endy; int x, y; int dir; // -2/2 : y | -1/1 : x int running = 0; int exists = 0; int spawned = 0; int age; int col; Edge(int xIn, int yIn, int dirIn, int ageIn, int colIn) { running = 1; startx = xIn; starty = yIn; x = xIn; y = yIn; dir = dirIn; exists = 1; spawned = 0; age = ageIn+1; col = colIn; } void posupdate() { int next; x += (dir == -1 || dir == 1) ? dir : 0; y += (dir == -2 || dir == 2) ? (dir/2) : 0; next = y*width+x; if(x >= WIDTH || x <= 0 || y <= 0 || y >= HEIGHT || next <= 0 || next >= WIDTH*HEIGHT || pixels[next] != 0xffffffff) { borked(); } else if(next < WIDTH*HEIGHT && next > 0) { pixels[next] = col; STILLRUNNING = 1; } } void borked() { running = 0; endx = x; endy = y; if(((dir == -1 || dir == 1) && Math.abs(endx - startx) > RANGE) || ((dir == -2 || dir == 2) && Math.abs(endy - starty) > RANGE) ) { spawn(); } } void spawn() { int dir1; spawned = 1; if(dir == 2 || dir == -2) {dir1 = -1;} else {dir1 = -2;} int brightness; brightness = (age < 32) ? 190 + age*2:255; e1 = new Edge((int)random(startx, endx), (int)random(starty, endy), dir1, age, color(c1, s1, brightness)); e2 = new Edge((int)random(startx, endx), (int)random(starty, endy), -1*dir1, age, color(c2, s2, brightness)); } void update() { if(running == 1) posupdate(); if(spawned == 1) { e1.update(); e2.update(); } } } Edge e1; void setup() { size(400,400); colorMode(HSB); background(#ffffff); noBackground(); startup(); } void startup() { c1 = (int)random(255); c2 = (int)random(255); s1 = (int)random(128,240); s2 = (int)random(60); for(int i = 0; i < WIDTH*HEIGHT; i++) { pixels[i] = 0xffffffff; } int dir; dir = (random(2) < 1) ? ((random(2) < 1) ? -2:2) : ((random(2) < 1) ? -1:1); e1 = new Edge((int)random(WIDTH), (int)random(HEIGHT), dir, 0, color((int)random(255), 255, 196)); } void loop() { STILLRUNNING = 0; e1.update(); if(STILLRUNNING == 0) { delay(5000); startup(); } }