/** A voting trend visualization by
Guru */ int n = 5; int selected = 0; int result[] = new int[] { 20 + rnd(100), 20 + rnd(100), 20 + rnd(100), 20 + rnd(100), 20 + rnd(100), }; int weight[][] = new int[][]{ new int[]{0, rnd(8), rnd(8), rnd(8), rnd(8)}, new int[]{rnd(8), 0, rnd(8), rnd(8), rnd(8)}, new int[]{rnd(8), rnd(8), 0, rnd(8), rnd(8)}, new int[]{rnd(8), rnd(8), rnd(8), 0, rnd(8)}, new int[]{rnd(8), rnd(8), rnd(8), rnd(8), 0} }; int rnd( int m ) { return 2 + int(random(m)); } color[] colors = new color[]{ color( 200, 0, 200 ), color( 15, 180, 180 ), color( 160, 128, 30 ), color( 128, 15, 200 ), color( 128, 128, 128 ) }; int RADIUS=150; void setup() { size(400,400); smooth(); } void draw() { background( 200 ); drawLines(); drawEllipses(); for( int i = 0; i < n; i++ ) { float ang = i * 2 * PI / n; float x = 200 + sin( ang ) * RADIUS; float y = 200 + cos( ang ) * RADIUS; if (mouseOver( x, y, result[i] / 2 )) { if (mousePressed && mouseButton == LEFT ) { selected = i; } } } } void drawLines() { float ang = selected * 2 * PI / n; float x = 200 + sin( ang ) * RADIUS; float y = 200 + cos( ang ) * RADIUS; stroke( colors[selected] ); for( int i=0; i < n; i++ ) { if ( i != selected ) { float tang = i * 2 * PI / n; float tx = 200 + sin( tang ) * RADIUS; float ty = 200 + cos( tang ) * RADIUS; noFill(); strokeWeight( weight[selected][i] ); bezier( x, y, 200, 200, 200, 200, tx,ty ); } } } void drawEllipses() { for( int i=0; i < n; i ++ ) { float ang = i * 2 * PI / n; float x = 200 + sin( ang ) * RADIUS; float y = 200 + cos( ang ) * RADIUS; if ( i == selected ) { strokeWeight(2); stroke( colors[i] ); } else { noStroke(); } if (mouseOver( x, y, result[i] / 2 )) { stroke( 255 ); strokeWeight( 3 ); } fill( colors[i] ); ellipse(x, y, result[i],result[i] ); } } boolean mouseOver( float x, float y, int r ) { int dx = int(x) - mouseX; int dy = int(y) - mouseY; return dx * dx + dy * dy < r * r; }