Emeline Liu

   About    Resume    Archive    Feed


Complete Graphs

Click!



Credit for the complete graphs code: this forum post.

Click "Read more" to see the Processing code.

// https://forum.processing.org/two/discussion/23879/complete-graph
int COUNT = 7;
final int RAD = 200;
int angle = 0;
int pos = 1;

float getX(float a) {
 return (RAD * cos(a * TWO_PI / COUNT));
}

float getY(float a) {
 return (RAD * sin(a * TWO_PI / COUNT));
}

void setup() {
 size(600, 600);
}

void draw() {
 background(30 + sin(angle / 3) * 30);
 translate(width / 2, height / 2);
 strokeWeight(10);
 if (pos == 1) {
  rotate(angle += 0.01);
 } else {
  rotate(angle -= 0.01);
 }
 for (int i = 0; i < COUNT; i++) {
  for (int j = 0; j < i; j++) {
   stroke(140, 140 + sin(angle) * 20, 190);
   line(getX(i), getY(i), getX(j), getY(j));
  }
 }
}

void mousePressed() {
 COUNT++;
 if (COUNT > 15) {
  COUNT = 2;
 }
 pos *= -1;
 RAD = random(150, 280);
}