@ class is art @ (@_@) this problem had bother me long enough ...> <
here is my bad code :
- ///data from Rhino's grasshopper- " X" coordinate, and "Y" coordinate
- float lines1X[];
float lines1Y[];
float lines2X[];
float lines2Y[];
float lines3X[];
float lines3Y[]; - //there are more lines...
- ArrayList stations1= new ArrayList();//does not work
void setup() {
size(800, 550);
// PImage img = loadImage("2012 siteBase.jpg");
// image (img, 0, 0);
lines1X = float(loadStrings("xPosition.txt"));
lines1Y = float(loadStrings("yPosition.txt"));
lines2X = float(loadStrings("x2Pos.txt"));
lines2Y = float(loadStrings("y2Pos.txt"));
lines3X = float(loadStrings("x3Pos.txt"));
lines3Y = float(loadStrings("y3Pos.txt"));
}
void draw() {
for (int i =0; i<lines2X.length; i++) {
float mapX = map(lines2X[i], 0, 800, 0, width);
float mapY = map(lines2Y[i], 550, 0, 0, height);
fill(255, 0, 0);
ellipse(mapX, mapY, 10, 10);
}
// -------------------------------------------------------- for (int i =0; i<lines3X.length; i++) {
float mapX = map(lines3X[i], 0, 800, 0, width);
float mapY = map(lines3Y[i], 550, 0, 0, height);
fill(255, 0, 0);
ellipse(mapX, mapY, 10, 10);
}
// -------------------------------------------------------
for (int i =0; i<lines4X.length; i++) {
float mapX = map(lines4X[i], 0, 800, 0, width);
float mapY = map(lines4Y[i], 550, 0, 0, height);
fill(255, 0, 0);
ellipse(mapX, mapY, 10, 10);
}
} - //////////////////try to change above repeat loop to class, but doesn't work
- class stations {
ArrayList stations;
float mapX;
float mapY;
stations station; - void addStation (float x, float y) {
PVector station= new PVector(x, y);
stations.add(station);
}
void display() {
for (int i =0; i<stations.size(); i++) {
PVector station= (PVector) stations.get(i);
fill(255, 0, 0);
ellipse(mapX, mapY, 10, 10);
}
}
}- ///////////////I try to write some thing like this too,
- class stations {
PVector ball;
PVector loc;
float linesX[];
float linesY[];
float linesZ[]; - stations(float loadStrings("ttopY.txt"), float loadStrings("ttopZ.txt"),float loadStrings("ttopX.txt") ) {
linesX[]= loadStrings("ttopZ.txt");
linesY[]= loadStrings("ttopZ.txt");
linesZ[]= loadStrings("ttopX.txt");
}
....~'"~|||....#_# never work .....
here is the simple example which is worked with only one line, and no class
The idea is: I have a map, they have points in (x,y) creat I want to have a train or car drive on this route.
- ArrayList<PVector> Balls;
PVector loc;
PVector vel;
PVector ball;
float lines1X[];
float lines1Y[];
boolean goBack = false; - int t = 0;
float exponent =4;
float x=0.0;
float y=0.0;
float step = 0.05;
float pct = 0.0; - void setup(){
size(600, 600);
Balls = new ArrayList();
lines1X = float(loadStrings("xPosition.txt"));
lines1Y = float(loadStrings("yPosition.txt"));
for(int i =0; i<lines1X.length; i++){
float mapX = map(lines1X[i],0,2500,0,width);
float mapY = map(lines1Y[i],2500,0,0,height);
PVector ball = new PVector(mapX,mapY);
Balls.add(ball);
} - noStroke();
smooth();
loc=new PVector(Balls.get(0).x,Balls.get(0).y);
}
void draw(){
fill(0, 155);
rect(0, 0, width, height);
//distX = endX - beginX;
//distY = endY - beginY;
//for(int i =0; i<Balls.size()-1; i++){
PVector ball = Balls.get(t);
if (pct < 1.0) {
pct += step;
loc.x = loc.x + (pct * (Balls.get(t+1).x-loc.x));
loc.y = loc.y + (pow(pct,exponent) * (Balls.get(t+1).y-loc.y));
//y = beginY + (pow(pct, exponent) * distY);
println(pct);
if(pct >= 1){
if(t==Balls.size()-2){
goBack = true;
}else if(t==0){
goBack = false;
}
if(goBack){
t--;
}else{
t++;
}
pct =0;
}
}
// }
- fill(255,0,0);
ellipse(loc.x, loc.y, 10, 10);
for(int i = 0; i<Balls.size(); i++){
PVector bb = Balls.get(i);
fill(0,255,0);
ellipse(bb.x,bb.y,10,10);
text(str(i),bb.x+5,bb.y-5);
}
}
xPosition.txt
{
1408.0
1317.391112
1394.302423
1509.650022
1475.176701
1440.958262
1350.16011
1273.364917
1304.509774
1274.0
}
yPosition.txt
{
950.0
1053.201979
1126.070458
1164.261628
1294.595287
1425.331547
1528.800457
1640.490372
1771.466451
1905.0
}
my Xmas tree was made by this long way without class
http://www.openprocessing.org/sketch/48335
sorry the question is so long...
Hope some one know how to make it. .