Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
oceans76
oceans76's Profile
1
Posts
0
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
Use data from array in an object / creating multiple objects
[1 Reply]
11-May-2011 10:18 AM
Forum:
Programming Questions
How do I pass data from an array into an object and how do I create multiple objects?
Is my approach all wrong?
//ArrayList people = new ArrayList();
Person people[] = new Person[0];
Human myHuman1;
Human myHuman2;
//Human myHuman[i];
PFont font;
void setup() {
size (600,600);
smooth();
font = loadFont ("ArialMT-24.vlw");
/* txt file example:
Smith, John, M, 1910, 1980
Doe, Jane, F, 1885, 1911
*/
String lines[] = loadStrings("pendelton.txt");
for(int i = 0; i < lines.length; i++){
String values[] = (lines[i].split(","));
people = (Person[]) append(people, new Person(values[0], values[1], values[2], values[3], values[4]) );
}
myHuman1 = new Human(color(0,0,255,10), (1910/10), (1980/10), 70);
myHuman2 = new Human(color(255,0,0,10), (1885/10), (1911/10), 26);
/*
for(int i = 0; i < ??; i++) {
myHuman[i] = new Human(c, (yearBorn/10), (yearDied/10), age);
}
*/
}
void draw() {
background (255);
myHuman1.display();
myHuman2.display();
/*
for(int i = 0; i < ??; i++) {
myHuman[i].display();
}
*/
}
class Person {
Person(String nameLast, String nameFirst, String gender, String yearBorn, String yearDied) {
println(nameLast + " " + nameFirst +" " + gender +" " + yearBorn +" " + yearDied +""+" age " + (int(yearDied) - int(yearBorn)));
}
}
class Human {
/*
if (gender == "M") {
c = (0,0,255,10);
}
if (gender == "F") {
c = (255,0,0,10);
}
*/
color c;
int yearBorn;
int yearDied;
int age = (int(yearDied) - int(yearBorn));
Human(color tempC, int tempyearBorn, int tempyearDied, int tempage) {
c = tempC;
yearBorn = tempyearBorn;
yearDied = tempyearDied;
age = tempage;
}
void display() {
stroke(0);
fill(c);
ellipseMode(CORNER);
ellipse(yearBorn,yearDied,age,age);
}
}
«Prev
Next »
Moderate user : oceans76
Forum