fix up line endings, improve code quality (issue #522)

This commit is contained in:
benfry
2011-04-16 19:26:16 +00:00
parent da7c72cc6d
commit 398519707f
4 changed files with 649 additions and 238 deletions
@@ -14,8 +14,7 @@ PFont body;
int num = 9; // Display this many entries on each screen.
int startingEntry = 0; // Display from this entry number
void setup()
{
void setup() {
size(200, 200);
fill(255);
noLoop();
@@ -26,9 +25,14 @@ void setup()
lines = loadStrings("cars2.tsv");
records = new Record[lines.length];
for (int i = 0; i < lines.length; i++) {
String[] pieces = split(lines[i], '\t'); // Load data into arrayif (pieces.length == 9) {
records[recordCount] = new Record(pieces);
recordCount++;
String[] pieces = split(lines[i], TAB); // Load data into array
if (pieces.length == 9) {
records[recordCount] = new Record(pieces);
recordCount++;
}
}
if (recordCount != records.length) {
records = (Record[]) subset(records, 0, recordCount);
}
}
@@ -36,37 +40,16 @@ void draw() {
background(0);
for (int i = 0; i < num; i++) {
int thisEntry = startingEntry + i;
text(thisEntry + " > " + records[thisEntry].name, 20, 20 + i*20); // Print name to console
if (thisEntry < recordCount) {
text(thisEntry + " > " + records[thisEntry].name, 20, 20 + i*20);
}
}
}
void mousePressed() {
startingEntry += num;
if (startingEntry + num > records.length) {
startingEntry -= num;
if (startingEntry > records.length) {
startingEntry = 0; // go back to the beginning
}
redraw();
}
class Record {
String name;
float mpg;
int cylinders;
float displacement;
float horsepower;
float weight;
float acceleration;
int year;
float origin;
public Record(String[] pieces) {
name = pieces[0];
mpg = float(pieces[1]);
cylinders = int(pieces[2]);
displacement = float(pieces[3]);
horsepower = float(pieces[4]);
weight = float(pieces[5]);
acceleration = float(pieces[6]);
year = int(pieces[7]);
origin = float(pieces[8]);
}
}
@@ -0,0 +1,23 @@
class Record {
String name;
float mpg;
int cylinders;
float displacement;
float horsepower;
float weight;
float acceleration;
int year;
float origin;
public Record(String[] pieces) {
name = pieces[0];
mpg = float(pieces[1]);
cylinders = int(pieces[2]);
displacement = float(pieces[3]);
horsepower = float(pieces[4]);
weight = float(pieces[5]);
acceleration = float(pieces[6]);
year = int(pieces[7]);
origin = float(pieces[8]);
}
}
File diff suppressed because one or more lines are too long