xxxxxxxxxx
87
let table;
function preload() {
table = loadTable("https://think.cs.vt.edu/corgis/datasets/csv/food/food.csv", "csv", "header");
}
function setup() {
createCanvas(400,400);
frameRate(1);
colorMode(HSB, 100);
}
function draw() {
let row = table.getRow(Math.round(random(table.getRowCount())));
console.log(row)
let food = row.getString("Description");
console.log(food)
let color1 = row.getNum("Data.Major Minerals.Sodium") % 100;
console.log("color1 " + color1);
let color2 = row.getNum("Data.Cholesterol") % 100;
console.log("color2 " + color2);
let sides = 3 + (row.getNum("Data.Major Minerals.Calcium") / 10);
console.log("sides " + sides);
let noseW = row.getNum("Data.Carbohydrate") * 10 % 100;
console.log("noseW " + noseW);
let noseH = row.getNum("Data.Major Minerals.Sodium") % 100;
console.log("noseH " + noseH);
let brow = row.getNum("Data.Fat.Saturated Fat") % 25;
console.log("brow " + brow);
background("white");
noStroke();
// Head
fill(color1, 50, 50);
regularPolygon(200, 200, 150, sides);
// Eyes
fill('white');
ellipse(160, 150, 50, 50);
ellipse(240, 150, 50, 50);
fill('black');
ellipse(160, 150, 20, 20);
ellipse(240, 150, 20, 20);
// Eyebrows
fill(color2, 75, 50);
rect(130, random(115,125), 60, brow);
rect(210, random(115,125), 60, brow);
// Nose
/*
stroke('purple');
strokeWeight(8);
noFill();
arc(190, 200, 100, 50, 270, 45);
*/
fill(color1, 100, random(100));
ellipse(200, 200, noseW, noseH);
// Randomize the width and/or height
// to simulate speech
fill(color2, 100, 25);
noStroke();
ellipse(200, 275, random(90, 100), random(10,50));
textAlign(CENTER, CENTER);
text(food, 200, 350);
}
function regularPolygon(x, y, radius, npoints) {
let angle = TWO_PI / npoints;
beginShape();
for (let a = 0; a < TWO_PI; a += angle) {
let sx = x + cos(a) * radius;
let sy = y + sin(a) * radius;
vertex(sx, sy);
}
endShape(CLOSE);
}