PVector previousPoint = null; ArrayList lines = new ArrayList(); ArrayList dragged = new ArrayList(); Line previousLine; void setup() { size(1000, 800); frameRate(60); background(0xFF); lines.add(new Line(0, 0, width, 0)); lines.add(new Line(0, 0, 0, height)); lines.add(new Line(width, 0, width, height)); lines.add(new Line(0, height, width, height)); } void draw() { PVector mousePoint = new PVector(mouseX, mouseY); if (previousPoint!=null) { if (dist(previousPoint.x, previousPoint.y, mousePoint.x, mousePoint.y)>1) { boolean intersectionFound = true; int tries = 0; while (intersectionFound && tries++<10 ) { intersectionFound=false; for (int i=0; i= 0 && s <= 1 && t >= 0 && t <= 1) return new PVector (p1A.x + (t * s1.x), p1A.y + (t * s1.y)); return null; }