How to add texture (with an image) to a line?

Assuming you have the center of each segment and its width and height, you can do this:

-Set imageMode to CENTER: https://processing.org/reference/imageMode_.html

  • Load your rectangular texture in a PImage object
  • Use translate/rotate. Translate is used to set the center of the sketch at the center of the line segment. You do a rotate and then you draw the image
  • Use push/pop. Push/pop allows to set and reset your sketch coordinate system. This comes handy when you are ready to set your next segment

In your code above, the translate/rotate and push/pop would be inside the for loop. You will need to have a PImage array that you can get the textures from while interacting with each line segment.

By the way, iamgeMode CENTER is just a recommendation. You can use any image mode you want but I find that CENTER works better in these situations.

Kf