Question regarding PVector and ArrayLists
in
Programming Questions
•
7 months ago
Hello,
The code I have so far creates dots on the screen. I'm still trying to wrap my head around ArrayLists and classes, so maybe I'm getting ahead of myself here... but what I'd like to be able to do is get the x and y value's of each dot on the screen.
I looked at PVector (
http://processing.org/reference/PVector.html), but I still don't understand how to use it, or how it works. I'd greatly appreciate it if someone could give me a push in the right direction and give me a better explanation of PVector.
- class Dot {
- float dotX, dotY;
- float dotDiam;
- Dot(float initDotX, float initDotY, float initDotDiam) {
- dotX = initDotX;
- dotY = initDotY;
- dotDiam = initDotDiam;
- }
- void render() {
- noStroke();
- fill(0);
- ellipse(dotX, dotY, dotDiam, dotDiam);
- }
- }
- ArrayList<Dot> dots;
- float dotSpacing;
- boolean notFull;
- float dotXWithSpacing, dotYWithSpacing;
- void setup() {
- notFull = true;
- dots = new ArrayList<Dot>();
- size(500,500);
- background(255);
- dotSpacing = 25;
- dotXWithSpacing = dotSpacing;
- dotYWithSpacing = dotSpacing;
- }
- void draw() {
- while(notFull) {
- Dot dotDraw = new Dot(dotXWithSpacing, dotYWithSpacing, 5);
- if (dotDraw.dotX <= width - (dotSpacing * 2) && dotDraw.dotY <= height - (dotSpacing)) {
- dotXWithSpacing = dotSpacing + dotDraw.dotX;
- dots.add(dotDraw);
- } else if (dotDraw.dotX > width - (dotSpacing * 2)) {
- dotXWithSpacing = dotSpacing;
- dotYWithSpacing = dotSpacing + dotDraw.dotY;
- dots.add(dotDraw);
- }
- if (dotDraw.dotY > height - (dotSpacing)) {
- notFull = false;
- }
- }
- for (Dot dotDraw : dots) {
- dotDraw.render();
- }
- }
1