moving an agent through points from a text file?
in
Programming Questions
•
1 years ago
I'm trying to move a single agent through a set of points imported from a text file. Currently I have the file right now bringing in all of the points and rendering them on the first frame. Ideally I would like to have each x,y coordinate rendered individually being updated by the framerate. I have seen simpler ways of rendering points from a text file but I have to maintain the points as agents in an arraylist to later add in other parameters such as max force, max velocity, range of influence, etc.. Any ideas?
CURRENT FILE:
- import toxi.geom.*;
- ArrayList agentPop;
- void setup(){
- colorMode(HSB, 160);
- size(500,500);
- agentPop = new ArrayList();
- String [] importP = loadStrings("trajectory.txt");
- for ( int i = 0; i < importP.length; i ++)
- {
- /// import points and seperate out by comma
- float [] xyz = float(split(importP[i], ","));
- ///place the points into position of agent
- Vec3D pos = new Vec3D(xyz[0],xyz[1],xyz[2]);
- // add vel, max force, etc here
- agentPop.add(new TAgent(pos));
- }
- }
- void draw(){
- background(0,0,255);
- for ( int i = 0; i < agentPop.size(); i ++){
- TAgent a = (TAgent) agentPop.get(i);
- a.render();
- }
- }
import toxi.geom.*;
ArrayList agentPop;
void setup(){
colorMode(HSB, 160);
size(500,500);
agentPop = new ArrayList();
String [] importP = loadStrings("trajectory.txt");
for ( int i = 0; i < importP.length; i ++)
{
/// import points and seperate out by comma
float [] xyz = float(split(importP[i], ","));
///place the points into position of agent
Vec3D pos = new Vec3D(xyz[0],xyz[1],xyz[2]);
// add vel, max force, etc here
agentPop.add(new TAgent(pos));
}
}
void draw(){
background(0,0,255);
for ( int i = 0; i < agentPop.size(); i ++){
TAgent a = (TAgent) agentPop.get(i);
a.render();
}
}
class TAgent
{
//states
Vec3D pos;
//constructor
TAgent(Vec3D _pos)
{
pos = _pos;
}
void render()
{
ellipse (pos.x,pos.y, 5, 5);
}
}
TEXT FILE:
- 253,303,0
- 310,303,0
- 366,303,0
- 403,283,0
- 403,227,0
- 403,170,0
- 403,113,0
- 403,56.7,0
- 400,3.39,0
- 343,3.39,0
- 286,3.39,0
- 230,3.39,0
- 173,3.39,0
- 116,3.39,0
- 59.6,3.39,0
- 2.89,3.39,0
1