We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi all, it seems a bit of a longwinded title but I have an array of PVectors which I want to get the x & y co ordinates from in order to draw a PShape. The issue I have is line 24, this points.get() approach worked when I was just grabbing the x and y separately from an array of floats but like this I can't get to the x & y variables within the PVector. points.get(i).x doesn't work either. I'm sure it's probably a simple solution and i'm brainfarting. Assistance would be appreciated, thanks.
Code below:
PShape shape;
ArrayList points = new ArrayList<PVector>();
PVector temp = new PVector();
void setup() {
size(800, 800);
}
void draw()
{
//populating the array with PVectors
for (int i = 0; i < 11; i++)
{
temp.x = (float)random(0, width-50);
temp.y = (float)random(0, width-50);
points.add(temp);
}
//creating the shape
shape = createShape();
shape.beginShape();
shape.fill(0, 0, 255);
shape.noStroke();
shape.vertex(points.get(0), points.get(1));
shape.bezierVertex(points.get(2), points.get(3), points.get(4), points.get(5), points.get(6), points.get(7));
shape.bezierVertex(points.get(8), points.get(9), points.get(10), points.get(11), points.get(12), points.get(13));
shape.bezierVertex(points.get(14), points.get(15), points.get(16), points.get(17), points.get(18), points.get(19));
shape.vertex(points.get(20), points.get(21));
shape.endShape();
//drawing the shape
shape(shape, 25, 25);
}
Answers
This code works for me.
Kf
If you use
Then you don't need to cast the result of the get () in line 21.
@ line #2
ArrayList points = new ArrayList<PVector>();
, the variable points is of datatype ArrayPoints. However the generic type wasn't specified. Although you've specified it when instantiating it w/new
, it's more important for the variable declaration to have the generic type:ArrayList<PVector> points = new ArrayList();
.Or even better, both sides have it:
ArrayList<PVector> points = new ArrayList<PVector>();
Thankyou to all of you for the assistance.