Oh, no… it seems I spoke too soon.
When it comes to recording to a .PDF it saves it as an embedded image of diagonal lines, which unfortunately is not what Im after.
I tried using the .SVG library, but that gives me a NPE error. the reference does state that the library does not work with images.
If the pink rectangle is the same proportion as the grid cells and you’re only working with rotated lines, you might be able to solve it as followed: You could write a function to calculate where the rotated lines intersect with the edges of the pink rectangle, save these x and y values, and use those to draw separate lines. Something like this:
The code above isn’t pretty, but you get the idea. Perhaps you could convert it into a class or a shape to speed up the sketch’s performance. Think something like this might work for your situation?
This is an amended take on my ray casting example, using light intersection. In this example I’ve only generated lines for one side of the rectangle, you would need to do this for all sides.
Alternatively amend the code to allow the lines to handle multiple intersections.
Please note some of the lines will look a bit thicker as they are draw twice, I’m drawing a set of lines diagonally right down, and another set of lines diagonally up left, those which intersect with the square are trimmed the others however are not, and therefore are drawn twice.
It seems like the simplest solution, which was suggested initialy and I don’t think it was ever clarified whether the intersection lines were required. If they are I’m not sure the mask would fit that purpose which is why I suggested the intersection function. But yes the simplest solution is to just draw a square over the lines based on the mouse position.