In [1]:
/**
   Bryn Mawr College, Department of Computer Science
*/

void setup() {
  size(400, 400);
  background(255);
  noLoop();
  smooth();
}

void draw() {
  
  // Head
  fill(0);
  ellipseMode(CENTER);
  ellipse(200, 160, 60, 80);
  
   // eyes
   fill(255, 255, 0);
   ellipse(185, 130, 5, 5);
   ellipse(215, 130, 5, 5);
  
  // antlers
  fill(0);
  strokeWeight(3);
  line(190, 125, 170, 95);
  ellipse(167, 95, 5, 5);
  line(210, 125, 230, 95);
  ellipse(233, 95, 5, 5);
  
  // Body
  fill(255, 0, 0);
  ellipse(200, 200, 140, 120);
  
  fill(0);
  strokeWeight(5);
  line(200, 140, 200, 260);
  strokeWeight(1);
  
  triangle(200, 250, 205, 260, 195, 260);
  
  // left dots
  fill(0);
  ellipse(140, 200, 8, 8);
  ellipse(155, 180, 7, 7);
  ellipse(165, 160, 8, 8);
  ellipse(158, 210, 6, 6);
  ellipse(172, 197, 8, 8);
  ellipse(185, 172, 9, 9);
  ellipse(180, 222, 8, 8);
  ellipse(164, 236, 8, 8);
  
  // right dots
  ellipse(210, 160, 8, 8);
  ellipse(222, 178, 7, 7);
  ellipse(235, 166, 6, 6);
  ellipse(213, 240, 8, 8);
  ellipse(210, 206, 9, 9);
  ellipse(240, 198, 7, 7);
  ellipse(252, 212, 8, 8);
  ellipse(232, 222, 8, 8);
}
Sketch #1:

Sketch #1 state: Loading...
In [2]:
/**
   Bryn Mawr College, Department of Computer Science
*/

void setup() {
  size(400, 400);
  background(255);
  noLoop();
  smooth();
}

void draw() {
  
  // Head
  fill(0);
  ellipseMode(CENTER);
  ellipse(200, 160, 60, 80);
  
   // eyes
   fill(255, 255, 0);
   ellipse(185, 130, 5, 5);
   ellipse(215, 130, 5, 5);
  
  // antlers
  fill(0);
  strokeWeight(3);
  line(190, 125, 170, 95);
  ellipse(167, 95, 5, 5);
  line(210, 125, 230, 95);
  ellipse(233, 95, 5, 5);
  
  // Body
  fill(0, 128, 128);
  ellipse(200, 200, 140, 120);
  
  fill(0);
  strokeWeight(5);
  line(200, 140, 200, 260);
  strokeWeight(1);
  
  triangle(200, 250, 205, 260, 195, 260);
  
  // left dots
  fill(0);
  ellipse(140, 200, 8, 8);
  ellipse(155, 180, 7, 7);
  ellipse(165, 160, 8, 8);
  ellipse(158, 210, 6, 6);
  ellipse(172, 197, 8, 8);
  ellipse(185, 172, 9, 9);
  ellipse(180, 222, 8, 8);
  ellipse(164, 236, 8, 8);
  
  // right dots
  ellipse(210, 160, 8, 8);
  ellipse(222, 178, 7, 7);
  ellipse(235, 166, 6, 6);
  ellipse(213, 240, 8, 8);
  ellipse(210, 206, 9, 9);
  ellipse(240, 198, 7, 7);
  ellipse(252, 212, 8, 8);
  ellipse(232, 222, 8, 8);
}
Sketch #2:

Sketch #2 state: Loading...
In [3]:
%%file survey.txt
346,300,567,25,102
Computer Science,Anthropology,English,Psychology,Sociology
Created file '/home/dblank/Public/CS110 Intro to Computing/2015/Notes/survey.txt'.
In [4]:
/**
Bryn Mawr College, Department of Computer Science <br>
Pie chart, data from a file
*/ 

// Arrays to hold data
String[] s;
float [] data;
String[] labels;

float x, y, w;
float angle, theta;
float total = 0.0;

float kx, ky, kw, ks;
float currentHue=0;
float deltaHue;

void setup() {
  size(500, 500);
  smooth();
  noLoop();
  background(255);

  // Center and size of chart
  x = width/2 - 100;
  y = height/2;
  w = 200;
  
  // Init Legend
  kx = x + 0.75*w;
  ky = y - 0.5*w;
  kw = 20;
  ks = 10;

  // Load and normalize data
  s = loadStrings("survey.txt");
  data = float(split(s[0],","));
  labels = split(s[1],",");
  
  for (int i=0; i<data.length; i++) 
    total += data[i];
  for (int i=0; i<data.length; i++) 
    data[i] = 100.0*(data[i] / total);

  colorMode(HSB);
  deltaHue = 255.0/data.length;  
}

void draw() {
  angle = 0;

  for (int i = 0; i < data.length; i++) {
    // Draw the ith Pie
    fill( color(currentHue,240,240) );
    theta = angle + data[i]*2*PI/100.0;
    arc(x, y, w, w, angle, theta);
    angle = theta;
    currentHue += deltaHue;
        
    ky = ky + 2*kw;
    rect(kx, ky, kw, kw);
    fill(0);
    text(labels[i], kx+kw+ks, ky+kw);
  }

}
Sketch #3:

Sketch #3 state: Loading...