this is my code , I changed one of the car to read from array instead of text file , but how could I draw the car usuing that array ?
Since I get the data as a udp packet I think it's better to save it as an array instead of textfile !
import processing.opengl.*;
String[] lines;
int index = 0;
Car myCar1;
Car myCar2;
Car myCar3;
PImage car;
void setup() {
size(screenWidth, screenHeight,OPENGL);
frameRate(20);
myCar1 = new Car(color(108,87,229));
myCar2 = new Car(color(108,87,229));
myCar3 = new Car(color(108,87,229));
car = loadImage("3.jpg");
}
void draw() {
background(0);
translate(width/2,height/3);
// image(car, 0, 0);
// Displays the image at point (100, 0) at half of its size
image(car, 0, -120, car.width/4, car.height/4);
String[]lines1 = { "100\t4","100\t8","100\t12","100\t16","100\t20","100\t24","100\t28","100\t32","100\t36","100\t40","100\t44","100\t48","100\t52"};
myCar1.Move();
lines = loadStrings("pos.txt");
// myCar3.Move();
lines = loadStrings("positions.txt");
// myCar2.Move();
}
class Car {
color c;
int z = 10;
int t = 30;
Car(color tempC){
c = tempC;
}
void display() {
fill(162, 211, 172);
rect(200,200,10,30);
}
void Move() {
fill(c);
if (index < lines.length) {
String[] pieces = split(lines[index], '\t');
if (pieces.length == 2) {
int x = int(pieces[0]);
int y = int(pieces[1]);
rect(x, y, z, t);
}
// Go to the next line for the next run through draw()
index = index + 1;
}
}
}