mirror of
https://github.com/processing/processing4.git
synced 2026-05-03 17:35:00 +02:00
add "visualizing data" examples
This commit is contained in:
14
java/examples/Books/Visualizing Data/ch03-usmap/readme.txt
Normal file
14
java/examples/Books/Visualizing Data/ch03-usmap/readme.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
For this chapter, the a sketch that implements every step described in the
|
||||
book is included. This is because the figures and steps used to develop the
|
||||
code don't really line up (there are more steps than figures). Each sketch
|
||||
has a name like step15_framerate, which should be self-explanatory when used
|
||||
with the book. (I do not recommend using this ugly style of naming for your
|
||||
own sketches, it's done this way simply because the step/figure numbering
|
||||
is relevant and needs to be included).
|
||||
|
||||
All examples have been tested but if you find errors of any kind (typos,
|
||||
unused variables, profanities in the comments, the usual), please contact
|
||||
me through http://benfry.com/writing and I'll be happy to fix the code.
|
||||
|
||||
The code in this file is (c) 2008 Ben Fry. Rights to use of the code can be
|
||||
found in the preface of "Visualizing Data".
|
||||
@@ -0,0 +1,11 @@
|
||||
PImage mapImage;
|
||||
|
||||
void setup() {
|
||||
size(640, 400);
|
||||
mapImage = loadImage("map.png");
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
image(mapImage, 0, 0);
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
class Table {
|
||||
int rowCount;
|
||||
String[][] data;
|
||||
|
||||
|
||||
Table(String filename) {
|
||||
String[] rows = loadStrings(filename);
|
||||
data = new String[rows.length][];
|
||||
|
||||
for (int i = 0; i < rows.length; i++) {
|
||||
if (trim(rows[i]).length() == 0) {
|
||||
continue; // skip empty rows
|
||||
}
|
||||
if (rows[i].startsWith("#")) {
|
||||
continue; // skip comment lines
|
||||
}
|
||||
|
||||
// split the row on the tabs
|
||||
String[] pieces = split(rows[i], TAB);
|
||||
// copy to the table array
|
||||
data[rowCount] = pieces;
|
||||
rowCount++;
|
||||
|
||||
// this could be done in one fell swoop via:
|
||||
//data[rowCount++] = split(rows[i], TAB);
|
||||
}
|
||||
// resize the 'data' array as necessary
|
||||
data = (String[][]) subset(data, 0, rowCount);
|
||||
}
|
||||
|
||||
|
||||
int getRowCount() {
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
|
||||
// find a row by its name, returns -1 if no row found
|
||||
int getRowIndex(String name) {
|
||||
for (int i = 0; i < rowCount; i++) {
|
||||
if (data[i][0].equals(name)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
println("No row named '" + name + "' was found");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
String getRowName(int row) {
|
||||
return getString(row, 0);
|
||||
}
|
||||
|
||||
|
||||
String getString(int rowIndex, int column) {
|
||||
return data[rowIndex][column];
|
||||
}
|
||||
|
||||
|
||||
String getString(String rowName, int column) {
|
||||
return getString(getRowIndex(rowName), column);
|
||||
}
|
||||
|
||||
|
||||
int getInt(String rowName, int column) {
|
||||
return parseInt(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
int getInt(int rowIndex, int column) {
|
||||
return parseInt(getString(rowIndex, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(String rowName, int column) {
|
||||
return parseFloat(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(int rowIndex, int column) {
|
||||
return parseFloat(getString(rowIndex, column));
|
||||
}
|
||||
|
||||
|
||||
void setRowName(int row, String what) {
|
||||
data[row][0] = what;
|
||||
}
|
||||
|
||||
|
||||
void setString(int rowIndex, int column, String what) {
|
||||
data[rowIndex][column] = what;
|
||||
}
|
||||
|
||||
|
||||
void setString(String rowName, int column, String what) {
|
||||
int rowIndex = getRowIndex(rowName);
|
||||
data[rowIndex][column] = what;
|
||||
}
|
||||
|
||||
|
||||
void setInt(int rowIndex, int column, int what) {
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
|
||||
|
||||
void setInt(String rowName, int column, int what) {
|
||||
int rowIndex = getRowIndex(rowName);
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
|
||||
|
||||
void setFloat(int rowIndex, int column, float what) {
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
|
||||
|
||||
void setFloat(String rowName, int column, float what) {
|
||||
int rowIndex = getRowIndex(rowName);
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
AL 439 270
|
||||
AK 94 325
|
||||
AZ 148 241
|
||||
AR 368 247
|
||||
CA 56 176
|
||||
CO 220 183
|
||||
CT 576 120
|
||||
DE 556 166
|
||||
FL 510 331
|
||||
GA 478 267
|
||||
HI 232 380
|
||||
ID 143 101
|
||||
IL 405 168
|
||||
IN 437 165
|
||||
IA 357 147
|
||||
KS 302 194
|
||||
KY 453 203
|
||||
LA 371 302
|
||||
ME 595 59
|
||||
MD 538 162
|
||||
MA 581 108
|
||||
MI 446 120
|
||||
MN 339 86
|
||||
MS 406 274
|
||||
MO 365 197
|
||||
MT 194 61
|
||||
NE 286 151
|
||||
NV 102 157
|
||||
NH 580 89
|
||||
NJ 561 143
|
||||
NM 208 245
|
||||
NY 541 107
|
||||
NC 519 221
|
||||
ND 283 65
|
||||
OH 472 160
|
||||
OK 309 239
|
||||
OR 74 86
|
||||
PA 523 144
|
||||
RI 589 117
|
||||
SC 506 251
|
||||
SD 286 109
|
||||
TN 441 229
|
||||
TX 291 299
|
||||
UT 154 171
|
||||
VT 567 86
|
||||
VA 529 189
|
||||
WA 92 38
|
||||
WV 496 178
|
||||
WI 392 103
|
||||
WY 207 125
|
||||
|
@@ -0,0 +1,30 @@
|
||||
PImage mapImage;
|
||||
Table locationTable;
|
||||
int rowCount;
|
||||
|
||||
void setup() {
|
||||
size(640, 400);
|
||||
mapImage = loadImage("map.png");
|
||||
// Make a data table from a file that contains
|
||||
// the coordinates of each state.
|
||||
locationTable = new Table("locations.tsv");
|
||||
// The row count will be used a lot, store it locally.
|
||||
rowCount = locationTable.getRowCount();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
image(mapImage, 0, 0);
|
||||
|
||||
// Drawing attributes for the ellipses
|
||||
smooth();
|
||||
fill(192, 0, 0);
|
||||
noStroke();
|
||||
|
||||
// Loop through the rows of the locations file and draw the points
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
float x = locationTable.getFloat(row, 1); // column 1
|
||||
float y = locationTable.getFloat(row, 2); // column 2
|
||||
ellipse(x, y, 9, 9);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
class Table {
|
||||
String[][] data;
|
||||
int rowCount;
|
||||
|
||||
|
||||
Table() {
|
||||
data = new String[10][10];
|
||||
}
|
||||
|
||||
|
||||
Table(String filename) {
|
||||
String[] rows = loadStrings(filename);
|
||||
data = new String[rows.length][];
|
||||
|
||||
for (int i = 0; i < rows.length; i++) {
|
||||
if (trim(rows[i]).length() == 0) {
|
||||
continue; // skip empty rows
|
||||
}
|
||||
if (rows[i].startsWith("#")) {
|
||||
continue; // skip comment lines
|
||||
}
|
||||
|
||||
// split the row on the tabs
|
||||
String[] pieces = split(rows[i], TAB);
|
||||
// copy to the table array
|
||||
data[rowCount] = pieces;
|
||||
rowCount++;
|
||||
|
||||
// this could be done in one fell swoop via:
|
||||
//data[rowCount++] = split(rows[i], TAB);
|
||||
}
|
||||
// resize the 'data' array as necessary
|
||||
data = (String[][]) subset(data, 0, rowCount);
|
||||
}
|
||||
|
||||
|
||||
int getRowCount() {
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
|
||||
// find a row by its name, returns -1 if no row found
|
||||
int getRowIndex(String name) {
|
||||
for (int i = 0; i < rowCount; i++) {
|
||||
if (data[i][0].equals(name)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
println("No row named '" + name + "' was found");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
String getRowName(int row) {
|
||||
return getString(row, 0);
|
||||
}
|
||||
|
||||
|
||||
String getString(int rowIndex, int column) {
|
||||
return data[rowIndex][column];
|
||||
}
|
||||
|
||||
|
||||
String getString(String rowName, int column) {
|
||||
return getString(getRowIndex(rowName), column);
|
||||
}
|
||||
|
||||
|
||||
int getInt(String rowName, int column) {
|
||||
return parseInt(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
int getInt(int rowIndex, int column) {
|
||||
return parseInt(getString(rowIndex, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(String rowName, int column) {
|
||||
return parseFloat(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(int rowIndex, int column) {
|
||||
return parseFloat(getString(rowIndex, column));
|
||||
}
|
||||
|
||||
|
||||
void setRowName(int row, String what) {
|
||||
data[row][0] = what;
|
||||
}
|
||||
|
||||
|
||||
void setString(int rowIndex, int column, String what) {
|
||||
data[rowIndex][column] = what;
|
||||
}
|
||||
|
||||
|
||||
void setString(String rowName, int column, String what) {
|
||||
int rowIndex = getRowIndex(rowName);
|
||||
data[rowIndex][column] = what;
|
||||
}
|
||||
|
||||
|
||||
void setInt(int rowIndex, int column, int what) {
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
|
||||
|
||||
void setInt(String rowName, int column, int what) {
|
||||
int rowIndex = getRowIndex(rowName);
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
|
||||
|
||||
void setFloat(int rowIndex, int column, float what) {
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
|
||||
|
||||
void setFloat(String rowName, int column, float what) {
|
||||
int rowIndex = getRowIndex(rowName);
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
|
||||
|
||||
// Write this table as a TSV file
|
||||
void write(PrintWriter writer) {
|
||||
for (int i = 0; i < rowCount; i++) {
|
||||
for (int j = 0; j < data[i].length; j++) {
|
||||
if (j != 0) {
|
||||
writer.print(TAB);
|
||||
}
|
||||
if (data[i][j] != null) {
|
||||
writer.print(data[i][j]);
|
||||
}
|
||||
}
|
||||
writer.println();
|
||||
}
|
||||
writer.flush();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
AL 439 270
|
||||
AK 94 325
|
||||
AZ 148 241
|
||||
AR 368 247
|
||||
CA 56 176
|
||||
CO 220 183
|
||||
CT 576 120
|
||||
DE 556 166
|
||||
FL 510 331
|
||||
GA 478 267
|
||||
HI 232 380
|
||||
ID 143 101
|
||||
IL 405 168
|
||||
IN 437 165
|
||||
IA 357 147
|
||||
KS 302 194
|
||||
KY 453 203
|
||||
LA 371 302
|
||||
ME 595 59
|
||||
MD 538 162
|
||||
MA 581 108
|
||||
MI 446 120
|
||||
MN 339 86
|
||||
MS 406 274
|
||||
MO 365 197
|
||||
MT 194 61
|
||||
NE 286 151
|
||||
NV 102 157
|
||||
NH 580 89
|
||||
NJ 561 143
|
||||
NM 208 245
|
||||
NY 541 107
|
||||
NC 519 221
|
||||
ND 283 65
|
||||
OH 472 160
|
||||
OK 309 239
|
||||
OR 74 86
|
||||
PA 523 144
|
||||
RI 589 117
|
||||
SC 506 251
|
||||
SD 286 109
|
||||
TN 441 229
|
||||
TX 291 299
|
||||
UT 154 171
|
||||
VT 567 86
|
||||
VA 529 189
|
||||
WA 92 38
|
||||
WV 496 178
|
||||
WI 392 103
|
||||
WY 207 125
|
||||
|
@@ -0,0 +1,50 @@
|
||||
AL 0.1
|
||||
AK -5.3
|
||||
AZ 3
|
||||
AR 7
|
||||
CA 11
|
||||
CO 1.5
|
||||
CT -6.7
|
||||
DE -4
|
||||
FL 9
|
||||
GA 2
|
||||
HI -3.3
|
||||
ID 6.6
|
||||
IL 7.2
|
||||
IN 7.1
|
||||
IA 6.9
|
||||
KS 6
|
||||
KY 1.8
|
||||
LA 7.5
|
||||
ME -4
|
||||
MD 0.1
|
||||
MA -6
|
||||
MI 1.7
|
||||
MN -2
|
||||
MS -4.4
|
||||
MO -2
|
||||
MT 1.0
|
||||
NE 1.2
|
||||
NV 1.6
|
||||
NH 0.5
|
||||
NJ 0.2
|
||||
NM 8.8
|
||||
NY 1.4
|
||||
NC 9.7
|
||||
ND 5.4
|
||||
OH 3.2
|
||||
OK 6
|
||||
OR -4
|
||||
PA -7
|
||||
RI -2
|
||||
SC 1
|
||||
SD 6
|
||||
TN 5
|
||||
TX -3.4
|
||||
UT 2.3
|
||||
VT 4.8
|
||||
VA 3
|
||||
WA 2.2
|
||||
WV 5.4
|
||||
WI 3.1
|
||||
WY -6
|
||||
|
@@ -0,0 +1,57 @@
|
||||
PImage mapImage;
|
||||
Table locationTable;
|
||||
int rowCount;
|
||||
|
||||
Table dataTable;
|
||||
float dataMin = MAX_FLOAT;
|
||||
float dataMax = MIN_FLOAT;
|
||||
|
||||
|
||||
void setup() {
|
||||
size(640, 400);
|
||||
mapImage = loadImage("map.png");
|
||||
locationTable = new Table("locations.tsv");
|
||||
rowCount = locationTable.getRowCount();
|
||||
|
||||
// Read the data table
|
||||
dataTable = new Table("random.tsv");
|
||||
|
||||
// Find the minimum and maximum values
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
float value = dataTable.getFloat(row, 1);
|
||||
if (value > dataMax) {
|
||||
dataMax = value;
|
||||
}
|
||||
if (value < dataMin) {
|
||||
dataMin = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
image(mapImage, 0, 0);
|
||||
|
||||
smooth();
|
||||
fill(192, 0, 0);
|
||||
noStroke();
|
||||
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
String abbrev = dataTable.getRowName(row);
|
||||
float x = locationTable.getFloat(abbrev, 1);
|
||||
float y = locationTable.getFloat(abbrev, 2);
|
||||
drawData(x, y, abbrev);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Map the size of the ellipse to the data value
|
||||
void drawData(float x, float y, String abbrev) {
|
||||
// Get data value for state
|
||||
float value = dataTable.getFloat(abbrev, 1);
|
||||
// Re-map the value to a number between 2 and 40
|
||||
float mapped = map(value, dataMin, dataMax, 2, 40);
|
||||
// Draw an ellipse for this item
|
||||
ellipse(x, y, mapped, mapped);
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
class Table {
|
||||
int rowCount;
|
||||
String[][] data;
|
||||
|
||||
|
||||
Table(String filename) {
|
||||
String[] rows = loadStrings(filename);
|
||||
data = new String[rows.length][];
|
||||
|
||||
for (int i = 0; i < rows.length; i++) {
|
||||
if (trim(rows[i]).length() == 0) {
|
||||
continue; // skip empty rows
|
||||
}
|
||||
if (rows[i].startsWith("#")) {
|
||||
continue; // skip comment lines
|
||||
}
|
||||
|
||||
// split the row on the tabs
|
||||
String[] pieces = split(rows[i], TAB);
|
||||
// copy to the table array
|
||||
data[rowCount] = pieces;
|
||||
rowCount++;
|
||||
|
||||
// this could be done in one fell swoop via:
|
||||
//data[rowCount++] = split(rows[i], TAB);
|
||||
}
|
||||
// resize the 'data' array as necessary
|
||||
data = (String[][]) subset(data, 0, rowCount);
|
||||
}
|
||||
|
||||
|
||||
int getRowCount() {
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
|
||||
// find a row by its name, returns -1 if no row found
|
||||
int getRowIndex(String name) {
|
||||
for (int i = 0; i < rowCount; i++) {
|
||||
if (data[i][0].equals(name)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
println("No row named '" + name + "' was found");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
String getRowName(int row) {
|
||||
return getString(row, 0);
|
||||
}
|
||||
|
||||
|
||||
String getString(int rowIndex, int column) {
|
||||
return data[rowIndex][column];
|
||||
}
|
||||
|
||||
|
||||
String getString(String rowName, int column) {
|
||||
return getString(getRowIndex(rowName), column);
|
||||
}
|
||||
|
||||
|
||||
int getInt(String rowName, int column) {
|
||||
return parseInt(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
int getInt(int rowIndex, int column) {
|
||||
return parseInt(getString(rowIndex, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(String rowName, int column) {
|
||||
return parseFloat(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(int rowIndex, int column) {
|
||||
return parseFloat(getString(rowIndex, column));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
AL 439 270
|
||||
AK 94 325
|
||||
AZ 148 241
|
||||
AR 368 247
|
||||
CA 56 176
|
||||
CO 220 183
|
||||
CT 576 120
|
||||
DE 556 166
|
||||
FL 510 331
|
||||
GA 478 267
|
||||
HI 232 380
|
||||
ID 143 101
|
||||
IL 405 168
|
||||
IN 437 165
|
||||
IA 357 147
|
||||
KS 302 194
|
||||
KY 453 203
|
||||
LA 371 302
|
||||
ME 595 59
|
||||
MD 538 162
|
||||
MA 581 108
|
||||
MI 446 120
|
||||
MN 339 86
|
||||
MS 406 274
|
||||
MO 365 197
|
||||
MT 194 61
|
||||
NE 286 151
|
||||
NV 102 157
|
||||
NH 580 89
|
||||
NJ 561 143
|
||||
NM 208 245
|
||||
NY 541 107
|
||||
NC 519 221
|
||||
ND 283 65
|
||||
OH 472 160
|
||||
OK 309 239
|
||||
OR 74 86
|
||||
PA 523 144
|
||||
RI 589 117
|
||||
SC 506 251
|
||||
SD 286 109
|
||||
TN 441 229
|
||||
TX 291 299
|
||||
UT 154 171
|
||||
VT 567 86
|
||||
VA 529 189
|
||||
WA 92 38
|
||||
WV 496 178
|
||||
WI 392 103
|
||||
WY 207 125
|
||||
|
@@ -0,0 +1,50 @@
|
||||
AL 0.1
|
||||
AK -5.3
|
||||
AZ 3
|
||||
AR 7
|
||||
CA 11
|
||||
CO 1.5
|
||||
CT -6.7
|
||||
DE -4
|
||||
FL 9
|
||||
GA 2
|
||||
HI -3.3
|
||||
ID 6.6
|
||||
IL 7.2
|
||||
IN 7.1
|
||||
IA 6.9
|
||||
KS 6
|
||||
KY 1.8
|
||||
LA 7.5
|
||||
ME -4
|
||||
MD 0.1
|
||||
MA -6
|
||||
MI 1.7
|
||||
MN -2
|
||||
MS -4.4
|
||||
MO -2
|
||||
MT 1.0
|
||||
NE 1.2
|
||||
NV 1.6
|
||||
NH 0.5
|
||||
NJ 0.2
|
||||
NM 8.8
|
||||
NY 1.4
|
||||
NC 9.7
|
||||
ND 5.4
|
||||
OH 3.2
|
||||
OK 6
|
||||
OR -4
|
||||
PA -7
|
||||
RI -2
|
||||
SC 1
|
||||
SD 6
|
||||
TN 5
|
||||
TX -3.4
|
||||
UT 2.3
|
||||
VT 4.8
|
||||
VA 3
|
||||
WA 2.2
|
||||
WV 5.4
|
||||
WI 3.1
|
||||
WY -6
|
||||
|
@@ -0,0 +1,54 @@
|
||||
PImage mapImage;
|
||||
Table locationTable;
|
||||
int rowCount;
|
||||
|
||||
Table dataTable;
|
||||
float dataMin = MAX_FLOAT;
|
||||
float dataMax = MIN_FLOAT;
|
||||
|
||||
|
||||
void setup() {
|
||||
size(640, 400);
|
||||
mapImage = loadImage("map.png");
|
||||
locationTable = new Table("locations.tsv");
|
||||
rowCount = locationTable.getRowCount();
|
||||
|
||||
// Read the data table
|
||||
dataTable = new Table("random.tsv");
|
||||
|
||||
// Find the minimum and maximum values
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
float value = dataTable.getFloat(row, 1);
|
||||
if (value > dataMax) {
|
||||
dataMax = value;
|
||||
}
|
||||
if (value < dataMin) {
|
||||
dataMin = value;
|
||||
}
|
||||
}
|
||||
|
||||
smooth();
|
||||
noStroke();
|
||||
}
|
||||
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
image(mapImage, 0, 0);
|
||||
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
String abbrev = dataTable.getRowName(row);
|
||||
float x = locationTable.getFloat(abbrev, 1);
|
||||
float y = locationTable.getFloat(abbrev, 2);
|
||||
drawData(x, y, abbrev);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void drawData(float x, float y, String abbrev) {
|
||||
float value = dataTable.getFloat(abbrev, 1);
|
||||
float percent = norm(value, dataMin, dataMax);
|
||||
color between = lerpColor(#FF4422, #4422CC, percent); // red to blue
|
||||
fill(between);
|
||||
ellipse(x, y, 15, 15);
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
class Table {
|
||||
int rowCount;
|
||||
String[][] data;
|
||||
|
||||
|
||||
Table(String filename) {
|
||||
String[] rows = loadStrings(filename);
|
||||
data = new String[rows.length][];
|
||||
|
||||
for (int i = 0; i < rows.length; i++) {
|
||||
if (trim(rows[i]).length() == 0) {
|
||||
continue; // skip empty rows
|
||||
}
|
||||
if (rows[i].startsWith("#")) {
|
||||
continue; // skip comment lines
|
||||
}
|
||||
|
||||
// split the row on the tabs
|
||||
String[] pieces = split(rows[i], TAB);
|
||||
// copy to the table array
|
||||
data[rowCount] = pieces;
|
||||
rowCount++;
|
||||
|
||||
// this could be done in one fell swoop via:
|
||||
//data[rowCount++] = split(rows[i], TAB);
|
||||
}
|
||||
// resize the 'data' array as necessary
|
||||
data = (String[][]) subset(data, 0, rowCount);
|
||||
}
|
||||
|
||||
|
||||
int getRowCount() {
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
|
||||
// find a row by its name, returns -1 if no row found
|
||||
int getRowIndex(String name) {
|
||||
for (int i = 0; i < rowCount; i++) {
|
||||
if (data[i][0].equals(name)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
println("No row named '" + name + "' was found");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
String getRowName(int row) {
|
||||
return getString(row, 0);
|
||||
}
|
||||
|
||||
|
||||
String getString(int rowIndex, int column) {
|
||||
return data[rowIndex][column];
|
||||
}
|
||||
|
||||
|
||||
String getString(String rowName, int column) {
|
||||
return getString(getRowIndex(rowName), column);
|
||||
}
|
||||
|
||||
|
||||
int getInt(String rowName, int column) {
|
||||
return parseInt(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
int getInt(int rowIndex, int column) {
|
||||
return parseInt(getString(rowIndex, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(String rowName, int column) {
|
||||
return parseFloat(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(int rowIndex, int column) {
|
||||
return parseFloat(getString(rowIndex, column));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
AL 439 270
|
||||
AK 94 325
|
||||
AZ 148 241
|
||||
AR 368 247
|
||||
CA 56 176
|
||||
CO 220 183
|
||||
CT 576 120
|
||||
DE 556 166
|
||||
FL 510 331
|
||||
GA 478 267
|
||||
HI 232 380
|
||||
ID 143 101
|
||||
IL 405 168
|
||||
IN 437 165
|
||||
IA 357 147
|
||||
KS 302 194
|
||||
KY 453 203
|
||||
LA 371 302
|
||||
ME 595 59
|
||||
MD 538 162
|
||||
MA 581 108
|
||||
MI 446 120
|
||||
MN 339 86
|
||||
MS 406 274
|
||||
MO 365 197
|
||||
MT 194 61
|
||||
NE 286 151
|
||||
NV 102 157
|
||||
NH 580 89
|
||||
NJ 561 143
|
||||
NM 208 245
|
||||
NY 541 107
|
||||
NC 519 221
|
||||
ND 283 65
|
||||
OH 472 160
|
||||
OK 309 239
|
||||
OR 74 86
|
||||
PA 523 144
|
||||
RI 589 117
|
||||
SC 506 251
|
||||
SD 286 109
|
||||
TN 441 229
|
||||
TX 291 299
|
||||
UT 154 171
|
||||
VT 567 86
|
||||
VA 529 189
|
||||
WA 92 38
|
||||
WV 496 178
|
||||
WI 392 103
|
||||
WY 207 125
|
||||
|
@@ -0,0 +1,50 @@
|
||||
AL 0.1
|
||||
AK -5.3
|
||||
AZ 3
|
||||
AR 7
|
||||
CA 11
|
||||
CO 1.5
|
||||
CT -6.7
|
||||
DE -4
|
||||
FL 9
|
||||
GA 2
|
||||
HI -3.3
|
||||
ID 6.6
|
||||
IL 7.2
|
||||
IN 7.1
|
||||
IA 6.9
|
||||
KS 6
|
||||
KY 1.8
|
||||
LA 7.5
|
||||
ME -4
|
||||
MD 0.1
|
||||
MA -6
|
||||
MI 1.7
|
||||
MN -2
|
||||
MS -4.4
|
||||
MO -2
|
||||
MT 1.0
|
||||
NE 1.2
|
||||
NV 1.6
|
||||
NH 0.5
|
||||
NJ 0.2
|
||||
NM 8.8
|
||||
NY 1.4
|
||||
NC 9.7
|
||||
ND 5.4
|
||||
OH 3.2
|
||||
OK 6
|
||||
OR -4
|
||||
PA -7
|
||||
RI -2
|
||||
SC 1
|
||||
SD 6
|
||||
TN 5
|
||||
TX -3.4
|
||||
UT 2.3
|
||||
VT 4.8
|
||||
VA 3
|
||||
WA 2.2
|
||||
WV 5.4
|
||||
WI 3.1
|
||||
WY -6
|
||||
|
@@ -0,0 +1,54 @@
|
||||
PImage mapImage;
|
||||
Table locationTable;
|
||||
int rowCount;
|
||||
|
||||
Table dataTable;
|
||||
float dataMin = MAX_FLOAT;
|
||||
float dataMax = MIN_FLOAT;
|
||||
|
||||
|
||||
void setup() {
|
||||
size(640, 400);
|
||||
mapImage = loadImage("map.png");
|
||||
locationTable = new Table("locations.tsv");
|
||||
rowCount = locationTable.getRowCount();
|
||||
|
||||
// Read the data table
|
||||
dataTable = new Table("random.tsv");
|
||||
|
||||
// Find the minimum and maximum values
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
float value = dataTable.getFloat(row, 1);
|
||||
if (value > dataMax) {
|
||||
dataMax = value;
|
||||
}
|
||||
if (value < dataMin) {
|
||||
dataMin = value;
|
||||
}
|
||||
}
|
||||
smooth();
|
||||
noStroke();
|
||||
}
|
||||
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
tint(255, 160);
|
||||
image(mapImage, 0, 0);
|
||||
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
String abbrev = dataTable.getRowName(row);
|
||||
float x = locationTable.getFloat(abbrev, 1);
|
||||
float y = locationTable.getFloat(abbrev, 2);
|
||||
drawData(x, y, abbrev);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void drawData(float x, float y, String abbrev) {
|
||||
float value = dataTable.getFloat(abbrev, 1);
|
||||
float percent = norm(value, dataMin, dataMax);
|
||||
color between = lerpColor(#296F34, #61E2F0, percent);
|
||||
fill(between);
|
||||
ellipse(x, y, 15, 15);
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
class Table {
|
||||
int rowCount;
|
||||
String[][] data;
|
||||
|
||||
|
||||
Table(String filename) {
|
||||
String[] rows = loadStrings(filename);
|
||||
data = new String[rows.length][];
|
||||
|
||||
for (int i = 0; i < rows.length; i++) {
|
||||
if (trim(rows[i]).length() == 0) {
|
||||
continue; // skip empty rows
|
||||
}
|
||||
if (rows[i].startsWith("#")) {
|
||||
continue; // skip comment lines
|
||||
}
|
||||
|
||||
// split the row on the tabs
|
||||
String[] pieces = split(rows[i], TAB);
|
||||
// copy to the table array
|
||||
data[rowCount] = pieces;
|
||||
rowCount++;
|
||||
|
||||
// this could be done in one fell swoop via:
|
||||
//data[rowCount++] = split(rows[i], TAB);
|
||||
}
|
||||
// resize the 'data' array as necessary
|
||||
data = (String[][]) subset(data, 0, rowCount);
|
||||
}
|
||||
|
||||
|
||||
int getRowCount() {
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
|
||||
// find a row by its name, returns -1 if no row found
|
||||
int getRowIndex(String name) {
|
||||
for (int i = 0; i < rowCount; i++) {
|
||||
if (data[i][0].equals(name)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
println("No row named '" + name + "' was found");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
String getRowName(int row) {
|
||||
return getString(row, 0);
|
||||
}
|
||||
|
||||
|
||||
String getString(int rowIndex, int column) {
|
||||
return data[rowIndex][column];
|
||||
}
|
||||
|
||||
|
||||
String getString(String rowName, int column) {
|
||||
return getString(getRowIndex(rowName), column);
|
||||
}
|
||||
|
||||
|
||||
int getInt(String rowName, int column) {
|
||||
return parseInt(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
int getInt(int rowIndex, int column) {
|
||||
return parseInt(getString(rowIndex, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(String rowName, int column) {
|
||||
return parseFloat(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(int rowIndex, int column) {
|
||||
return parseFloat(getString(rowIndex, column));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
AL 439 270
|
||||
AK 94 325
|
||||
AZ 148 241
|
||||
AR 368 247
|
||||
CA 56 176
|
||||
CO 220 183
|
||||
CT 576 120
|
||||
DE 556 166
|
||||
FL 510 331
|
||||
GA 478 267
|
||||
HI 232 380
|
||||
ID 143 101
|
||||
IL 405 168
|
||||
IN 437 165
|
||||
IA 357 147
|
||||
KS 302 194
|
||||
KY 453 203
|
||||
LA 371 302
|
||||
ME 595 59
|
||||
MD 538 162
|
||||
MA 581 108
|
||||
MI 446 120
|
||||
MN 339 86
|
||||
MS 406 274
|
||||
MO 365 197
|
||||
MT 194 61
|
||||
NE 286 151
|
||||
NV 102 157
|
||||
NH 580 89
|
||||
NJ 561 143
|
||||
NM 208 245
|
||||
NY 541 107
|
||||
NC 519 221
|
||||
ND 283 65
|
||||
OH 472 160
|
||||
OK 309 239
|
||||
OR 74 86
|
||||
PA 523 144
|
||||
RI 589 117
|
||||
SC 506 251
|
||||
SD 286 109
|
||||
TN 441 229
|
||||
TX 291 299
|
||||
UT 154 171
|
||||
VT 567 86
|
||||
VA 529 189
|
||||
WA 92 38
|
||||
WV 496 178
|
||||
WI 392 103
|
||||
WY 207 125
|
||||
|
@@ -0,0 +1,50 @@
|
||||
AL 0.1
|
||||
AK -5.3
|
||||
AZ 3
|
||||
AR 7
|
||||
CA 11
|
||||
CO 1.5
|
||||
CT -6.7
|
||||
DE -4
|
||||
FL 9
|
||||
GA 2
|
||||
HI -3.3
|
||||
ID 6.6
|
||||
IL 7.2
|
||||
IN 7.1
|
||||
IA 6.9
|
||||
KS 6
|
||||
KY 1.8
|
||||
LA 7.5
|
||||
ME -4
|
||||
MD 0.1
|
||||
MA -6
|
||||
MI 1.7
|
||||
MN -2
|
||||
MS -4.4
|
||||
MO -2
|
||||
MT 1.0
|
||||
NE 1.2
|
||||
NV 1.6
|
||||
NH 0.5
|
||||
NJ 0.2
|
||||
NM 8.8
|
||||
NY 1.4
|
||||
NC 9.7
|
||||
ND 5.4
|
||||
OH 3.2
|
||||
OK 6
|
||||
OR -4
|
||||
PA -7
|
||||
RI -2
|
||||
SC 1
|
||||
SD 6
|
||||
TN 5
|
||||
TX -3.4
|
||||
UT 2.3
|
||||
VT 4.8
|
||||
VA 3
|
||||
WA 2.2
|
||||
WV 5.4
|
||||
WI 3.1
|
||||
WY -6
|
||||
|
@@ -0,0 +1,54 @@
|
||||
PImage mapImage;
|
||||
Table locationTable;
|
||||
int rowCount;
|
||||
|
||||
Table dataTable;
|
||||
float dataMin = MAX_FLOAT;
|
||||
float dataMax = MIN_FLOAT;
|
||||
|
||||
|
||||
void setup() {
|
||||
size(640, 400);
|
||||
mapImage = loadImage("map.png");
|
||||
locationTable = new Table("locations.tsv");
|
||||
rowCount = locationTable.getRowCount();
|
||||
|
||||
// Read the data table
|
||||
dataTable = new Table("random.tsv");
|
||||
|
||||
// Find the minimum and maximum values
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
float value = dataTable.getFloat(row, 1);
|
||||
if (value > dataMax) {
|
||||
dataMax = value;
|
||||
}
|
||||
if (value < dataMin) {
|
||||
dataMin = value;
|
||||
}
|
||||
}
|
||||
|
||||
smooth();
|
||||
noStroke();
|
||||
}
|
||||
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
image(mapImage, 0, 0);
|
||||
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
String abbrev = dataTable.getRowName(row);
|
||||
float x = locationTable.getFloat(abbrev, 1);
|
||||
float y = locationTable.getFloat(abbrev, 2);
|
||||
drawData(x, y, abbrev);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void drawData(float x, float y, String abbrev) {
|
||||
float value = dataTable.getFloat(abbrev, 1);
|
||||
float percent = norm(value, dataMin, dataMax);
|
||||
color between = lerpColor(#296F34, #61E2F0, percent, HSB);
|
||||
fill(between);
|
||||
ellipse(x, y, 15, 15);
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
class Table {
|
||||
int rowCount;
|
||||
String[][] data;
|
||||
|
||||
|
||||
Table(String filename) {
|
||||
String[] rows = loadStrings(filename);
|
||||
data = new String[rows.length][];
|
||||
|
||||
for (int i = 0; i < rows.length; i++) {
|
||||
if (trim(rows[i]).length() == 0) {
|
||||
continue; // skip empty rows
|
||||
}
|
||||
if (rows[i].startsWith("#")) {
|
||||
continue; // skip comment lines
|
||||
}
|
||||
|
||||
// split the row on the tabs
|
||||
String[] pieces = split(rows[i], TAB);
|
||||
// copy to the table array
|
||||
data[rowCount] = pieces;
|
||||
rowCount++;
|
||||
|
||||
// this could be done in one fell swoop via:
|
||||
//data[rowCount++] = split(rows[i], TAB);
|
||||
}
|
||||
// resize the 'data' array as necessary
|
||||
data = (String[][]) subset(data, 0, rowCount);
|
||||
}
|
||||
|
||||
|
||||
int getRowCount() {
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
|
||||
// find a row by its name, returns -1 if no row found
|
||||
int getRowIndex(String name) {
|
||||
for (int i = 0; i < rowCount; i++) {
|
||||
if (data[i][0].equals(name)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
println("No row named '" + name + "' was found");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
String getRowName(int row) {
|
||||
return getString(row, 0);
|
||||
}
|
||||
|
||||
|
||||
String getString(int rowIndex, int column) {
|
||||
return data[rowIndex][column];
|
||||
}
|
||||
|
||||
|
||||
String getString(String rowName, int column) {
|
||||
return getString(getRowIndex(rowName), column);
|
||||
}
|
||||
|
||||
|
||||
int getInt(String rowName, int column) {
|
||||
return parseInt(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
int getInt(int rowIndex, int column) {
|
||||
return parseInt(getString(rowIndex, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(String rowName, int column) {
|
||||
return parseFloat(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(int rowIndex, int column) {
|
||||
return parseFloat(getString(rowIndex, column));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
AL 439 270
|
||||
AK 94 325
|
||||
AZ 148 241
|
||||
AR 368 247
|
||||
CA 56 176
|
||||
CO 220 183
|
||||
CT 576 120
|
||||
DE 556 166
|
||||
FL 510 331
|
||||
GA 478 267
|
||||
HI 232 380
|
||||
ID 143 101
|
||||
IL 405 168
|
||||
IN 437 165
|
||||
IA 357 147
|
||||
KS 302 194
|
||||
KY 453 203
|
||||
LA 371 302
|
||||
ME 595 59
|
||||
MD 538 162
|
||||
MA 581 108
|
||||
MI 446 120
|
||||
MN 339 86
|
||||
MS 406 274
|
||||
MO 365 197
|
||||
MT 194 61
|
||||
NE 286 151
|
||||
NV 102 157
|
||||
NH 580 89
|
||||
NJ 561 143
|
||||
NM 208 245
|
||||
NY 541 107
|
||||
NC 519 221
|
||||
ND 283 65
|
||||
OH 472 160
|
||||
OK 309 239
|
||||
OR 74 86
|
||||
PA 523 144
|
||||
RI 589 117
|
||||
SC 506 251
|
||||
SD 286 109
|
||||
TN 441 229
|
||||
TX 291 299
|
||||
UT 154 171
|
||||
VT 567 86
|
||||
VA 529 189
|
||||
WA 92 38
|
||||
WV 496 178
|
||||
WI 392 103
|
||||
WY 207 125
|
||||
|
@@ -0,0 +1,50 @@
|
||||
AL 0.1
|
||||
AK -5.3
|
||||
AZ 3
|
||||
AR 7
|
||||
CA 11
|
||||
CO 1.5
|
||||
CT -6.7
|
||||
DE -4
|
||||
FL 9
|
||||
GA 2
|
||||
HI -3.3
|
||||
ID 6.6
|
||||
IL 7.2
|
||||
IN 7.1
|
||||
IA 6.9
|
||||
KS 6
|
||||
KY 1.8
|
||||
LA 7.5
|
||||
ME -4
|
||||
MD 0.1
|
||||
MA -6
|
||||
MI 1.7
|
||||
MN -2
|
||||
MS -4.4
|
||||
MO -2
|
||||
MT 1.0
|
||||
NE 1.2
|
||||
NV 1.6
|
||||
NH 0.5
|
||||
NJ 0.2
|
||||
NM 8.8
|
||||
NY 1.4
|
||||
NC 9.7
|
||||
ND 5.4
|
||||
OH 3.2
|
||||
OK 6
|
||||
OR -4
|
||||
PA -7
|
||||
RI -2
|
||||
SC 1
|
||||
SD 6
|
||||
TN 5
|
||||
TX -3.4
|
||||
UT 2.3
|
||||
VT 4.8
|
||||
VA 3
|
||||
WA 2.2
|
||||
WV 5.4
|
||||
WI 3.1
|
||||
WY -6
|
||||
|
@@ -0,0 +1,59 @@
|
||||
PImage mapImage;
|
||||
Table locationTable;
|
||||
int rowCount;
|
||||
|
||||
Table dataTable;
|
||||
float dataMin = MAX_FLOAT;
|
||||
float dataMax = MIN_FLOAT;
|
||||
|
||||
|
||||
void setup() {
|
||||
size(640, 400);
|
||||
mapImage = loadImage("map.png");
|
||||
locationTable = new Table("locations.tsv");
|
||||
rowCount = locationTable.getRowCount();
|
||||
|
||||
// Read the data table
|
||||
dataTable = new Table("random.tsv");
|
||||
|
||||
// Find the minimum and maximum values
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
float value = dataTable.getFloat(row, 1);
|
||||
if (value > dataMax) {
|
||||
dataMax = value;
|
||||
}
|
||||
if (value < dataMin) {
|
||||
dataMin = value;
|
||||
}
|
||||
}
|
||||
|
||||
smooth();
|
||||
noStroke();
|
||||
}
|
||||
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
image(mapImage, 0, 0);
|
||||
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
String abbrev = dataTable.getRowName(row);
|
||||
float x = locationTable.getFloat(abbrev, 1);
|
||||
float y = locationTable.getFloat(abbrev, 2);
|
||||
drawData(x, y, abbrev);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void drawData(float x, float y, String abbrev) {
|
||||
float value = dataTable.getFloat(abbrev, 1);
|
||||
float diameter = 0;
|
||||
if (value >= 0) {
|
||||
diameter = map(value, 0, dataMax, 3, 30);
|
||||
fill(#333366); // blue
|
||||
} else {
|
||||
diameter = map(value, 0, dataMin, 3, 30);
|
||||
fill(#ec5166); // red
|
||||
}
|
||||
ellipse(x, y, diameter, diameter);
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
class Table {
|
||||
int rowCount;
|
||||
String[][] data;
|
||||
|
||||
|
||||
Table(String filename) {
|
||||
String[] rows = loadStrings(filename);
|
||||
data = new String[rows.length][];
|
||||
|
||||
for (int i = 0; i < rows.length; i++) {
|
||||
if (trim(rows[i]).length() == 0) {
|
||||
continue; // skip empty rows
|
||||
}
|
||||
if (rows[i].startsWith("#")) {
|
||||
continue; // skip comment lines
|
||||
}
|
||||
|
||||
// split the row on the tabs
|
||||
String[] pieces = split(rows[i], TAB);
|
||||
// copy to the table array
|
||||
data[rowCount] = pieces;
|
||||
rowCount++;
|
||||
|
||||
// this could be done in one fell swoop via:
|
||||
//data[rowCount++] = split(rows[i], TAB);
|
||||
}
|
||||
// resize the 'data' array as necessary
|
||||
data = (String[][]) subset(data, 0, rowCount);
|
||||
}
|
||||
|
||||
|
||||
int getRowCount() {
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
|
||||
// find a row by its name, returns -1 if no row found
|
||||
int getRowIndex(String name) {
|
||||
for (int i = 0; i < rowCount; i++) {
|
||||
if (data[i][0].equals(name)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
println("No row named '" + name + "' was found");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
String getRowName(int row) {
|
||||
return getString(row, 0);
|
||||
}
|
||||
|
||||
|
||||
String getString(int rowIndex, int column) {
|
||||
return data[rowIndex][column];
|
||||
}
|
||||
|
||||
|
||||
String getString(String rowName, int column) {
|
||||
return getString(getRowIndex(rowName), column);
|
||||
}
|
||||
|
||||
|
||||
int getInt(String rowName, int column) {
|
||||
return parseInt(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
int getInt(int rowIndex, int column) {
|
||||
return parseInt(getString(rowIndex, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(String rowName, int column) {
|
||||
return parseFloat(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(int rowIndex, int column) {
|
||||
return parseFloat(getString(rowIndex, column));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
AL 439 270
|
||||
AK 94 325
|
||||
AZ 148 241
|
||||
AR 368 247
|
||||
CA 56 176
|
||||
CO 220 183
|
||||
CT 576 120
|
||||
DE 556 166
|
||||
FL 510 331
|
||||
GA 478 267
|
||||
HI 232 380
|
||||
ID 143 101
|
||||
IL 405 168
|
||||
IN 437 165
|
||||
IA 357 147
|
||||
KS 302 194
|
||||
KY 453 203
|
||||
LA 371 302
|
||||
ME 595 59
|
||||
MD 538 162
|
||||
MA 581 108
|
||||
MI 446 120
|
||||
MN 339 86
|
||||
MS 406 274
|
||||
MO 365 197
|
||||
MT 194 61
|
||||
NE 286 151
|
||||
NV 102 157
|
||||
NH 580 89
|
||||
NJ 561 143
|
||||
NM 208 245
|
||||
NY 541 107
|
||||
NC 519 221
|
||||
ND 283 65
|
||||
OH 472 160
|
||||
OK 309 239
|
||||
OR 74 86
|
||||
PA 523 144
|
||||
RI 589 117
|
||||
SC 506 251
|
||||
SD 286 109
|
||||
TN 441 229
|
||||
TX 291 299
|
||||
UT 154 171
|
||||
VT 567 86
|
||||
VA 529 189
|
||||
WA 92 38
|
||||
WV 496 178
|
||||
WI 392 103
|
||||
WY 207 125
|
||||
|
@@ -0,0 +1,50 @@
|
||||
AL 0.1
|
||||
AK -5.3
|
||||
AZ 3
|
||||
AR 7
|
||||
CA 11
|
||||
CO 1.5
|
||||
CT -6.7
|
||||
DE -4
|
||||
FL 9
|
||||
GA 2
|
||||
HI -3.3
|
||||
ID 6.6
|
||||
IL 7.2
|
||||
IN 7.1
|
||||
IA 6.9
|
||||
KS 6
|
||||
KY 1.8
|
||||
LA 7.5
|
||||
ME -4
|
||||
MD 0.1
|
||||
MA -6
|
||||
MI 1.7
|
||||
MN -2
|
||||
MS -4.4
|
||||
MO -2
|
||||
MT 1.0
|
||||
NE 1.2
|
||||
NV 1.6
|
||||
NH 0.5
|
||||
NJ 0.2
|
||||
NM 8.8
|
||||
NY 1.4
|
||||
NC 9.7
|
||||
ND 5.4
|
||||
OH 3.2
|
||||
OK 6
|
||||
OR -4
|
||||
PA -7
|
||||
RI -2
|
||||
SC 1
|
||||
SD 6
|
||||
TN 5
|
||||
TX -3.4
|
||||
UT 2.3
|
||||
VT 4.8
|
||||
VA 3
|
||||
WA 2.2
|
||||
WV 5.4
|
||||
WI 3.1
|
||||
WY -6
|
||||
|
@@ -0,0 +1,58 @@
|
||||
PImage mapImage;
|
||||
Table locationTable;
|
||||
int rowCount;
|
||||
|
||||
Table dataTable;
|
||||
float dataMin = MAX_FLOAT;
|
||||
float dataMax = MIN_FLOAT;
|
||||
|
||||
|
||||
void setup() {
|
||||
size(640, 400);
|
||||
mapImage = loadImage("map.png");
|
||||
locationTable = new Table("locations.tsv");
|
||||
rowCount = locationTable.getRowCount();
|
||||
|
||||
// Read the data table
|
||||
dataTable = new Table("random.tsv");
|
||||
|
||||
// Find the minimum and maximum values
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
float value = dataTable.getFloat(row, 1);
|
||||
if (value > dataMax) {
|
||||
dataMax = value;
|
||||
}
|
||||
if (value < dataMin) {
|
||||
dataMin = value;
|
||||
}
|
||||
}
|
||||
|
||||
smooth();
|
||||
noStroke();
|
||||
}
|
||||
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
image(mapImage, 0, 0);
|
||||
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
String abbrev = dataTable.getRowName(row);
|
||||
float x = locationTable.getFloat(abbrev, 1);
|
||||
float y = locationTable.getFloat(abbrev, 2);
|
||||
drawData(x, y, abbrev);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void drawData(float x, float y, String abbrev) {
|
||||
float value = dataTable.getFloat(abbrev, 1);
|
||||
if (value >= 0) {
|
||||
float a = map(value, 0, dataMax, 0, 255);
|
||||
fill(#333366, a);
|
||||
} else {
|
||||
float a = map(value, 0, dataMin, 0, 255);
|
||||
fill(#EC5166, a);
|
||||
}
|
||||
ellipse(x, y, 15, 15);
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
class Table {
|
||||
int rowCount;
|
||||
String[][] data;
|
||||
|
||||
|
||||
Table(String filename) {
|
||||
String[] rows = loadStrings(filename);
|
||||
data = new String[rows.length][];
|
||||
|
||||
for (int i = 0; i < rows.length; i++) {
|
||||
if (trim(rows[i]).length() == 0) {
|
||||
continue; // skip empty rows
|
||||
}
|
||||
if (rows[i].startsWith("#")) {
|
||||
continue; // skip comment lines
|
||||
}
|
||||
|
||||
// split the row on the tabs
|
||||
String[] pieces = split(rows[i], TAB);
|
||||
// copy to the table array
|
||||
data[rowCount] = pieces;
|
||||
rowCount++;
|
||||
|
||||
// this could be done in one fell swoop via:
|
||||
//data[rowCount++] = split(rows[i], TAB);
|
||||
}
|
||||
// resize the 'data' array as necessary
|
||||
data = (String[][]) subset(data, 0, rowCount);
|
||||
}
|
||||
|
||||
|
||||
int getRowCount() {
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
|
||||
// find a row by its name, returns -1 if no row found
|
||||
int getRowIndex(String name) {
|
||||
for (int i = 0; i < rowCount; i++) {
|
||||
if (data[i][0].equals(name)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
println("No row named '" + name + "' was found");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
String getRowName(int row) {
|
||||
return getString(row, 0);
|
||||
}
|
||||
|
||||
|
||||
String getString(int rowIndex, int column) {
|
||||
return data[rowIndex][column];
|
||||
}
|
||||
|
||||
|
||||
String getString(String rowName, int column) {
|
||||
return getString(getRowIndex(rowName), column);
|
||||
}
|
||||
|
||||
|
||||
int getInt(String rowName, int column) {
|
||||
return parseInt(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
int getInt(int rowIndex, int column) {
|
||||
return parseInt(getString(rowIndex, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(String rowName, int column) {
|
||||
return parseFloat(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(int rowIndex, int column) {
|
||||
return parseFloat(getString(rowIndex, column));
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,50 @@
|
||||
AL 439 270
|
||||
AK 94 325
|
||||
AZ 148 241
|
||||
AR 368 247
|
||||
CA 56 176
|
||||
CO 220 183
|
||||
CT 576 120
|
||||
DE 556 166
|
||||
FL 510 331
|
||||
GA 478 267
|
||||
HI 232 380
|
||||
ID 143 101
|
||||
IL 405 168
|
||||
IN 437 165
|
||||
IA 357 147
|
||||
KS 302 194
|
||||
KY 453 203
|
||||
LA 371 302
|
||||
ME 595 59
|
||||
MD 538 162
|
||||
MA 581 108
|
||||
MI 446 120
|
||||
MN 339 86
|
||||
MS 406 274
|
||||
MO 365 197
|
||||
MT 194 61
|
||||
NE 286 151
|
||||
NV 102 157
|
||||
NH 580 89
|
||||
NJ 561 143
|
||||
NM 208 245
|
||||
NY 541 107
|
||||
NC 519 221
|
||||
ND 283 65
|
||||
OH 472 160
|
||||
OK 309 239
|
||||
OR 74 86
|
||||
PA 523 144
|
||||
RI 589 117
|
||||
SC 506 251
|
||||
SD 286 109
|
||||
TN 441 229
|
||||
TX 291 299
|
||||
UT 154 171
|
||||
VT 567 86
|
||||
VA 529 189
|
||||
WA 92 38
|
||||
WV 496 178
|
||||
WI 392 103
|
||||
WY 207 125
|
||||
|
@@ -0,0 +1,50 @@
|
||||
AL 0.1
|
||||
AK -5.3
|
||||
AZ 3
|
||||
AR 7
|
||||
CA 11
|
||||
CO 1.5
|
||||
CT -6.7
|
||||
DE -4
|
||||
FL 9
|
||||
GA 2
|
||||
HI -3.3
|
||||
ID 6.6
|
||||
IL 7.2
|
||||
IN 7.1
|
||||
IA 6.9
|
||||
KS 6
|
||||
KY 1.8
|
||||
LA 7.5
|
||||
ME -4
|
||||
MD 0.1
|
||||
MA -6
|
||||
MI 1.7
|
||||
MN -2
|
||||
MS -4.4
|
||||
MO -2
|
||||
MT 1.0
|
||||
NE 1.2
|
||||
NV 1.6
|
||||
NH 0.5
|
||||
NJ 0.2
|
||||
NM 8.8
|
||||
NY 1.4
|
||||
NC 9.7
|
||||
ND 5.4
|
||||
OH 3.2
|
||||
OK 6
|
||||
OR -4
|
||||
PA -7
|
||||
RI -2
|
||||
SC 1
|
||||
SD 6
|
||||
TN 5
|
||||
TX -3.4
|
||||
UT 2.3
|
||||
VT 4.8
|
||||
VA 3
|
||||
WA 2.2
|
||||
WV 5.4
|
||||
WI 3.1
|
||||
WY -6
|
||||
|
@@ -0,0 +1,70 @@
|
||||
PImage mapImage;
|
||||
Table locationTable;
|
||||
int rowCount;
|
||||
|
||||
Table dataTable;
|
||||
float dataMin = MAX_FLOAT;
|
||||
float dataMax = MIN_FLOAT;
|
||||
|
||||
|
||||
void setup() {
|
||||
size(640, 400);
|
||||
mapImage = loadImage("map.png");
|
||||
locationTable = new Table("locations.tsv");
|
||||
rowCount = locationTable.getRowCount();
|
||||
|
||||
// Read the data table
|
||||
dataTable = new Table("random.tsv");
|
||||
|
||||
// Find the minimum and maximum values
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
float value = dataTable.getFloat(row, 1);
|
||||
if (value > dataMax) {
|
||||
dataMax = value;
|
||||
}
|
||||
if (value < dataMin) {
|
||||
dataMin = value;
|
||||
}
|
||||
}
|
||||
|
||||
PFont font = loadFont("Univers-Bold-12.vlw");
|
||||
textFont(font);
|
||||
|
||||
smooth();
|
||||
noStroke();
|
||||
}
|
||||
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
image(mapImage, 0, 0);
|
||||
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
String abbrev = dataTable.getRowName(row);
|
||||
float x = locationTable.getFloat(abbrev, 1);
|
||||
float y = locationTable.getFloat(abbrev, 2);
|
||||
drawData(x, y, abbrev);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void drawData(float x, float y, String abbrev) {
|
||||
float value = dataTable.getFloat(abbrev, 1);
|
||||
float radius = 0;
|
||||
if (value >= 0) {
|
||||
radius = map(value, 0, dataMax, 1.5, 15);
|
||||
fill(#333366); // blue
|
||||
} else {
|
||||
radius = map(value, 0, dataMin, 1.5, 15);
|
||||
fill(#ec5166); // red
|
||||
}
|
||||
ellipseMode(RADIUS);
|
||||
ellipse(x, y, radius, radius);
|
||||
|
||||
if (dist(x, y, mouseX, mouseY) < radius+2) {
|
||||
fill(0);
|
||||
textAlign(CENTER);
|
||||
// Show the data value and the state abbreviation in parentheses
|
||||
text(value + " (" + abbrev + ")", x, y-radius-4);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
class Table {
|
||||
int rowCount;
|
||||
String[][] data;
|
||||
|
||||
|
||||
Table(String filename) {
|
||||
String[] rows = loadStrings(filename);
|
||||
data = new String[rows.length][];
|
||||
|
||||
for (int i = 0; i < rows.length; i++) {
|
||||
if (trim(rows[i]).length() == 0) {
|
||||
continue; // skip empty rows
|
||||
}
|
||||
if (rows[i].startsWith("#")) {
|
||||
continue; // skip comment lines
|
||||
}
|
||||
|
||||
// split the row on the tabs
|
||||
String[] pieces = split(rows[i], TAB);
|
||||
// copy to the table array
|
||||
data[rowCount] = pieces;
|
||||
rowCount++;
|
||||
|
||||
// this could be done in one fell swoop via:
|
||||
//data[rowCount++] = split(rows[i], TAB);
|
||||
}
|
||||
// resize the 'data' array as necessary
|
||||
data = (String[][]) subset(data, 0, rowCount);
|
||||
}
|
||||
|
||||
|
||||
int getRowCount() {
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
|
||||
// find a row by its name, returns -1 if no row found
|
||||
int getRowIndex(String name) {
|
||||
for (int i = 0; i < rowCount; i++) {
|
||||
if (data[i][0].equals(name)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
println("No row named '" + name + "' was found");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
String getRowName(int row) {
|
||||
return getString(row, 0);
|
||||
}
|
||||
|
||||
|
||||
String getString(int rowIndex, int column) {
|
||||
return data[rowIndex][column];
|
||||
}
|
||||
|
||||
|
||||
String getString(String rowName, int column) {
|
||||
return getString(getRowIndex(rowName), column);
|
||||
}
|
||||
|
||||
|
||||
int getInt(String rowName, int column) {
|
||||
return parseInt(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
int getInt(int rowIndex, int column) {
|
||||
return parseInt(getString(rowIndex, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(String rowName, int column) {
|
||||
return parseFloat(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(int rowIndex, int column) {
|
||||
return parseFloat(getString(rowIndex, column));
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,50 @@
|
||||
AL 439 270
|
||||
AK 94 325
|
||||
AZ 148 241
|
||||
AR 368 247
|
||||
CA 56 176
|
||||
CO 220 183
|
||||
CT 576 120
|
||||
DE 556 166
|
||||
FL 510 331
|
||||
GA 478 267
|
||||
HI 232 380
|
||||
ID 143 101
|
||||
IL 405 168
|
||||
IN 437 165
|
||||
IA 357 147
|
||||
KS 302 194
|
||||
KY 453 203
|
||||
LA 371 302
|
||||
ME 595 59
|
||||
MD 538 162
|
||||
MA 581 108
|
||||
MI 446 120
|
||||
MN 339 86
|
||||
MS 406 274
|
||||
MO 365 197
|
||||
MT 194 61
|
||||
NE 286 151
|
||||
NV 102 157
|
||||
NH 580 89
|
||||
NJ 561 143
|
||||
NM 208 245
|
||||
NY 541 107
|
||||
NC 519 221
|
||||
ND 283 65
|
||||
OH 472 160
|
||||
OK 309 239
|
||||
OR 74 86
|
||||
PA 523 144
|
||||
RI 589 117
|
||||
SC 506 251
|
||||
SD 286 109
|
||||
TN 441 229
|
||||
TX 291 299
|
||||
UT 154 171
|
||||
VT 567 86
|
||||
VA 529 189
|
||||
WA 92 38
|
||||
WV 496 178
|
||||
WI 392 103
|
||||
WY 207 125
|
||||
|
@@ -0,0 +1,50 @@
|
||||
AL Alabama
|
||||
AK Alaska
|
||||
AZ Arizona
|
||||
AR Arkansas
|
||||
CA California
|
||||
CO Colorado
|
||||
CT Connecticut
|
||||
DE Delaware
|
||||
FL Florida
|
||||
GA Georgia
|
||||
HI Hawaii
|
||||
ID Idaho
|
||||
IL Illinois
|
||||
IN Indiana
|
||||
IA Iowa
|
||||
KS Kansas
|
||||
KY Kentucky
|
||||
LA Louisiana
|
||||
ME Maine
|
||||
MD Maryland
|
||||
MA Massachusetts
|
||||
MI Michigan
|
||||
MN Minnesota
|
||||
MS Mississippi
|
||||
MO Missouri
|
||||
MT Montana
|
||||
NE Nebraska
|
||||
NV Nevada
|
||||
NH New Hampshire
|
||||
NJ New Jersey
|
||||
NM New Mexico
|
||||
NY New York
|
||||
NC North Carolina
|
||||
ND North Dakota
|
||||
OH Ohio
|
||||
OK Oklahoma
|
||||
OR Oregon
|
||||
PA Pennsylvania
|
||||
RI Rhode Island
|
||||
SC South Carolina
|
||||
SD South Dakota
|
||||
TN Tennessee
|
||||
TX Texas
|
||||
UT Utah
|
||||
VT Vermont
|
||||
VA Virginia
|
||||
WA Washington
|
||||
WV West Virginia
|
||||
WI Wisconsin
|
||||
WY Wyoming
|
||||
|
@@ -0,0 +1,50 @@
|
||||
AL 0.1
|
||||
AK -5.3
|
||||
AZ 3
|
||||
AR 7
|
||||
CA 11
|
||||
CO 1.5
|
||||
CT -6.7
|
||||
DE -4
|
||||
FL 9
|
||||
GA 2
|
||||
HI -3.3
|
||||
ID 6.6
|
||||
IL 7.2
|
||||
IN 7.1
|
||||
IA 6.9
|
||||
KS 6
|
||||
KY 1.8
|
||||
LA 7.5
|
||||
ME -4
|
||||
MD 0.1
|
||||
MA -6
|
||||
MI 1.7
|
||||
MN -2
|
||||
MS -4.4
|
||||
MO -2
|
||||
MT 1.0
|
||||
NE 1.2
|
||||
NV 1.6
|
||||
NH 0.5
|
||||
NJ 0.2
|
||||
NM 8.8
|
||||
NY 1.4
|
||||
NC 9.7
|
||||
ND 5.4
|
||||
OH 3.2
|
||||
OK 6
|
||||
OR -4
|
||||
PA -7
|
||||
RI -2
|
||||
SC 1
|
||||
SD 6
|
||||
TN 5
|
||||
TX -3.4
|
||||
UT 2.3
|
||||
VT 4.8
|
||||
VA 3
|
||||
WA 2.2
|
||||
WV 5.4
|
||||
WI 3.1
|
||||
WY -6
|
||||
|
@@ -0,0 +1,70 @@
|
||||
PImage mapImage;
|
||||
Table locationTable;
|
||||
Table nameTable;
|
||||
int rowCount;
|
||||
|
||||
Table dataTable;
|
||||
float dataMin = MAX_FLOAT;
|
||||
float dataMax = MIN_FLOAT;
|
||||
|
||||
|
||||
void setup() {
|
||||
size(640, 400);
|
||||
mapImage = loadImage("map.png");
|
||||
locationTable = new Table("locations.tsv");
|
||||
nameTable = new Table("names.tsv");
|
||||
rowCount = locationTable.getRowCount();
|
||||
|
||||
dataTable = new Table("random.tsv");
|
||||
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
float value = dataTable.getFloat(row, 1);
|
||||
if (value > dataMax) {
|
||||
dataMax = value;
|
||||
}
|
||||
if (value < dataMin) {
|
||||
dataMin = value;
|
||||
}
|
||||
}
|
||||
|
||||
PFont font = loadFont("Univers-Bold-12.vlw");
|
||||
textFont(font);
|
||||
|
||||
smooth();
|
||||
noStroke();
|
||||
}
|
||||
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
image(mapImage, 0, 0);
|
||||
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
String abbrev = dataTable.getRowName(row);
|
||||
float x = locationTable.getFloat(abbrev, 1);
|
||||
float y = locationTable.getFloat(abbrev, 2);
|
||||
drawData(x, y, abbrev);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void drawData(float x, float y, String abbrev) {
|
||||
float value = dataTable.getFloat(abbrev, 1);
|
||||
float radius = 0;
|
||||
if (value >= 0) {
|
||||
radius = map(value, 0, dataMax, 1.5, 15);
|
||||
fill(#333366); // blue
|
||||
} else {
|
||||
radius = map(value, 0, dataMin, 1.5, 15);
|
||||
fill(#ec5166); // red
|
||||
}
|
||||
ellipseMode(RADIUS);
|
||||
ellipse(x, y, radius, radius);
|
||||
|
||||
if (dist(x, y, mouseX, mouseY) < radius+2) {
|
||||
fill(0);
|
||||
textAlign(CENTER);
|
||||
String name = nameTable.getString(abbrev, 1);
|
||||
text(name + " " + value, x, y-radius-4);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
class Table {
|
||||
int rowCount;
|
||||
String[][] data;
|
||||
|
||||
|
||||
Table(String filename) {
|
||||
String[] rows = loadStrings(filename);
|
||||
data = new String[rows.length][];
|
||||
|
||||
for (int i = 0; i < rows.length; i++) {
|
||||
if (trim(rows[i]).length() == 0) {
|
||||
continue; // skip empty rows
|
||||
}
|
||||
if (rows[i].startsWith("#")) {
|
||||
continue; // skip comment lines
|
||||
}
|
||||
|
||||
// split the row on the tabs
|
||||
String[] pieces = split(rows[i], TAB);
|
||||
// copy to the table array
|
||||
data[rowCount] = pieces;
|
||||
rowCount++;
|
||||
|
||||
// this could be done in one fell swoop via:
|
||||
//data[rowCount++] = split(rows[i], TAB);
|
||||
}
|
||||
// resize the 'data' array as necessary
|
||||
data = (String[][]) subset(data, 0, rowCount);
|
||||
}
|
||||
|
||||
|
||||
int getRowCount() {
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
|
||||
// find a row by its name, returns -1 if no row found
|
||||
int getRowIndex(String name) {
|
||||
for (int i = 0; i < rowCount; i++) {
|
||||
if (data[i][0].equals(name)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
println("No row named '" + name + "' was found");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
String getRowName(int row) {
|
||||
return getString(row, 0);
|
||||
}
|
||||
|
||||
|
||||
String getString(int rowIndex, int column) {
|
||||
return data[rowIndex][column];
|
||||
}
|
||||
|
||||
|
||||
String getString(String rowName, int column) {
|
||||
return getString(getRowIndex(rowName), column);
|
||||
}
|
||||
|
||||
|
||||
int getInt(String rowName, int column) {
|
||||
return parseInt(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
int getInt(int rowIndex, int column) {
|
||||
return parseInt(getString(rowIndex, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(String rowName, int column) {
|
||||
return parseFloat(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(int rowIndex, int column) {
|
||||
return parseFloat(getString(rowIndex, column));
|
||||
}
|
||||
|
||||
|
||||
void setRowName(int row, String what) {
|
||||
data[row][0] = what;
|
||||
}
|
||||
|
||||
|
||||
void setString(int rowIndex, int column, String what) {
|
||||
data[rowIndex][column] = what;
|
||||
}
|
||||
|
||||
|
||||
void setString(String rowName, int column, String what) {
|
||||
int rowIndex = getRowIndex(rowName);
|
||||
data[rowIndex][column] = what;
|
||||
}
|
||||
|
||||
|
||||
void setInt(int rowIndex, int column, int what) {
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
|
||||
|
||||
void setInt(String rowName, int column, int what) {
|
||||
int rowIndex = getRowIndex(rowName);
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
|
||||
|
||||
void setFloat(int rowIndex, int column, float what) {
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
|
||||
|
||||
void setFloat(String rowName, int column, float what) {
|
||||
int rowIndex = getRowIndex(rowName);
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,50 @@
|
||||
AL 439 270
|
||||
AK 94 325
|
||||
AZ 148 241
|
||||
AR 368 247
|
||||
CA 56 176
|
||||
CO 220 183
|
||||
CT 576 120
|
||||
DE 556 166
|
||||
FL 510 331
|
||||
GA 478 267
|
||||
HI 232 380
|
||||
ID 143 101
|
||||
IL 405 168
|
||||
IN 437 165
|
||||
IA 357 147
|
||||
KS 302 194
|
||||
KY 453 203
|
||||
LA 371 302
|
||||
ME 595 59
|
||||
MD 538 162
|
||||
MA 581 108
|
||||
MI 446 120
|
||||
MN 339 86
|
||||
MS 406 274
|
||||
MO 365 197
|
||||
MT 194 61
|
||||
NE 286 151
|
||||
NV 102 157
|
||||
NH 580 89
|
||||
NJ 561 143
|
||||
NM 208 245
|
||||
NY 541 107
|
||||
NC 519 221
|
||||
ND 283 65
|
||||
OH 472 160
|
||||
OK 309 239
|
||||
OR 74 86
|
||||
PA 523 144
|
||||
RI 589 117
|
||||
SC 506 251
|
||||
SD 286 109
|
||||
TN 441 229
|
||||
TX 291 299
|
||||
UT 154 171
|
||||
VT 567 86
|
||||
VA 529 189
|
||||
WA 92 38
|
||||
WV 496 178
|
||||
WI 392 103
|
||||
WY 207 125
|
||||
|
@@ -0,0 +1,50 @@
|
||||
AL Alabama
|
||||
AK Alaska
|
||||
AZ Arizona
|
||||
AR Arkansas
|
||||
CA California
|
||||
CO Colorado
|
||||
CT Connecticut
|
||||
DE Delaware
|
||||
FL Florida
|
||||
GA Georgia
|
||||
HI Hawaii
|
||||
ID Idaho
|
||||
IL Illinois
|
||||
IN Indiana
|
||||
IA Iowa
|
||||
KS Kansas
|
||||
KY Kentucky
|
||||
LA Louisiana
|
||||
ME Maine
|
||||
MD Maryland
|
||||
MA Massachusetts
|
||||
MI Michigan
|
||||
MN Minnesota
|
||||
MS Mississippi
|
||||
MO Missouri
|
||||
MT Montana
|
||||
NE Nebraska
|
||||
NV Nevada
|
||||
NH New Hampshire
|
||||
NJ New Jersey
|
||||
NM New Mexico
|
||||
NY New York
|
||||
NC North Carolina
|
||||
ND North Dakota
|
||||
OH Ohio
|
||||
OK Oklahoma
|
||||
OR Oregon
|
||||
PA Pennsylvania
|
||||
RI Rhode Island
|
||||
SC South Carolina
|
||||
SD South Dakota
|
||||
TN Tennessee
|
||||
TX Texas
|
||||
UT Utah
|
||||
VT Vermont
|
||||
VA Virginia
|
||||
WA Washington
|
||||
WV West Virginia
|
||||
WI Wisconsin
|
||||
WY Wyoming
|
||||
|
@@ -0,0 +1,50 @@
|
||||
AL 0.1
|
||||
AK -5.3
|
||||
AZ 3
|
||||
AR 7
|
||||
CA 11
|
||||
CO 1.5
|
||||
CT -6.7
|
||||
DE -4
|
||||
FL 9
|
||||
GA 2
|
||||
HI -3.3
|
||||
ID 6.6
|
||||
IL 7.2
|
||||
IN 7.1
|
||||
IA 6.9
|
||||
KS 6
|
||||
KY 1.8
|
||||
LA 7.5
|
||||
ME -4
|
||||
MD 0.1
|
||||
MA -6
|
||||
MI 1.7
|
||||
MN -2
|
||||
MS -4.4
|
||||
MO -2
|
||||
MT 1.0
|
||||
NE 1.2
|
||||
NV 1.6
|
||||
NH 0.5
|
||||
NJ 0.2
|
||||
NM 8.8
|
||||
NY 1.4
|
||||
NC 9.7
|
||||
ND 5.4
|
||||
OH 3.2
|
||||
OK 6
|
||||
OR -4
|
||||
PA -7
|
||||
RI -2
|
||||
SC 1
|
||||
SD 6
|
||||
TN 5
|
||||
TX -3.4
|
||||
UT 2.3
|
||||
VT 4.8
|
||||
VA 3
|
||||
WA 2.2
|
||||
WV 5.4
|
||||
WI 3.1
|
||||
WY -6
|
||||
|
@@ -0,0 +1,94 @@
|
||||
PImage mapImage;
|
||||
Table locationTable;
|
||||
Table nameTable;
|
||||
int rowCount;
|
||||
|
||||
Table dataTable;
|
||||
float dataMin = MAX_FLOAT;
|
||||
float dataMax = MIN_FLOAT;
|
||||
|
||||
|
||||
void setup() {
|
||||
size(640, 400);
|
||||
mapImage = loadImage("map.png");
|
||||
locationTable = new Table("locations.tsv");
|
||||
nameTable = new Table("names.tsv");
|
||||
rowCount = locationTable.getRowCount();
|
||||
|
||||
dataTable = new Table("random.tsv");
|
||||
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
float value = dataTable.getFloat(row, 1);
|
||||
if (value > dataMax) {
|
||||
dataMax = value;
|
||||
}
|
||||
if (value < dataMin) {
|
||||
dataMin = value;
|
||||
}
|
||||
}
|
||||
|
||||
PFont font = loadFont("Univers-Bold-12.vlw");
|
||||
textFont(font);
|
||||
|
||||
smooth();
|
||||
noStroke();
|
||||
}
|
||||
|
||||
|
||||
// Global variables set in drawData() and read in draw()
|
||||
float closestDist;
|
||||
String closestText;
|
||||
float closestTextX;
|
||||
float closestTextY;
|
||||
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
image(mapImage, 0, 0);
|
||||
|
||||
// Use the built-in width and height variables to set the
|
||||
// closest distance high so it will be replaced immediately
|
||||
closestDist = width*height;
|
||||
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
String abbrev = dataTable.getRowName(row);
|
||||
float x = locationTable.getFloat(abbrev, 1);
|
||||
float y = locationTable.getFloat(abbrev, 2);
|
||||
drawData(x, y, abbrev);
|
||||
}
|
||||
|
||||
// Use global variables set in drawData()
|
||||
// to draw text related to closest circle.
|
||||
if (closestDist != width*height) {
|
||||
fill(0);
|
||||
textAlign(CENTER);
|
||||
text(closestText, closestTextX, closestTextY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void drawData(float x, float y, String abbrev) {
|
||||
float value = dataTable.getFloat(abbrev, 1);
|
||||
float radius = 0;
|
||||
if (value >= 0) {
|
||||
radius = map(value, 0, dataMax, 1.5, 15);
|
||||
fill(#333366); // blue
|
||||
} else {
|
||||
radius = map(value, 0, dataMin, 1.5, 15);
|
||||
fill(#ec5166); // red
|
||||
}
|
||||
ellipseMode(RADIUS);
|
||||
ellipse(x, y, radius, radius);
|
||||
|
||||
float d = dist(x, y, mouseX, mouseY);
|
||||
// Because the following check is done each time a new
|
||||
// circle is drawn, we end up with the values of the
|
||||
// circle closest to the mouse.
|
||||
if ((d < radius + 2) && (d < closestDist)) {
|
||||
closestDist = d;
|
||||
String name = nameTable.getString(abbrev, 1);
|
||||
closestText = name + " " + value;
|
||||
closestTextX = x;
|
||||
closestTextY = y-radius-4;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
class Table {
|
||||
int rowCount;
|
||||
String[][] data;
|
||||
|
||||
|
||||
Table(String filename) {
|
||||
String[] rows = loadStrings(filename);
|
||||
data = new String[rows.length][];
|
||||
|
||||
for (int i = 0; i < rows.length; i++) {
|
||||
if (trim(rows[i]).length() == 0) {
|
||||
continue; // skip empty rows
|
||||
}
|
||||
if (rows[i].startsWith("#")) {
|
||||
continue; // skip comment lines
|
||||
}
|
||||
|
||||
// split the row on the tabs
|
||||
String[] pieces = split(rows[i], TAB);
|
||||
// copy to the table array
|
||||
data[rowCount] = pieces;
|
||||
rowCount++;
|
||||
|
||||
// this could be done in one fell swoop via:
|
||||
//data[rowCount++] = split(rows[i], TAB);
|
||||
}
|
||||
// resize the 'data' array as necessary
|
||||
data = (String[][]) subset(data, 0, rowCount);
|
||||
}
|
||||
|
||||
|
||||
int getRowCount() {
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
|
||||
// find a row by its name, returns -1 if no row found
|
||||
int getRowIndex(String name) {
|
||||
for (int i = 0; i < rowCount; i++) {
|
||||
if (data[i][0].equals(name)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
println("No row named '" + name + "' was found");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
String getRowName(int row) {
|
||||
return getString(row, 0);
|
||||
}
|
||||
|
||||
|
||||
String getString(int rowIndex, int column) {
|
||||
return data[rowIndex][column];
|
||||
}
|
||||
|
||||
|
||||
String getString(String rowName, int column) {
|
||||
return getString(getRowIndex(rowName), column);
|
||||
}
|
||||
|
||||
|
||||
int getInt(String rowName, int column) {
|
||||
return parseInt(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
int getInt(int rowIndex, int column) {
|
||||
return parseInt(getString(rowIndex, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(String rowName, int column) {
|
||||
return parseFloat(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(int rowIndex, int column) {
|
||||
return parseFloat(getString(rowIndex, column));
|
||||
}
|
||||
|
||||
|
||||
void setRowName(int row, String what) {
|
||||
data[row][0] = what;
|
||||
}
|
||||
|
||||
|
||||
void setString(int rowIndex, int column, String what) {
|
||||
data[rowIndex][column] = what;
|
||||
}
|
||||
|
||||
|
||||
void setString(String rowName, int column, String what) {
|
||||
int rowIndex = getRowIndex(rowName);
|
||||
data[rowIndex][column] = what;
|
||||
}
|
||||
|
||||
|
||||
void setInt(int rowIndex, int column, int what) {
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
|
||||
|
||||
void setInt(String rowName, int column, int what) {
|
||||
int rowIndex = getRowIndex(rowName);
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
|
||||
|
||||
void setFloat(int rowIndex, int column, float what) {
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
|
||||
|
||||
void setFloat(String rowName, int column, float what) {
|
||||
int rowIndex = getRowIndex(rowName);
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,50 @@
|
||||
AL 439 270
|
||||
AK 94 325
|
||||
AZ 148 241
|
||||
AR 368 247
|
||||
CA 56 176
|
||||
CO 220 183
|
||||
CT 576 120
|
||||
DE 556 166
|
||||
FL 510 331
|
||||
GA 478 267
|
||||
HI 232 380
|
||||
ID 143 101
|
||||
IL 405 168
|
||||
IN 437 165
|
||||
IA 357 147
|
||||
KS 302 194
|
||||
KY 453 203
|
||||
LA 371 302
|
||||
ME 595 59
|
||||
MD 538 162
|
||||
MA 581 108
|
||||
MI 446 120
|
||||
MN 339 86
|
||||
MS 406 274
|
||||
MO 365 197
|
||||
MT 194 61
|
||||
NE 286 151
|
||||
NV 102 157
|
||||
NH 580 89
|
||||
NJ 561 143
|
||||
NM 208 245
|
||||
NY 541 107
|
||||
NC 519 221
|
||||
ND 283 65
|
||||
OH 472 160
|
||||
OK 309 239
|
||||
OR 74 86
|
||||
PA 523 144
|
||||
RI 589 117
|
||||
SC 506 251
|
||||
SD 286 109
|
||||
TN 441 229
|
||||
TX 291 299
|
||||
UT 154 171
|
||||
VT 567 86
|
||||
VA 529 189
|
||||
WA 92 38
|
||||
WV 496 178
|
||||
WI 392 103
|
||||
WY 207 125
|
||||
|
@@ -0,0 +1,50 @@
|
||||
AL Alabama
|
||||
AK Alaska
|
||||
AZ Arizona
|
||||
AR Arkansas
|
||||
CA California
|
||||
CO Colorado
|
||||
CT Connecticut
|
||||
DE Delaware
|
||||
FL Florida
|
||||
GA Georgia
|
||||
HI Hawaii
|
||||
ID Idaho
|
||||
IL Illinois
|
||||
IN Indiana
|
||||
IA Iowa
|
||||
KS Kansas
|
||||
KY Kentucky
|
||||
LA Louisiana
|
||||
ME Maine
|
||||
MD Maryland
|
||||
MA Massachusetts
|
||||
MI Michigan
|
||||
MN Minnesota
|
||||
MS Mississippi
|
||||
MO Missouri
|
||||
MT Montana
|
||||
NE Nebraska
|
||||
NV Nevada
|
||||
NH New Hampshire
|
||||
NJ New Jersey
|
||||
NM New Mexico
|
||||
NY New York
|
||||
NC North Carolina
|
||||
ND North Dakota
|
||||
OH Ohio
|
||||
OK Oklahoma
|
||||
OR Oregon
|
||||
PA Pennsylvania
|
||||
RI Rhode Island
|
||||
SC South Carolina
|
||||
SD South Dakota
|
||||
TN Tennessee
|
||||
TX Texas
|
||||
UT Utah
|
||||
VT Vermont
|
||||
VA Virginia
|
||||
WA Washington
|
||||
WV West Virginia
|
||||
WI Wisconsin
|
||||
WY Wyoming
|
||||
|
@@ -0,0 +1,50 @@
|
||||
AL 0.1
|
||||
AK -5.3
|
||||
AZ 3
|
||||
AR 7
|
||||
CA 11
|
||||
CO 1.5
|
||||
CT -6.7
|
||||
DE -4
|
||||
FL 9
|
||||
GA 2
|
||||
HI -3.3
|
||||
ID 6.6
|
||||
IL 7.2
|
||||
IN 7.1
|
||||
IA 6.9
|
||||
KS 6
|
||||
KY 1.8
|
||||
LA 7.5
|
||||
ME -4
|
||||
MD 0.1
|
||||
MA -6
|
||||
MI 1.7
|
||||
MN -2
|
||||
MS -4.4
|
||||
MO -2
|
||||
MT 1.0
|
||||
NE 1.2
|
||||
NV 1.6
|
||||
NH 0.5
|
||||
NJ 0.2
|
||||
NM 8.8
|
||||
NY 1.4
|
||||
NC 9.7
|
||||
ND 5.4
|
||||
OH 3.2
|
||||
OK 6
|
||||
OR -4
|
||||
PA -7
|
||||
RI -2
|
||||
SC 1
|
||||
SD 6
|
||||
TN 5
|
||||
TX -3.4
|
||||
UT 2.3
|
||||
VT 4.8
|
||||
VA 3
|
||||
WA 2.2
|
||||
WV 5.4
|
||||
WI 3.1
|
||||
WY -6
|
||||
|
@@ -0,0 +1,90 @@
|
||||
PImage mapImage;
|
||||
Table locationTable;
|
||||
Table nameTable;
|
||||
int rowCount;
|
||||
|
||||
Table dataTable;
|
||||
float dataMin = -10;
|
||||
float dataMax = 10;
|
||||
|
||||
|
||||
void setup() {
|
||||
size(640, 400);
|
||||
mapImage = loadImage("map.png");
|
||||
locationTable = new Table("locations.tsv");
|
||||
nameTable = new Table("names.tsv");
|
||||
rowCount = locationTable.getRowCount();
|
||||
|
||||
dataTable = new Table("random.tsv");
|
||||
|
||||
PFont font = loadFont("Univers-Bold-12.vlw");
|
||||
textFont(font);
|
||||
|
||||
smooth();
|
||||
noStroke();
|
||||
}
|
||||
|
||||
float closestDist;
|
||||
String closestText;
|
||||
float closestTextX;
|
||||
float closestTextY;
|
||||
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
image(mapImage, 0, 0);
|
||||
|
||||
closestDist = width*height; // abritrarily high
|
||||
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
String abbrev = dataTable.getRowName(row);
|
||||
float x = locationTable.getFloat(abbrev, 1);
|
||||
float y = locationTable.getFloat(abbrev, 2);
|
||||
drawData(x, y, abbrev);
|
||||
}
|
||||
|
||||
if (closestDist != width*height) {
|
||||
fill(0);
|
||||
textAlign(CENTER);
|
||||
text(closestText, closestTextX, closestTextY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void drawData(float x, float y, String abbrev) {
|
||||
float value = dataTable.getFloat(abbrev, 1);
|
||||
float radius = 0;
|
||||
if (value >= 0) {
|
||||
radius = map(value, 0, dataMax, 1.5, 15);
|
||||
fill(#333366); // blue
|
||||
} else {
|
||||
radius = map(value, 0, dataMin, 1.5, 15);
|
||||
fill(#ec5166); // red
|
||||
}
|
||||
ellipseMode(RADIUS);
|
||||
ellipse(x, y, radius, radius);
|
||||
|
||||
float d = dist(x, y, mouseX, mouseY);
|
||||
if ((d < radius + 2) && (d < closestDist)) {
|
||||
closestDist = d;
|
||||
String name = nameTable.getString(abbrev, 1);
|
||||
closestText = name + " " + value;
|
||||
closestTextX = x;
|
||||
closestTextY = y-radius-4;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void keyPressed() {
|
||||
if (key == ' ') {
|
||||
updateTable();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void updateTable() {
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
float newValue = random(-10, 10);
|
||||
dataTable.setFloat(row, 1, newValue);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
class Table {
|
||||
int rowCount;
|
||||
String[][] data;
|
||||
|
||||
|
||||
Table(String filename) {
|
||||
String[] rows = loadStrings(filename);
|
||||
data = new String[rows.length][];
|
||||
|
||||
for (int i = 0; i < rows.length; i++) {
|
||||
if (trim(rows[i]).length() == 0) {
|
||||
continue; // skip empty rows
|
||||
}
|
||||
if (rows[i].startsWith("#")) {
|
||||
continue; // skip comment lines
|
||||
}
|
||||
|
||||
// split the row on the tabs
|
||||
String[] pieces = split(rows[i], TAB);
|
||||
// copy to the table array
|
||||
data[rowCount] = pieces;
|
||||
rowCount++;
|
||||
|
||||
// this could be done in one fell swoop via:
|
||||
//data[rowCount++] = split(rows[i], TAB);
|
||||
}
|
||||
// resize the 'data' array as necessary
|
||||
data = (String[][]) subset(data, 0, rowCount);
|
||||
}
|
||||
|
||||
|
||||
int getRowCount() {
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
|
||||
// find a row by its name, returns -1 if no row found
|
||||
int getRowIndex(String name) {
|
||||
for (int i = 0; i < rowCount; i++) {
|
||||
if (data[i][0].equals(name)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
println("No row named '" + name + "' was found");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
String getRowName(int row) {
|
||||
return getString(row, 0);
|
||||
}
|
||||
|
||||
|
||||
String getString(int rowIndex, int column) {
|
||||
return data[rowIndex][column];
|
||||
}
|
||||
|
||||
|
||||
String getString(String rowName, int column) {
|
||||
return getString(getRowIndex(rowName), column);
|
||||
}
|
||||
|
||||
|
||||
int getInt(String rowName, int column) {
|
||||
return parseInt(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
int getInt(int rowIndex, int column) {
|
||||
return parseInt(getString(rowIndex, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(String rowName, int column) {
|
||||
return parseFloat(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(int rowIndex, int column) {
|
||||
return parseFloat(getString(rowIndex, column));
|
||||
}
|
||||
|
||||
|
||||
void setRowName(int row, String what) {
|
||||
data[row][0] = what;
|
||||
}
|
||||
|
||||
|
||||
void setString(int rowIndex, int column, String what) {
|
||||
data[rowIndex][column] = what;
|
||||
}
|
||||
|
||||
|
||||
void setString(String rowName, int column, String what) {
|
||||
int rowIndex = getRowIndex(rowName);
|
||||
data[rowIndex][column] = what;
|
||||
}
|
||||
|
||||
|
||||
void setInt(int rowIndex, int column, int what) {
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
|
||||
|
||||
void setInt(String rowName, int column, int what) {
|
||||
int rowIndex = getRowIndex(rowName);
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
|
||||
|
||||
void setFloat(int rowIndex, int column, float what) {
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
|
||||
|
||||
void setFloat(String rowName, int column, float what) {
|
||||
int rowIndex = getRowIndex(rowName);
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,50 @@
|
||||
AL 439 270
|
||||
AK 94 325
|
||||
AZ 148 241
|
||||
AR 368 247
|
||||
CA 56 176
|
||||
CO 220 183
|
||||
CT 576 120
|
||||
DE 556 166
|
||||
FL 510 331
|
||||
GA 478 267
|
||||
HI 232 380
|
||||
ID 143 101
|
||||
IL 405 168
|
||||
IN 437 165
|
||||
IA 357 147
|
||||
KS 302 194
|
||||
KY 453 203
|
||||
LA 371 302
|
||||
ME 595 59
|
||||
MD 538 162
|
||||
MA 581 108
|
||||
MI 446 120
|
||||
MN 339 86
|
||||
MS 406 274
|
||||
MO 365 197
|
||||
MT 194 61
|
||||
NE 286 151
|
||||
NV 102 157
|
||||
NH 580 89
|
||||
NJ 561 143
|
||||
NM 208 245
|
||||
NY 541 107
|
||||
NC 519 221
|
||||
ND 283 65
|
||||
OH 472 160
|
||||
OK 309 239
|
||||
OR 74 86
|
||||
PA 523 144
|
||||
RI 589 117
|
||||
SC 506 251
|
||||
SD 286 109
|
||||
TN 441 229
|
||||
TX 291 299
|
||||
UT 154 171
|
||||
VT 567 86
|
||||
VA 529 189
|
||||
WA 92 38
|
||||
WV 496 178
|
||||
WI 392 103
|
||||
WY 207 125
|
||||
|
@@ -0,0 +1,50 @@
|
||||
AL Alabama
|
||||
AK Alaska
|
||||
AZ Arizona
|
||||
AR Arkansas
|
||||
CA California
|
||||
CO Colorado
|
||||
CT Connecticut
|
||||
DE Delaware
|
||||
FL Florida
|
||||
GA Georgia
|
||||
HI Hawaii
|
||||
ID Idaho
|
||||
IL Illinois
|
||||
IN Indiana
|
||||
IA Iowa
|
||||
KS Kansas
|
||||
KY Kentucky
|
||||
LA Louisiana
|
||||
ME Maine
|
||||
MD Maryland
|
||||
MA Massachusetts
|
||||
MI Michigan
|
||||
MN Minnesota
|
||||
MS Mississippi
|
||||
MO Missouri
|
||||
MT Montana
|
||||
NE Nebraska
|
||||
NV Nevada
|
||||
NH New Hampshire
|
||||
NJ New Jersey
|
||||
NM New Mexico
|
||||
NY New York
|
||||
NC North Carolina
|
||||
ND North Dakota
|
||||
OH Ohio
|
||||
OK Oklahoma
|
||||
OR Oregon
|
||||
PA Pennsylvania
|
||||
RI Rhode Island
|
||||
SC South Carolina
|
||||
SD South Dakota
|
||||
TN Tennessee
|
||||
TX Texas
|
||||
UT Utah
|
||||
VT Vermont
|
||||
VA Virginia
|
||||
WA Washington
|
||||
WV West Virginia
|
||||
WI Wisconsin
|
||||
WY Wyoming
|
||||
|
@@ -0,0 +1,50 @@
|
||||
AL 0.1
|
||||
AK -5.3
|
||||
AZ 3
|
||||
AR 7
|
||||
CA 11
|
||||
CO 1.5
|
||||
CT -6.7
|
||||
DE -4
|
||||
FL 9
|
||||
GA 2
|
||||
HI -3.3
|
||||
ID 6.6
|
||||
IL 7.2
|
||||
IN 7.1
|
||||
IA 6.9
|
||||
KS 6
|
||||
KY 1.8
|
||||
LA 7.5
|
||||
ME -4
|
||||
MD 0.1
|
||||
MA -6
|
||||
MI 1.7
|
||||
MN -2
|
||||
MS -4.4
|
||||
MO -2
|
||||
MT 1.0
|
||||
NE 1.2
|
||||
NV 1.6
|
||||
NH 0.5
|
||||
NJ 0.2
|
||||
NM 8.8
|
||||
NY 1.4
|
||||
NC 9.7
|
||||
ND 5.4
|
||||
OH 3.2
|
||||
OK 6
|
||||
OR -4
|
||||
PA -7
|
||||
RI -2
|
||||
SC 1
|
||||
SD 6
|
||||
TN 5
|
||||
TX -3.4
|
||||
UT 2.3
|
||||
VT 4.8
|
||||
VA 3
|
||||
WA 2.2
|
||||
WV 5.4
|
||||
WI 3.1
|
||||
WY -6
|
||||
|
@@ -0,0 +1,90 @@
|
||||
PImage mapImage;
|
||||
Table locationTable;
|
||||
Table nameTable;
|
||||
int rowCount;
|
||||
|
||||
Table dataTable;
|
||||
float dataMin = -10;
|
||||
float dataMax = 10;
|
||||
|
||||
|
||||
void setup() {
|
||||
size(640, 400);
|
||||
mapImage = loadImage("map.png");
|
||||
locationTable = new Table("locations.tsv");
|
||||
nameTable = new Table("names.tsv");
|
||||
rowCount = locationTable.getRowCount();
|
||||
|
||||
dataTable = new Table("random.tsv");
|
||||
|
||||
PFont font = loadFont("Univers-Bold-12.vlw");
|
||||
textFont(font);
|
||||
|
||||
smooth();
|
||||
noStroke();
|
||||
}
|
||||
|
||||
float closestDist;
|
||||
String closestText;
|
||||
float closestTextX;
|
||||
float closestTextY;
|
||||
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
image(mapImage, 0, 0);
|
||||
|
||||
closestDist = width*height; // abritrarily high
|
||||
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
String abbrev = dataTable.getRowName(row);
|
||||
float x = locationTable.getFloat(abbrev, 1);
|
||||
float y = locationTable.getFloat(abbrev, 2);
|
||||
drawData(x, y, abbrev);
|
||||
}
|
||||
|
||||
if (closestDist != width*height) {
|
||||
fill(0);
|
||||
textAlign(CENTER);
|
||||
text(closestText, closestTextX, closestTextY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void drawData(float x, float y, String abbrev) {
|
||||
float value = dataTable.getFloat(abbrev, 1);
|
||||
float radius = 0;
|
||||
if (value >= 0) {
|
||||
radius = map(value, 0, dataMax, 1.5, 15);
|
||||
fill(#333366); // blue
|
||||
} else {
|
||||
radius = map(value, 0, dataMin, 1.5, 15);
|
||||
fill(#ec5166); // red
|
||||
}
|
||||
ellipseMode(RADIUS);
|
||||
ellipse(x, y, radius, radius);
|
||||
|
||||
float d = dist(x, y, mouseX, mouseY);
|
||||
if ((d < radius + 2) && (d < closestDist)) {
|
||||
closestDist = d;
|
||||
String name = nameTable.getString(abbrev, 1);
|
||||
closestText = name + " " + nfp(value, 0, 2);
|
||||
closestTextX = x;
|
||||
closestTextY = y-radius-4;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void keyPressed() {
|
||||
if (key == ' ') {
|
||||
updateTable();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void updateTable() {
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
float newValue = random(-10, 10);
|
||||
dataTable.setFloat(row, 1, newValue);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
class Table {
|
||||
int rowCount;
|
||||
String[][] data;
|
||||
|
||||
|
||||
Table(String filename) {
|
||||
String[] rows = loadStrings(filename);
|
||||
data = new String[rows.length][];
|
||||
|
||||
for (int i = 0; i < rows.length; i++) {
|
||||
if (trim(rows[i]).length() == 0) {
|
||||
continue; // skip empty rows
|
||||
}
|
||||
if (rows[i].startsWith("#")) {
|
||||
continue; // skip comment lines
|
||||
}
|
||||
|
||||
// split the row on the tabs
|
||||
String[] pieces = split(rows[i], TAB);
|
||||
// copy to the table array
|
||||
data[rowCount] = pieces;
|
||||
rowCount++;
|
||||
|
||||
// this could be done in one fell swoop via:
|
||||
//data[rowCount++] = split(rows[i], TAB);
|
||||
}
|
||||
// resize the 'data' array as necessary
|
||||
data = (String[][]) subset(data, 0, rowCount);
|
||||
}
|
||||
|
||||
|
||||
int getRowCount() {
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
|
||||
// find a row by its name, returns -1 if no row found
|
||||
int getRowIndex(String name) {
|
||||
for (int i = 0; i < rowCount; i++) {
|
||||
if (data[i][0].equals(name)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
println("No row named '" + name + "' was found");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
String getRowName(int row) {
|
||||
return getString(row, 0);
|
||||
}
|
||||
|
||||
|
||||
String getString(int rowIndex, int column) {
|
||||
return data[rowIndex][column];
|
||||
}
|
||||
|
||||
|
||||
String getString(String rowName, int column) {
|
||||
return getString(getRowIndex(rowName), column);
|
||||
}
|
||||
|
||||
|
||||
int getInt(String rowName, int column) {
|
||||
return parseInt(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
int getInt(int rowIndex, int column) {
|
||||
return parseInt(getString(rowIndex, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(String rowName, int column) {
|
||||
return parseFloat(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(int rowIndex, int column) {
|
||||
return parseFloat(getString(rowIndex, column));
|
||||
}
|
||||
|
||||
|
||||
void setRowName(int row, String what) {
|
||||
data[row][0] = what;
|
||||
}
|
||||
|
||||
|
||||
void setString(int rowIndex, int column, String what) {
|
||||
data[rowIndex][column] = what;
|
||||
}
|
||||
|
||||
|
||||
void setString(String rowName, int column, String what) {
|
||||
int rowIndex = getRowIndex(rowName);
|
||||
data[rowIndex][column] = what;
|
||||
}
|
||||
|
||||
|
||||
void setInt(int rowIndex, int column, int what) {
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
|
||||
|
||||
void setInt(String rowName, int column, int what) {
|
||||
int rowIndex = getRowIndex(rowName);
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
|
||||
|
||||
void setFloat(int rowIndex, int column, float what) {
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
|
||||
|
||||
void setFloat(String rowName, int column, float what) {
|
||||
int rowIndex = getRowIndex(rowName);
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,50 @@
|
||||
AL 439 270
|
||||
AK 94 325
|
||||
AZ 148 241
|
||||
AR 368 247
|
||||
CA 56 176
|
||||
CO 220 183
|
||||
CT 576 120
|
||||
DE 556 166
|
||||
FL 510 331
|
||||
GA 478 267
|
||||
HI 232 380
|
||||
ID 143 101
|
||||
IL 405 168
|
||||
IN 437 165
|
||||
IA 357 147
|
||||
KS 302 194
|
||||
KY 453 203
|
||||
LA 371 302
|
||||
ME 595 59
|
||||
MD 538 162
|
||||
MA 581 108
|
||||
MI 446 120
|
||||
MN 339 86
|
||||
MS 406 274
|
||||
MO 365 197
|
||||
MT 194 61
|
||||
NE 286 151
|
||||
NV 102 157
|
||||
NH 580 89
|
||||
NJ 561 143
|
||||
NM 208 245
|
||||
NY 541 107
|
||||
NC 519 221
|
||||
ND 283 65
|
||||
OH 472 160
|
||||
OK 309 239
|
||||
OR 74 86
|
||||
PA 523 144
|
||||
RI 589 117
|
||||
SC 506 251
|
||||
SD 286 109
|
||||
TN 441 229
|
||||
TX 291 299
|
||||
UT 154 171
|
||||
VT 567 86
|
||||
VA 529 189
|
||||
WA 92 38
|
||||
WV 496 178
|
||||
WI 392 103
|
||||
WY 207 125
|
||||
|
@@ -0,0 +1,50 @@
|
||||
AL Alabama
|
||||
AK Alaska
|
||||
AZ Arizona
|
||||
AR Arkansas
|
||||
CA California
|
||||
CO Colorado
|
||||
CT Connecticut
|
||||
DE Delaware
|
||||
FL Florida
|
||||
GA Georgia
|
||||
HI Hawaii
|
||||
ID Idaho
|
||||
IL Illinois
|
||||
IN Indiana
|
||||
IA Iowa
|
||||
KS Kansas
|
||||
KY Kentucky
|
||||
LA Louisiana
|
||||
ME Maine
|
||||
MD Maryland
|
||||
MA Massachusetts
|
||||
MI Michigan
|
||||
MN Minnesota
|
||||
MS Mississippi
|
||||
MO Missouri
|
||||
MT Montana
|
||||
NE Nebraska
|
||||
NV Nevada
|
||||
NH New Hampshire
|
||||
NJ New Jersey
|
||||
NM New Mexico
|
||||
NY New York
|
||||
NC North Carolina
|
||||
ND North Dakota
|
||||
OH Ohio
|
||||
OK Oklahoma
|
||||
OR Oregon
|
||||
PA Pennsylvania
|
||||
RI Rhode Island
|
||||
SC South Carolina
|
||||
SD South Dakota
|
||||
TN Tennessee
|
||||
TX Texas
|
||||
UT Utah
|
||||
VT Vermont
|
||||
VA Virginia
|
||||
WA Washington
|
||||
WV West Virginia
|
||||
WI Wisconsin
|
||||
WY Wyoming
|
||||
|
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
# An array of the 50 state abbreviations
|
||||
@states = ('AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'FL', 'GA',
|
||||
'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD',
|
||||
'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ',
|
||||
'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC',
|
||||
'SD', 'TN', 'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY');
|
||||
|
||||
# A CGI script must identify the type of data it's sending,
|
||||
# this line specifies that plain text data will follow.
|
||||
print "Content-type: text/plain\n\n";
|
||||
|
||||
# Loop through each of the state abbreviations in the array
|
||||
foreach $state (@states) {
|
||||
|
||||
# Pick a random number between -10 and 10. (rand() returns a
|
||||
# number between 0 and 1, multiply that by 20 and subtract 10)
|
||||
$r = (rand() * 20) - 10;
|
||||
|
||||
# Print the state name, followed by a tab,
|
||||
# then the random value, followed by a new line.
|
||||
print "$state\t$r\n";
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
PImage mapImage;
|
||||
Table locationTable;
|
||||
Table nameTable;
|
||||
int rowCount;
|
||||
|
||||
Table dataTable;
|
||||
float dataMin = -10;
|
||||
float dataMax = 10;
|
||||
|
||||
|
||||
void setup() {
|
||||
size(640, 400);
|
||||
mapImage = loadImage("map.png");
|
||||
locationTable = new Table("locations.tsv");
|
||||
nameTable = new Table("names.tsv");
|
||||
rowCount = locationTable.getRowCount();
|
||||
updateTable();
|
||||
|
||||
PFont font = loadFont("Univers-Bold-12.vlw");
|
||||
textFont(font);
|
||||
|
||||
smooth();
|
||||
noStroke();
|
||||
}
|
||||
|
||||
float closestDist;
|
||||
String closestText;
|
||||
float closestTextX;
|
||||
float closestTextY;
|
||||
|
||||
|
||||
void draw() {
|
||||
image(mapImage, 0, 0);
|
||||
|
||||
closestDist = width*height; // abritrarily high
|
||||
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
String abbrev = dataTable.getRowName(row);
|
||||
float x = locationTable.getFloat(abbrev, 1);
|
||||
float y = locationTable.getFloat(abbrev, 2);
|
||||
drawData(x, y, abbrev);
|
||||
}
|
||||
|
||||
if (closestDist != width*height) {
|
||||
fill(0);
|
||||
textAlign(CENTER);
|
||||
text(closestText, closestTextX, closestTextY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void drawData(float x, float y, String abbrev) {
|
||||
float value = dataTable.getFloat(abbrev, 1);
|
||||
float radius = 0;
|
||||
if (value >= 0) {
|
||||
radius = map(value, 0, dataMax, 1.5, 15);
|
||||
fill(#333366); // blue
|
||||
} else {
|
||||
radius = map(value, 0, dataMin, 1.5, 15);
|
||||
fill(#ec5166); // red
|
||||
}
|
||||
ellipseMode(RADIUS);
|
||||
ellipse(x, y, radius, radius);
|
||||
|
||||
float d = dist(x, y, mouseX, mouseY);
|
||||
if ((d < radius + 2) && (d < closestDist)) {
|
||||
closestDist = d;
|
||||
String name = nameTable.getString(abbrev, 1);
|
||||
closestText = name + " " + nfp(value, 0, 2);
|
||||
closestTextX = x;
|
||||
closestTextY = y-radius-4;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void keyPressed() {
|
||||
if (key == ' ') {
|
||||
updateTable();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void updateTable() {
|
||||
dataTable = new Table("http://benfry.com/writing/map/random.cgi");
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
class Integrator {
|
||||
|
||||
final float DAMPING = 0.5f;
|
||||
final float ATTRACTION = 0.2f;
|
||||
|
||||
float value;
|
||||
float vel;
|
||||
float accel;
|
||||
float force;
|
||||
float mass = 1;
|
||||
|
||||
float damping = DAMPING;
|
||||
float attraction = ATTRACTION;
|
||||
boolean targeting;
|
||||
float target;
|
||||
|
||||
|
||||
Integrator() { }
|
||||
|
||||
|
||||
Integrator(float value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
Integrator(float value, float damping, float attraction) {
|
||||
this.value = value;
|
||||
this.damping = damping;
|
||||
this.attraction = attraction;
|
||||
}
|
||||
|
||||
|
||||
void set(float v) {
|
||||
value = v;
|
||||
}
|
||||
|
||||
|
||||
void update() {
|
||||
if (targeting) {
|
||||
force += attraction * (target - value);
|
||||
}
|
||||
|
||||
accel = force / mass;
|
||||
vel = (vel + accel) * damping;
|
||||
value += vel;
|
||||
|
||||
force = 0;
|
||||
}
|
||||
|
||||
|
||||
void target(float t) {
|
||||
targeting = true;
|
||||
target = t;
|
||||
}
|
||||
|
||||
|
||||
void noTarget() {
|
||||
targeting = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
class Table {
|
||||
int rowCount;
|
||||
String[][] data;
|
||||
|
||||
|
||||
Table(String filename) {
|
||||
String[] rows = loadStrings(filename);
|
||||
data = new String[rows.length][];
|
||||
|
||||
for (int i = 0; i < rows.length; i++) {
|
||||
if (trim(rows[i]).length() == 0) {
|
||||
continue; // skip empty rows
|
||||
}
|
||||
if (rows[i].startsWith("#")) {
|
||||
continue; // skip comment lines
|
||||
}
|
||||
|
||||
// split the row on the tabs
|
||||
String[] pieces = split(rows[i], TAB);
|
||||
// copy to the table array
|
||||
data[rowCount] = pieces;
|
||||
rowCount++;
|
||||
|
||||
// this could be done in one fell swoop via:
|
||||
//data[rowCount++] = split(rows[i], TAB);
|
||||
}
|
||||
// resize the 'data' array as necessary
|
||||
data = (String[][]) subset(data, 0, rowCount);
|
||||
}
|
||||
|
||||
|
||||
int getRowCount() {
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
|
||||
// find a row by its name, returns -1 if no row found
|
||||
int getRowIndex(String name) {
|
||||
for (int i = 0; i < rowCount; i++) {
|
||||
if (data[i][0].equals(name)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
println("No row named '" + name + "' was found");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
String getRowName(int row) {
|
||||
return getString(row, 0);
|
||||
}
|
||||
|
||||
|
||||
String getString(int rowIndex, int column) {
|
||||
return data[rowIndex][column];
|
||||
}
|
||||
|
||||
|
||||
String getString(String rowName, int column) {
|
||||
return getString(getRowIndex(rowName), column);
|
||||
}
|
||||
|
||||
|
||||
int getInt(String rowName, int column) {
|
||||
return parseInt(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
int getInt(int rowIndex, int column) {
|
||||
return parseInt(getString(rowIndex, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(String rowName, int column) {
|
||||
return parseFloat(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(int rowIndex, int column) {
|
||||
return parseFloat(getString(rowIndex, column));
|
||||
}
|
||||
|
||||
|
||||
void setRowName(int row, String what) {
|
||||
data[row][0] = what;
|
||||
}
|
||||
|
||||
|
||||
void setString(int rowIndex, int column, String what) {
|
||||
data[rowIndex][column] = what;
|
||||
}
|
||||
|
||||
|
||||
void setString(String rowName, int column, String what) {
|
||||
int rowIndex = getRowIndex(rowName);
|
||||
data[rowIndex][column] = what;
|
||||
}
|
||||
|
||||
|
||||
void setInt(int rowIndex, int column, int what) {
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
|
||||
|
||||
void setInt(String rowName, int column, int what) {
|
||||
int rowIndex = getRowIndex(rowName);
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
|
||||
|
||||
void setFloat(int rowIndex, int column, float what) {
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
|
||||
|
||||
void setFloat(String rowName, int column, float what) {
|
||||
int rowIndex = getRowIndex(rowName);
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,50 @@
|
||||
AL 439 270
|
||||
AK 94 325
|
||||
AZ 148 241
|
||||
AR 368 247
|
||||
CA 56 176
|
||||
CO 220 183
|
||||
CT 576 120
|
||||
DE 556 166
|
||||
FL 510 331
|
||||
GA 478 267
|
||||
HI 232 380
|
||||
ID 143 101
|
||||
IL 405 168
|
||||
IN 437 165
|
||||
IA 357 147
|
||||
KS 302 194
|
||||
KY 453 203
|
||||
LA 371 302
|
||||
ME 595 59
|
||||
MD 538 162
|
||||
MA 581 108
|
||||
MI 446 120
|
||||
MN 339 86
|
||||
MS 406 274
|
||||
MO 365 197
|
||||
MT 194 61
|
||||
NE 286 151
|
||||
NV 102 157
|
||||
NH 580 89
|
||||
NJ 561 143
|
||||
NM 208 245
|
||||
NY 541 107
|
||||
NC 519 221
|
||||
ND 283 65
|
||||
OH 472 160
|
||||
OK 309 239
|
||||
OR 74 86
|
||||
PA 523 144
|
||||
RI 589 117
|
||||
SC 506 251
|
||||
SD 286 109
|
||||
TN 441 229
|
||||
TX 291 299
|
||||
UT 154 171
|
||||
VT 567 86
|
||||
VA 529 189
|
||||
WA 92 38
|
||||
WV 496 178
|
||||
WI 392 103
|
||||
WY 207 125
|
||||
|
@@ -0,0 +1,50 @@
|
||||
AL Alabama
|
||||
AK Alaska
|
||||
AZ Arizona
|
||||
AR Arkansas
|
||||
CA California
|
||||
CO Colorado
|
||||
CT Connecticut
|
||||
DE Delaware
|
||||
FL Florida
|
||||
GA Georgia
|
||||
HI Hawaii
|
||||
ID Idaho
|
||||
IL Illinois
|
||||
IN Indiana
|
||||
IA Iowa
|
||||
KS Kansas
|
||||
KY Kentucky
|
||||
LA Louisiana
|
||||
ME Maine
|
||||
MD Maryland
|
||||
MA Massachusetts
|
||||
MI Michigan
|
||||
MN Minnesota
|
||||
MS Mississippi
|
||||
MO Missouri
|
||||
MT Montana
|
||||
NE Nebraska
|
||||
NV Nevada
|
||||
NH New Hampshire
|
||||
NJ New Jersey
|
||||
NM New Mexico
|
||||
NY New York
|
||||
NC North Carolina
|
||||
ND North Dakota
|
||||
OH Ohio
|
||||
OK Oklahoma
|
||||
OR Oregon
|
||||
PA Pennsylvania
|
||||
RI Rhode Island
|
||||
SC South Carolina
|
||||
SD South Dakota
|
||||
TN Tennessee
|
||||
TX Texas
|
||||
UT Utah
|
||||
VT Vermont
|
||||
VA Virginia
|
||||
WA Washington
|
||||
WV West Virginia
|
||||
WI Wisconsin
|
||||
WY Wyoming
|
||||
|
@@ -0,0 +1,50 @@
|
||||
AL 0.1
|
||||
AK -5.3
|
||||
AZ 3
|
||||
AR 7
|
||||
CA 11
|
||||
CO 1.5
|
||||
CT -6.7
|
||||
DE -4
|
||||
FL 9
|
||||
GA 2
|
||||
HI -3.3
|
||||
ID 6.6
|
||||
IL 7.2
|
||||
IN 7.1
|
||||
IA 6.9
|
||||
KS 6
|
||||
KY 1.8
|
||||
LA 7.5
|
||||
ME -4
|
||||
MD 0.1
|
||||
MA -6
|
||||
MI 1.7
|
||||
MN -2
|
||||
MS -4.4
|
||||
MO -2
|
||||
MT 1.0
|
||||
NE 1.2
|
||||
NV 1.6
|
||||
NH 0.5
|
||||
NJ 0.2
|
||||
NM 8.8
|
||||
NY 1.4
|
||||
NC 9.7
|
||||
ND 5.4
|
||||
OH 3.2
|
||||
OK 6
|
||||
OR -4
|
||||
PA -7
|
||||
RI -2
|
||||
SC 1
|
||||
SD 6
|
||||
TN 5
|
||||
TX -3.4
|
||||
UT 2.3
|
||||
VT 4.8
|
||||
VA 3
|
||||
WA 2.2
|
||||
WV 5.4
|
||||
WI 3.1
|
||||
WY -6
|
||||
|
@@ -0,0 +1,106 @@
|
||||
PImage mapImage;
|
||||
Table locationTable;
|
||||
Table nameTable;
|
||||
int rowCount;
|
||||
|
||||
Table dataTable;
|
||||
float dataMin = -10;
|
||||
float dataMax = 10;
|
||||
|
||||
Integrator[] interpolators;
|
||||
|
||||
|
||||
void setup() {
|
||||
size(640, 400);
|
||||
mapImage = loadImage("map.png");
|
||||
locationTable = new Table("locations.tsv");
|
||||
nameTable = new Table("names.tsv");
|
||||
rowCount = locationTable.getRowCount();
|
||||
|
||||
dataTable = new Table("random.tsv");
|
||||
interpolators = new Integrator[rowCount];
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
float initialValue = dataTable.getFloat(row, 1);
|
||||
interpolators[row] = new Integrator(initialValue);
|
||||
}
|
||||
|
||||
PFont font = loadFont("Univers-Bold-12.vlw");
|
||||
textFont(font);
|
||||
|
||||
smooth();
|
||||
noStroke();
|
||||
}
|
||||
|
||||
float closestDist;
|
||||
String closestText;
|
||||
float closestTextX;
|
||||
float closestTextY;
|
||||
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
image(mapImage, 0, 0);
|
||||
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
interpolators[row].update();
|
||||
}
|
||||
|
||||
closestDist = width*height; // abritrarily high
|
||||
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
String abbrev = dataTable.getRowName(row);
|
||||
float x = locationTable.getFloat(abbrev, 1);
|
||||
float y = locationTable.getFloat(abbrev, 2);
|
||||
drawData(x, y, abbrev);
|
||||
}
|
||||
|
||||
if (closestDist != width*height) {
|
||||
fill(0);
|
||||
textAlign(CENTER);
|
||||
text(closestText, closestTextX, closestTextY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void drawData(float x, float y, String abbrev) {
|
||||
// Figure out what row this is
|
||||
int row = dataTable.getRowIndex(abbrev);
|
||||
// Get the current value
|
||||
float value = interpolators[row].value;
|
||||
|
||||
float radius = 0;
|
||||
if (value >= 0) {
|
||||
radius = map(value, 0, dataMax, 1.5, 15);
|
||||
fill(#333366); // blue
|
||||
} else {
|
||||
radius = map(value, 0, dataMin, 1.5, 15);
|
||||
fill(#ec5166); // red
|
||||
}
|
||||
ellipseMode(RADIUS);
|
||||
ellipse(x, y, radius, radius);
|
||||
|
||||
float d = dist(x, y, mouseX, mouseY);
|
||||
if ((d < radius + 2) && (d < closestDist)) {
|
||||
closestDist = d;
|
||||
String name = nameTable.getString(abbrev, 1);
|
||||
String val = nfp(interpolators[row].target, 0, 2);
|
||||
closestText = name + " " + val;
|
||||
closestTextX = x;
|
||||
closestTextY = y-radius-4;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void keyPressed() {
|
||||
if (key == ' ') {
|
||||
updateTable();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void updateTable() {
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
float newValue = random(dataMin, dataMax);
|
||||
interpolators[row].target(newValue);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
class Integrator {
|
||||
|
||||
final float DAMPING = 0.5f;
|
||||
final float ATTRACTION = 0.2f;
|
||||
|
||||
float value;
|
||||
float vel;
|
||||
float accel;
|
||||
float force;
|
||||
float mass = 1;
|
||||
|
||||
float damping = DAMPING;
|
||||
float attraction = ATTRACTION;
|
||||
boolean targeting;
|
||||
float target;
|
||||
|
||||
|
||||
Integrator() { }
|
||||
|
||||
|
||||
Integrator(float value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
Integrator(float value, float damping, float attraction) {
|
||||
this.value = value;
|
||||
this.damping = damping;
|
||||
this.attraction = attraction;
|
||||
}
|
||||
|
||||
|
||||
void set(float v) {
|
||||
value = v;
|
||||
}
|
||||
|
||||
|
||||
void update() {
|
||||
if (targeting) {
|
||||
force += attraction * (target - value);
|
||||
}
|
||||
|
||||
accel = force / mass;
|
||||
vel = (vel + accel) * damping;
|
||||
value += vel;
|
||||
|
||||
force = 0;
|
||||
}
|
||||
|
||||
|
||||
void target(float t) {
|
||||
targeting = true;
|
||||
target = t;
|
||||
}
|
||||
|
||||
|
||||
void noTarget() {
|
||||
targeting = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
class Table {
|
||||
int rowCount;
|
||||
String[][] data;
|
||||
|
||||
|
||||
Table(String filename) {
|
||||
String[] rows = loadStrings(filename);
|
||||
data = new String[rows.length][];
|
||||
|
||||
for (int i = 0; i < rows.length; i++) {
|
||||
if (trim(rows[i]).length() == 0) {
|
||||
continue; // skip empty rows
|
||||
}
|
||||
if (rows[i].startsWith("#")) {
|
||||
continue; // skip comment lines
|
||||
}
|
||||
|
||||
// split the row on the tabs
|
||||
String[] pieces = split(rows[i], TAB);
|
||||
// copy to the table array
|
||||
data[rowCount] = pieces;
|
||||
rowCount++;
|
||||
|
||||
// this could be done in one fell swoop via:
|
||||
//data[rowCount++] = split(rows[i], TAB);
|
||||
}
|
||||
// resize the 'data' array as necessary
|
||||
data = (String[][]) subset(data, 0, rowCount);
|
||||
}
|
||||
|
||||
|
||||
int getRowCount() {
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
|
||||
// find a row by its name, returns -1 if no row found
|
||||
int getRowIndex(String name) {
|
||||
for (int i = 0; i < rowCount; i++) {
|
||||
if (data[i][0].equals(name)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
println("No row named '" + name + "' was found");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
String getRowName(int row) {
|
||||
return getString(row, 0);
|
||||
}
|
||||
|
||||
|
||||
String getString(int rowIndex, int column) {
|
||||
return data[rowIndex][column];
|
||||
}
|
||||
|
||||
|
||||
String getString(String rowName, int column) {
|
||||
return getString(getRowIndex(rowName), column);
|
||||
}
|
||||
|
||||
|
||||
int getInt(String rowName, int column) {
|
||||
return parseInt(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
int getInt(int rowIndex, int column) {
|
||||
return parseInt(getString(rowIndex, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(String rowName, int column) {
|
||||
return parseFloat(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(int rowIndex, int column) {
|
||||
return parseFloat(getString(rowIndex, column));
|
||||
}
|
||||
|
||||
|
||||
void setRowName(int row, String what) {
|
||||
data[row][0] = what;
|
||||
}
|
||||
|
||||
|
||||
void setString(int rowIndex, int column, String what) {
|
||||
data[rowIndex][column] = what;
|
||||
}
|
||||
|
||||
|
||||
void setString(String rowName, int column, String what) {
|
||||
int rowIndex = getRowIndex(rowName);
|
||||
data[rowIndex][column] = what;
|
||||
}
|
||||
|
||||
|
||||
void setInt(int rowIndex, int column, int what) {
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
|
||||
|
||||
void setInt(String rowName, int column, int what) {
|
||||
int rowIndex = getRowIndex(rowName);
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
|
||||
|
||||
void setFloat(int rowIndex, int column, float what) {
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
|
||||
|
||||
void setFloat(String rowName, int column, float what) {
|
||||
int rowIndex = getRowIndex(rowName);
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,50 @@
|
||||
AL 439 270
|
||||
AK 94 325
|
||||
AZ 148 241
|
||||
AR 368 247
|
||||
CA 56 176
|
||||
CO 220 183
|
||||
CT 576 120
|
||||
DE 556 166
|
||||
FL 510 331
|
||||
GA 478 267
|
||||
HI 232 380
|
||||
ID 143 101
|
||||
IL 405 168
|
||||
IN 437 165
|
||||
IA 357 147
|
||||
KS 302 194
|
||||
KY 453 203
|
||||
LA 371 302
|
||||
ME 595 59
|
||||
MD 538 162
|
||||
MA 581 108
|
||||
MI 446 120
|
||||
MN 339 86
|
||||
MS 406 274
|
||||
MO 365 197
|
||||
MT 194 61
|
||||
NE 286 151
|
||||
NV 102 157
|
||||
NH 580 89
|
||||
NJ 561 143
|
||||
NM 208 245
|
||||
NY 541 107
|
||||
NC 519 221
|
||||
ND 283 65
|
||||
OH 472 160
|
||||
OK 309 239
|
||||
OR 74 86
|
||||
PA 523 144
|
||||
RI 589 117
|
||||
SC 506 251
|
||||
SD 286 109
|
||||
TN 441 229
|
||||
TX 291 299
|
||||
UT 154 171
|
||||
VT 567 86
|
||||
VA 529 189
|
||||
WA 92 38
|
||||
WV 496 178
|
||||
WI 392 103
|
||||
WY 207 125
|
||||
|
@@ -0,0 +1,50 @@
|
||||
AL Alabama
|
||||
AK Alaska
|
||||
AZ Arizona
|
||||
AR Arkansas
|
||||
CA California
|
||||
CO Colorado
|
||||
CT Connecticut
|
||||
DE Delaware
|
||||
FL Florida
|
||||
GA Georgia
|
||||
HI Hawaii
|
||||
ID Idaho
|
||||
IL Illinois
|
||||
IN Indiana
|
||||
IA Iowa
|
||||
KS Kansas
|
||||
KY Kentucky
|
||||
LA Louisiana
|
||||
ME Maine
|
||||
MD Maryland
|
||||
MA Massachusetts
|
||||
MI Michigan
|
||||
MN Minnesota
|
||||
MS Mississippi
|
||||
MO Missouri
|
||||
MT Montana
|
||||
NE Nebraska
|
||||
NV Nevada
|
||||
NH New Hampshire
|
||||
NJ New Jersey
|
||||
NM New Mexico
|
||||
NY New York
|
||||
NC North Carolina
|
||||
ND North Dakota
|
||||
OH Ohio
|
||||
OK Oklahoma
|
||||
OR Oregon
|
||||
PA Pennsylvania
|
||||
RI Rhode Island
|
||||
SC South Carolina
|
||||
SD South Dakota
|
||||
TN Tennessee
|
||||
TX Texas
|
||||
UT Utah
|
||||
VT Vermont
|
||||
VA Virginia
|
||||
WA Washington
|
||||
WV West Virginia
|
||||
WI Wisconsin
|
||||
WY Wyoming
|
||||
|
@@ -0,0 +1,50 @@
|
||||
AL 0.1
|
||||
AK -5.3
|
||||
AZ 3
|
||||
AR 7
|
||||
CA 11
|
||||
CO 1.5
|
||||
CT -6.7
|
||||
DE -4
|
||||
FL 9
|
||||
GA 2
|
||||
HI -3.3
|
||||
ID 6.6
|
||||
IL 7.2
|
||||
IN 7.1
|
||||
IA 6.9
|
||||
KS 6
|
||||
KY 1.8
|
||||
LA 7.5
|
||||
ME -4
|
||||
MD 0.1
|
||||
MA -6
|
||||
MI 1.7
|
||||
MN -2
|
||||
MS -4.4
|
||||
MO -2
|
||||
MT 1.0
|
||||
NE 1.2
|
||||
NV 1.6
|
||||
NH 0.5
|
||||
NJ 0.2
|
||||
NM 8.8
|
||||
NY 1.4
|
||||
NC 9.7
|
||||
ND 5.4
|
||||
OH 3.2
|
||||
OK 6
|
||||
OR -4
|
||||
PA -7
|
||||
RI -2
|
||||
SC 1
|
||||
SD 6
|
||||
TN 5
|
||||
TX -3.4
|
||||
UT 2.3
|
||||
VT 4.8
|
||||
VA 3
|
||||
WA 2.2
|
||||
WV 5.4
|
||||
WI 3.1
|
||||
WY -6
|
||||
|
@@ -0,0 +1,107 @@
|
||||
PImage mapImage;
|
||||
Table locationTable;
|
||||
Table nameTable;
|
||||
int rowCount;
|
||||
|
||||
Table dataTable;
|
||||
float dataMin = -10;
|
||||
float dataMax = 10;
|
||||
|
||||
Integrator[] interpolators;
|
||||
|
||||
|
||||
void setup() {
|
||||
size(640, 400);
|
||||
mapImage = loadImage("map.png");
|
||||
locationTable = new Table("locations.tsv");
|
||||
nameTable = new Table("names.tsv");
|
||||
rowCount = locationTable.getRowCount();
|
||||
|
||||
dataTable = new Table("random.tsv");
|
||||
interpolators = new Integrator[rowCount];
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
float initialValue = dataTable.getFloat(row, 1);
|
||||
interpolators[row] = new Integrator(initialValue);
|
||||
}
|
||||
|
||||
PFont font = loadFont("Univers-Bold-12.vlw");
|
||||
textFont(font);
|
||||
|
||||
smooth();
|
||||
noStroke();
|
||||
frameRate(30);
|
||||
}
|
||||
|
||||
float closestDist;
|
||||
String closestText;
|
||||
float closestTextX;
|
||||
float closestTextY;
|
||||
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
image(mapImage, 0, 0);
|
||||
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
interpolators[row].update();
|
||||
}
|
||||
|
||||
closestDist = width*height; // abritrarily high
|
||||
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
String abbrev = dataTable.getRowName(row);
|
||||
float x = locationTable.getFloat(abbrev, 1);
|
||||
float y = locationTable.getFloat(abbrev, 2);
|
||||
drawData(x, y, abbrev);
|
||||
}
|
||||
|
||||
if (closestDist != width*height) {
|
||||
fill(0);
|
||||
textAlign(CENTER);
|
||||
text(closestText, closestTextX, closestTextY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void drawData(float x, float y, String abbrev) {
|
||||
// Figure out what row this is
|
||||
int row = dataTable.getRowIndex(abbrev);
|
||||
// Get the current value
|
||||
float value = interpolators[row].value;
|
||||
|
||||
float radius = 0;
|
||||
if (value >= 0) {
|
||||
radius = map(value, 0, dataMax, 1.5, 15);
|
||||
fill(#333366); // blue
|
||||
} else {
|
||||
radius = map(value, 0, dataMin, 1.5, 15);
|
||||
fill(#ec5166); // red
|
||||
}
|
||||
ellipseMode(RADIUS);
|
||||
ellipse(x, y, radius, radius);
|
||||
|
||||
float d = dist(x, y, mouseX, mouseY);
|
||||
if ((d < radius + 2) && (d < closestDist)) {
|
||||
closestDist = d;
|
||||
String name = nameTable.getString(abbrev, 1);
|
||||
String val = nfp(interpolators[row].target, 0, 2);
|
||||
closestText = name + " " + val;
|
||||
closestTextX = x;
|
||||
closestTextY = y-radius-4;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void keyPressed() {
|
||||
if (key == ' ') {
|
||||
updateTable();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void updateTable() {
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
float newValue = random(dataMin, dataMax);
|
||||
interpolators[row].target(newValue);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
class Integrator {
|
||||
|
||||
final float DAMPING = 0.5f;
|
||||
final float ATTRACTION = 0.2f;
|
||||
|
||||
float value;
|
||||
float vel;
|
||||
float accel;
|
||||
float force;
|
||||
float mass = 1;
|
||||
|
||||
float damping = DAMPING;
|
||||
float attraction = ATTRACTION;
|
||||
boolean targeting;
|
||||
float target;
|
||||
|
||||
|
||||
Integrator() { }
|
||||
|
||||
|
||||
Integrator(float value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
Integrator(float value, float damping, float attraction) {
|
||||
this.value = value;
|
||||
this.damping = damping;
|
||||
this.attraction = attraction;
|
||||
}
|
||||
|
||||
|
||||
void set(float v) {
|
||||
value = v;
|
||||
}
|
||||
|
||||
|
||||
void update() {
|
||||
if (targeting) {
|
||||
force += attraction * (target - value);
|
||||
}
|
||||
|
||||
accel = force / mass;
|
||||
vel = (vel + accel) * damping;
|
||||
value += vel;
|
||||
|
||||
force = 0;
|
||||
}
|
||||
|
||||
|
||||
void target(float t) {
|
||||
targeting = true;
|
||||
target = t;
|
||||
}
|
||||
|
||||
|
||||
void noTarget() {
|
||||
targeting = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
class Table {
|
||||
int rowCount;
|
||||
String[][] data;
|
||||
|
||||
|
||||
Table(String filename) {
|
||||
String[] rows = loadStrings(filename);
|
||||
data = new String[rows.length][];
|
||||
|
||||
for (int i = 0; i < rows.length; i++) {
|
||||
if (trim(rows[i]).length() == 0) {
|
||||
continue; // skip empty rows
|
||||
}
|
||||
if (rows[i].startsWith("#")) {
|
||||
continue; // skip comment lines
|
||||
}
|
||||
|
||||
// split the row on the tabs
|
||||
String[] pieces = split(rows[i], TAB);
|
||||
// copy to the table array
|
||||
data[rowCount] = pieces;
|
||||
rowCount++;
|
||||
|
||||
// this could be done in one fell swoop via:
|
||||
//data[rowCount++] = split(rows[i], TAB);
|
||||
}
|
||||
// resize the 'data' array as necessary
|
||||
data = (String[][]) subset(data, 0, rowCount);
|
||||
}
|
||||
|
||||
|
||||
int getRowCount() {
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
|
||||
// find a row by its name, returns -1 if no row found
|
||||
int getRowIndex(String name) {
|
||||
for (int i = 0; i < rowCount; i++) {
|
||||
if (data[i][0].equals(name)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
println("No row named '" + name + "' was found");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
String getRowName(int row) {
|
||||
return getString(row, 0);
|
||||
}
|
||||
|
||||
|
||||
String getString(int rowIndex, int column) {
|
||||
return data[rowIndex][column];
|
||||
}
|
||||
|
||||
|
||||
String getString(String rowName, int column) {
|
||||
return getString(getRowIndex(rowName), column);
|
||||
}
|
||||
|
||||
|
||||
int getInt(String rowName, int column) {
|
||||
return parseInt(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
int getInt(int rowIndex, int column) {
|
||||
return parseInt(getString(rowIndex, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(String rowName, int column) {
|
||||
return parseFloat(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(int rowIndex, int column) {
|
||||
return parseFloat(getString(rowIndex, column));
|
||||
}
|
||||
|
||||
|
||||
void setRowName(int row, String what) {
|
||||
data[row][0] = what;
|
||||
}
|
||||
|
||||
|
||||
void setString(int rowIndex, int column, String what) {
|
||||
data[rowIndex][column] = what;
|
||||
}
|
||||
|
||||
|
||||
void setString(String rowName, int column, String what) {
|
||||
int rowIndex = getRowIndex(rowName);
|
||||
data[rowIndex][column] = what;
|
||||
}
|
||||
|
||||
|
||||
void setInt(int rowIndex, int column, int what) {
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
|
||||
|
||||
void setInt(String rowName, int column, int what) {
|
||||
int rowIndex = getRowIndex(rowName);
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
|
||||
|
||||
void setFloat(int rowIndex, int column, float what) {
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
|
||||
|
||||
void setFloat(String rowName, int column, float what) {
|
||||
int rowIndex = getRowIndex(rowName);
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,50 @@
|
||||
AL 439 270
|
||||
AK 94 325
|
||||
AZ 148 241
|
||||
AR 368 247
|
||||
CA 56 176
|
||||
CO 220 183
|
||||
CT 576 120
|
||||
DE 556 166
|
||||
FL 510 331
|
||||
GA 478 267
|
||||
HI 232 380
|
||||
ID 143 101
|
||||
IL 405 168
|
||||
IN 437 165
|
||||
IA 357 147
|
||||
KS 302 194
|
||||
KY 453 203
|
||||
LA 371 302
|
||||
ME 595 59
|
||||
MD 538 162
|
||||
MA 581 108
|
||||
MI 446 120
|
||||
MN 339 86
|
||||
MS 406 274
|
||||
MO 365 197
|
||||
MT 194 61
|
||||
NE 286 151
|
||||
NV 102 157
|
||||
NH 580 89
|
||||
NJ 561 143
|
||||
NM 208 245
|
||||
NY 541 107
|
||||
NC 519 221
|
||||
ND 283 65
|
||||
OH 472 160
|
||||
OK 309 239
|
||||
OR 74 86
|
||||
PA 523 144
|
||||
RI 589 117
|
||||
SC 506 251
|
||||
SD 286 109
|
||||
TN 441 229
|
||||
TX 291 299
|
||||
UT 154 171
|
||||
VT 567 86
|
||||
VA 529 189
|
||||
WA 92 38
|
||||
WV 496 178
|
||||
WI 392 103
|
||||
WY 207 125
|
||||
|
@@ -0,0 +1,50 @@
|
||||
AL Alabama
|
||||
AK Alaska
|
||||
AZ Arizona
|
||||
AR Arkansas
|
||||
CA California
|
||||
CO Colorado
|
||||
CT Connecticut
|
||||
DE Delaware
|
||||
FL Florida
|
||||
GA Georgia
|
||||
HI Hawaii
|
||||
ID Idaho
|
||||
IL Illinois
|
||||
IN Indiana
|
||||
IA Iowa
|
||||
KS Kansas
|
||||
KY Kentucky
|
||||
LA Louisiana
|
||||
ME Maine
|
||||
MD Maryland
|
||||
MA Massachusetts
|
||||
MI Michigan
|
||||
MN Minnesota
|
||||
MS Mississippi
|
||||
MO Missouri
|
||||
MT Montana
|
||||
NE Nebraska
|
||||
NV Nevada
|
||||
NH New Hampshire
|
||||
NJ New Jersey
|
||||
NM New Mexico
|
||||
NY New York
|
||||
NC North Carolina
|
||||
ND North Dakota
|
||||
OH Ohio
|
||||
OK Oklahoma
|
||||
OR Oregon
|
||||
PA Pennsylvania
|
||||
RI Rhode Island
|
||||
SC South Carolina
|
||||
SD South Dakota
|
||||
TN Tennessee
|
||||
TX Texas
|
||||
UT Utah
|
||||
VT Vermont
|
||||
VA Virginia
|
||||
WA Washington
|
||||
WV West Virginia
|
||||
WI Wisconsin
|
||||
WY Wyoming
|
||||
|
@@ -0,0 +1,50 @@
|
||||
AL 0.1
|
||||
AK -5.3
|
||||
AZ 3
|
||||
AR 7
|
||||
CA 11
|
||||
CO 1.5
|
||||
CT -6.7
|
||||
DE -4
|
||||
FL 9
|
||||
GA 2
|
||||
HI -3.3
|
||||
ID 6.6
|
||||
IL 7.2
|
||||
IN 7.1
|
||||
IA 6.9
|
||||
KS 6
|
||||
KY 1.8
|
||||
LA 7.5
|
||||
ME -4
|
||||
MD 0.1
|
||||
MA -6
|
||||
MI 1.7
|
||||
MN -2
|
||||
MS -4.4
|
||||
MO -2
|
||||
MT 1.0
|
||||
NE 1.2
|
||||
NV 1.6
|
||||
NH 0.5
|
||||
NJ 0.2
|
||||
NM 8.8
|
||||
NY 1.4
|
||||
NC 9.7
|
||||
ND 5.4
|
||||
OH 3.2
|
||||
OK 6
|
||||
OR -4
|
||||
PA -7
|
||||
RI -2
|
||||
SC 1
|
||||
SD 6
|
||||
TN 5
|
||||
TX -3.4
|
||||
UT 2.3
|
||||
VT 4.8
|
||||
VA 3
|
||||
WA 2.2
|
||||
WV 5.4
|
||||
WI 3.1
|
||||
WY -6
|
||||
|
@@ -0,0 +1,107 @@
|
||||
PImage mapImage;
|
||||
Table locationTable;
|
||||
Table nameTable;
|
||||
int rowCount;
|
||||
|
||||
Table dataTable;
|
||||
float dataMin = -10;
|
||||
float dataMax = 10;
|
||||
|
||||
Integrator[] interpolators;
|
||||
|
||||
|
||||
void setup() {
|
||||
size(640, 400);
|
||||
mapImage = loadImage("map.png");
|
||||
locationTable = new Table("locations.tsv");
|
||||
nameTable = new Table("names.tsv");
|
||||
rowCount = locationTable.getRowCount();
|
||||
|
||||
dataTable = new Table("random.tsv");
|
||||
interpolators = new Integrator[rowCount];
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
float initialValue = dataTable.getFloat(row, 1);
|
||||
interpolators[row] = new Integrator(initialValue, 0.5, 0.01);
|
||||
}
|
||||
|
||||
PFont font = loadFont("Univers-Bold-12.vlw");
|
||||
textFont(font);
|
||||
|
||||
smooth();
|
||||
noStroke();
|
||||
//frameRate(30);
|
||||
}
|
||||
|
||||
float closestDist;
|
||||
String closestText;
|
||||
float closestTextX;
|
||||
float closestTextY;
|
||||
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
image(mapImage, 0, 0);
|
||||
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
interpolators[row].update();
|
||||
}
|
||||
|
||||
closestDist = width*height; // abritrarily high
|
||||
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
String abbrev = dataTable.getRowName(row);
|
||||
float x = locationTable.getFloat(abbrev, 1);
|
||||
float y = locationTable.getFloat(abbrev, 2);
|
||||
drawData(x, y, abbrev);
|
||||
}
|
||||
|
||||
if (closestDist != width*height) {
|
||||
fill(0);
|
||||
textAlign(CENTER);
|
||||
text(closestText, closestTextX, closestTextY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void drawData(float x, float y, String abbrev) {
|
||||
// Figure out what row this is
|
||||
int row = dataTable.getRowIndex(abbrev);
|
||||
// Get the current value
|
||||
float value = interpolators[row].value;
|
||||
|
||||
float radius = 0;
|
||||
if (value >= 0) {
|
||||
radius = map(value, 0, dataMax, 1.5, 15);
|
||||
fill(#333366); // blue
|
||||
} else {
|
||||
radius = map(value, 0, dataMin, 1.5, 15);
|
||||
fill(#ec5166); // red
|
||||
}
|
||||
ellipseMode(RADIUS);
|
||||
ellipse(x, y, radius, radius);
|
||||
|
||||
float d = dist(x, y, mouseX, mouseY);
|
||||
if ((d < radius + 2) && (d < closestDist)) {
|
||||
closestDist = d;
|
||||
String name = nameTable.getString(abbrev, 1);
|
||||
String val = nfp(interpolators[row].target, 0, 2);
|
||||
closestText = name + " " + val;
|
||||
closestTextX = x;
|
||||
closestTextY = y-radius-4;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void keyPressed() {
|
||||
if (key == ' ') {
|
||||
updateTable();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void updateTable() {
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
float newValue = random(dataMin, dataMax);
|
||||
interpolators[row].target(newValue);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
class Integrator {
|
||||
|
||||
final float DAMPING = 0.5f;
|
||||
final float ATTRACTION = 0.2f;
|
||||
|
||||
float value;
|
||||
float vel;
|
||||
float accel;
|
||||
float force;
|
||||
float mass = 1;
|
||||
|
||||
float damping = DAMPING;
|
||||
float attraction = ATTRACTION;
|
||||
boolean targeting;
|
||||
float target;
|
||||
|
||||
|
||||
Integrator() { }
|
||||
|
||||
|
||||
Integrator(float value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
Integrator(float value, float damping, float attraction) {
|
||||
this.value = value;
|
||||
this.damping = damping;
|
||||
this.attraction = attraction;
|
||||
}
|
||||
|
||||
|
||||
void set(float v) {
|
||||
value = v;
|
||||
}
|
||||
|
||||
|
||||
void update() {
|
||||
if (targeting) {
|
||||
force += attraction * (target - value);
|
||||
}
|
||||
|
||||
accel = force / mass;
|
||||
vel = (vel + accel) * damping;
|
||||
value += vel;
|
||||
|
||||
force = 0;
|
||||
}
|
||||
|
||||
|
||||
void target(float t) {
|
||||
targeting = true;
|
||||
target = t;
|
||||
}
|
||||
|
||||
|
||||
void noTarget() {
|
||||
targeting = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
class Table {
|
||||
int rowCount;
|
||||
String[][] data;
|
||||
|
||||
|
||||
Table(String filename) {
|
||||
String[] rows = loadStrings(filename);
|
||||
data = new String[rows.length][];
|
||||
|
||||
for (int i = 0; i < rows.length; i++) {
|
||||
if (trim(rows[i]).length() == 0) {
|
||||
continue; // skip empty rows
|
||||
}
|
||||
if (rows[i].startsWith("#")) {
|
||||
continue; // skip comment lines
|
||||
}
|
||||
|
||||
// split the row on the tabs
|
||||
String[] pieces = split(rows[i], TAB);
|
||||
// copy to the table array
|
||||
data[rowCount] = pieces;
|
||||
rowCount++;
|
||||
|
||||
// this could be done in one fell swoop via:
|
||||
//data[rowCount++] = split(rows[i], TAB);
|
||||
}
|
||||
// resize the 'data' array as necessary
|
||||
data = (String[][]) subset(data, 0, rowCount);
|
||||
}
|
||||
|
||||
|
||||
int getRowCount() {
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
|
||||
// find a row by its name, returns -1 if no row found
|
||||
int getRowIndex(String name) {
|
||||
for (int i = 0; i < rowCount; i++) {
|
||||
if (data[i][0].equals(name)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
println("No row named '" + name + "' was found");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
String getRowName(int row) {
|
||||
return getString(row, 0);
|
||||
}
|
||||
|
||||
|
||||
String getString(int rowIndex, int column) {
|
||||
return data[rowIndex][column];
|
||||
}
|
||||
|
||||
|
||||
String getString(String rowName, int column) {
|
||||
return getString(getRowIndex(rowName), column);
|
||||
}
|
||||
|
||||
|
||||
int getInt(String rowName, int column) {
|
||||
return parseInt(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
int getInt(int rowIndex, int column) {
|
||||
return parseInt(getString(rowIndex, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(String rowName, int column) {
|
||||
return parseFloat(getString(rowName, column));
|
||||
}
|
||||
|
||||
|
||||
float getFloat(int rowIndex, int column) {
|
||||
return parseFloat(getString(rowIndex, column));
|
||||
}
|
||||
|
||||
|
||||
void setRowName(int row, String what) {
|
||||
data[row][0] = what;
|
||||
}
|
||||
|
||||
|
||||
void setString(int rowIndex, int column, String what) {
|
||||
data[rowIndex][column] = what;
|
||||
}
|
||||
|
||||
|
||||
void setString(String rowName, int column, String what) {
|
||||
int rowIndex = getRowIndex(rowName);
|
||||
data[rowIndex][column] = what;
|
||||
}
|
||||
|
||||
|
||||
void setInt(int rowIndex, int column, int what) {
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
|
||||
|
||||
void setInt(String rowName, int column, int what) {
|
||||
int rowIndex = getRowIndex(rowName);
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
|
||||
|
||||
void setFloat(int rowIndex, int column, float what) {
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
|
||||
|
||||
void setFloat(String rowName, int column, float what) {
|
||||
int rowIndex = getRowIndex(rowName);
|
||||
data[rowIndex][column] = str(what);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,50 @@
|
||||
AL 439 270
|
||||
AK 94 325
|
||||
AZ 148 241
|
||||
AR 368 247
|
||||
CA 56 176
|
||||
CO 220 183
|
||||
CT 576 120
|
||||
DE 556 166
|
||||
FL 510 331
|
||||
GA 478 267
|
||||
HI 232 380
|
||||
ID 143 101
|
||||
IL 405 168
|
||||
IN 437 165
|
||||
IA 357 147
|
||||
KS 302 194
|
||||
KY 453 203
|
||||
LA 371 302
|
||||
ME 595 59
|
||||
MD 538 162
|
||||
MA 581 108
|
||||
MI 446 120
|
||||
MN 339 86
|
||||
MS 406 274
|
||||
MO 365 197
|
||||
MT 194 61
|
||||
NE 286 151
|
||||
NV 102 157
|
||||
NH 580 89
|
||||
NJ 561 143
|
||||
NM 208 245
|
||||
NY 541 107
|
||||
NC 519 221
|
||||
ND 283 65
|
||||
OH 472 160
|
||||
OK 309 239
|
||||
OR 74 86
|
||||
PA 523 144
|
||||
RI 589 117
|
||||
SC 506 251
|
||||
SD 286 109
|
||||
TN 441 229
|
||||
TX 291 299
|
||||
UT 154 171
|
||||
VT 567 86
|
||||
VA 529 189
|
||||
WA 92 38
|
||||
WV 496 178
|
||||
WI 392 103
|
||||
WY 207 125
|
||||
|
@@ -0,0 +1,50 @@
|
||||
AL Alabama
|
||||
AK Alaska
|
||||
AZ Arizona
|
||||
AR Arkansas
|
||||
CA California
|
||||
CO Colorado
|
||||
CT Connecticut
|
||||
DE Delaware
|
||||
FL Florida
|
||||
GA Georgia
|
||||
HI Hawaii
|
||||
ID Idaho
|
||||
IL Illinois
|
||||
IN Indiana
|
||||
IA Iowa
|
||||
KS Kansas
|
||||
KY Kentucky
|
||||
LA Louisiana
|
||||
ME Maine
|
||||
MD Maryland
|
||||
MA Massachusetts
|
||||
MI Michigan
|
||||
MN Minnesota
|
||||
MS Mississippi
|
||||
MO Missouri
|
||||
MT Montana
|
||||
NE Nebraska
|
||||
NV Nevada
|
||||
NH New Hampshire
|
||||
NJ New Jersey
|
||||
NM New Mexico
|
||||
NY New York
|
||||
NC North Carolina
|
||||
ND North Dakota
|
||||
OH Ohio
|
||||
OK Oklahoma
|
||||
OR Oregon
|
||||
PA Pennsylvania
|
||||
RI Rhode Island
|
||||
SC South Carolina
|
||||
SD South Dakota
|
||||
TN Tennessee
|
||||
TX Texas
|
||||
UT Utah
|
||||
VT Vermont
|
||||
VA Virginia
|
||||
WA Washington
|
||||
WV West Virginia
|
||||
WI Wisconsin
|
||||
WY Wyoming
|
||||
|
@@ -0,0 +1,50 @@
|
||||
AL 0.1
|
||||
AK -5.3
|
||||
AZ 3
|
||||
AR 7
|
||||
CA 11
|
||||
CO 1.5
|
||||
CT -6.7
|
||||
DE -4
|
||||
FL 9
|
||||
GA 2
|
||||
HI -3.3
|
||||
ID 6.6
|
||||
IL 7.2
|
||||
IN 7.1
|
||||
IA 6.9
|
||||
KS 6
|
||||
KY 1.8
|
||||
LA 7.5
|
||||
ME -4
|
||||
MD 0.1
|
||||
MA -6
|
||||
MI 1.7
|
||||
MN -2
|
||||
MS -4.4
|
||||
MO -2
|
||||
MT 1.0
|
||||
NE 1.2
|
||||
NV 1.6
|
||||
NH 0.5
|
||||
NJ 0.2
|
||||
NM 8.8
|
||||
NY 1.4
|
||||
NC 9.7
|
||||
ND 5.4
|
||||
OH 3.2
|
||||
OK 6
|
||||
OR -4
|
||||
PA -7
|
||||
RI -2
|
||||
SC 1
|
||||
SD 6
|
||||
TN 5
|
||||
TX -3.4
|
||||
UT 2.3
|
||||
VT 4.8
|
||||
VA 3
|
||||
WA 2.2
|
||||
WV 5.4
|
||||
WI 3.1
|
||||
WY -6
|
||||
|
@@ -0,0 +1,107 @@
|
||||
PImage mapImage;
|
||||
Table locationTable;
|
||||
Table nameTable;
|
||||
int rowCount;
|
||||
|
||||
Table dataTable;
|
||||
float dataMin = -10;
|
||||
float dataMax = 10;
|
||||
|
||||
Integrator[] interpolators;
|
||||
|
||||
|
||||
void setup() {
|
||||
size(640, 400);
|
||||
mapImage = loadImage("map.png");
|
||||
locationTable = new Table("locations.tsv");
|
||||
nameTable = new Table("names.tsv");
|
||||
rowCount = locationTable.getRowCount();
|
||||
|
||||
dataTable = new Table("random.tsv");
|
||||
interpolators = new Integrator[rowCount];
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
float initialValue = dataTable.getFloat(row, 1);
|
||||
interpolators[row] = new Integrator(initialValue, 0.9, 0.1);
|
||||
}
|
||||
|
||||
PFont font = loadFont("Univers-Bold-12.vlw");
|
||||
textFont(font);
|
||||
|
||||
smooth();
|
||||
noStroke();
|
||||
//frameRate(30);
|
||||
}
|
||||
|
||||
float closestDist;
|
||||
String closestText;
|
||||
float closestTextX;
|
||||
float closestTextY;
|
||||
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
image(mapImage, 0, 0);
|
||||
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
interpolators[row].update();
|
||||
}
|
||||
|
||||
closestDist = width*height; // abritrarily high
|
||||
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
String abbrev = dataTable.getRowName(row);
|
||||
float x = locationTable.getFloat(abbrev, 1);
|
||||
float y = locationTable.getFloat(abbrev, 2);
|
||||
drawData(x, y, abbrev);
|
||||
}
|
||||
|
||||
if (closestDist != width*height) {
|
||||
fill(0);
|
||||
textAlign(CENTER);
|
||||
text(closestText, closestTextX, closestTextY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void drawData(float x, float y, String abbrev) {
|
||||
// Figure out what row this is
|
||||
int row = dataTable.getRowIndex(abbrev);
|
||||
// Get the current value
|
||||
float value = interpolators[row].value;
|
||||
|
||||
float radius = 0;
|
||||
if (value >= 0) {
|
||||
radius = map(value, 0, dataMax, 1.5, 15);
|
||||
fill(#333366); // blue
|
||||
} else {
|
||||
radius = map(value, 0, dataMin, 1.5, 15);
|
||||
fill(#ec5166); // red
|
||||
}
|
||||
ellipseMode(RADIUS);
|
||||
ellipse(x, y, radius, radius);
|
||||
|
||||
float d = dist(x, y, mouseX, mouseY);
|
||||
if ((d < radius + 2) && (d < closestDist)) {
|
||||
closestDist = d;
|
||||
String name = nameTable.getString(abbrev, 1);
|
||||
String val = nfp(interpolators[row].target, 0, 2);
|
||||
closestText = name + " " + val;
|
||||
closestTextX = x;
|
||||
closestTextY = y-radius-4;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void keyPressed() {
|
||||
if (key == ' ') {
|
||||
updateTable();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void updateTable() {
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
float newValue = random(dataMin, dataMax);
|
||||
interpolators[row].target(newValue);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user