Is there a way to get this effect of generating
0, 1
1, 2
2, 3
3, 0
…
with a single condition, I mean either without using if/else, or taking the if/else out of the for loop? And avoid hard coding ‘0’
This just seems janky to me
PVector[] points;
int nPoints;
float textSz;
void setup() {
size(100, 100);
textSz = 16;
nPoints = 4;
points = new PVector[nPoints];
}
void draw() {
background(50);
for (int i = 0; i < points.length; i++) {
if (i+1 < points.length) {
points[i] = new PVector(i, i+1);
} else {
points[i] = new PVector(i, 0);
}
}
display();
}
void display() {
for (int i = 0; i < points.length; i++) {
textAlign(LEFT, TOP);
textSize(textSz);
String x = nf(points[i].x, 1, 0);
String y = nf(points[i].y, 1, 0);
String p = x + ", " + y;
text(p, 0, i * textSz);
}
}
Sorry… what’s not working? It runs on the Processing iCompiler, which of course runs lots of things it shouldn’t, but maybe it’s that text() doesn’t like outputting a PVector?
I’ll update the code after I check it in the Processing IDE.
The output I get is
[0, 1, 0]
[1, 2, 0]
[2, 3, 0]
[3, 0, 0]
… which is what I’m trying for.
I don’t follow the example you provided, it should go back to 0, not 1