//--------------------------------- // bretzel orgie (processing) // // date: 2006.03.17 // author: erational.org // version: 0.1 //--------------------------------- // parameters //----------------------------------- int item = 0; // nb elements int d = 4; // drawing speed int state = 0; // state: 0: nothing 1: growing int px = 200; // pointer current x int py = 200; // pointer current y int dx = -1; // direction x int dy = 0; // direction y int entropy = 4; //105; // entropy level 0: very unstable 100000: stable int r; // current color: red int g; // current color: green int b; // current color: blue // init GUI //----------------------------------- int px2 = px; int py2 = py; void setup() { size(800,1000); background(90); rand_color(); } // function //----------------------------------- boolean new_event() { if ((int)random(entropy)==0) return true; else return false; } void change_direction() { switch ((int)random(4)) { case 0: dx=0; dy=1; break; case 1: dx=1; dy=0; break; case 2: dx=0; dy=-1; break; case 3: dx=-1; dy=0; break; } } void rand_color() { r = (int)random(255); g = (int)random(255); b = (int)random(255); } // main //----------------------------------- void draw() { if (state==0) { // state: nothing // create new element item++; px2 = px; py2 = py; state = 1; } else if (state==1) { // state: growing // growing px2 += dx * d ; py2 += dy * d; stroke(r, g, b, 77 +random(153)); line(px,py,px2,py2); // change state ? if (new_event()) { state = 0; px = px2; py = py2; if (px<0||px>800) px = (int)random(800); if (py<0||py>800) py = (int)random(800); change_direction(); rand_color(); } } }