I'm pretty new to programming and I feel like there's something obvious that I'm missing. I have an ArrayList filled with PVectors, and I'd like to use use those coordinates to draw a point for each PVector. How do I translate the coordinates stored in the PVectors to the parameters of a point? Or in other words, how do I display my ArrayList of PVectors as a series of points?
Here's my code:
PVector myPos; ArrayList myPoints = new ArrayList();
void setup() { size(300, 300,P3D); background(255); byte b[] = loadBytes("portcus.txt"); // Print each value, from 0 to 255 for (int i = 0; i < b.length; i++) { // Every tenth number, start a new line if ((i % 10) == 0) { println(); }
if ((i % 2) == 0) { // bytes are from -128 to 127, this converts to 0 to 255 int x_ = b[i] & 0xff; int y_ = b[i+1] & 0xff; myPos = new PVector(x_, y_); myPoints.add(myPos); println(myPos.x + ", " + myPos.y); } } // Print a blank line at the end println(); }
void draw(){ for(int i = 0; i< myPoints.size(); i++){ //println(myPoints.get(i)); //this for loop is where I was intending to draw the points } }
Currently all it does is coding a txt file as byte date, translating each letter in the file to a number between 0 and 255, storing the info in a ArrayList and then printing the values to the console. I was going to make two Arrays, one for the x coordinates and one for the ys, but my professor said this would be easier (And then he left to go help other students and this is as far as I got).
Any help is greatly appreciated~