String art in Processing. What I've got so far. SOLVED

Good afternoon all.
I’m trying to use processing to create some “string art”, which is overlapping lines that form curves. The code I’ve got is below. I’ve tried to make it so that I don’t have hard-coded values, meaning I can change just one or two little things and it makes a different image.

The problem I have is that the final line doesn’t get drawn, and every tweak I’ve tried makes things worse.

I’ve made comments in the code pasted below, so it should be clear what I’m doing. If my explanation isn’t clear, running the code generates the image, and you can see where there is a missing final line in the resulting image.

Could somebody please help me out here?

Thanks for reading

size(600, 600);

background(255);
int gap = 15;
int heightMinusGap = height - gap;

float lineBeginX = gap; // line origin x position
float lineBeginY = gap; // line origin y position
float lineEndX = gap;   // line end x position
float lineEndY = heightMinusGap;  // line end y position


// This loop draws a line beggining at the line origin x, y and 
// ending at the line end x, y. Once the line is drawn, it adds "gap"
// to both the line origin y position, leaving the x position 
// the same as the setup figures, and the line end x position
// leaving the line end the same as at the start. When it gets to 
// the canvas height minus the gap figure, the loop exits.


while (lineBeginY < heightMinusGap){
   line(lineBeginX, lineBeginY, lineEndX, lineEndY);
lineBeginY = lineBeginY + gap;
lineEndX = lineEndX +gap;
}

Hello @Matty27,

Try:
<=

Reference:

:)

4 Likes

That worked perfectly.
Thank you very much

1 Like