Using an HTML canvas, I have implemented a connect-the-dots application where users can draw lines between multiple points from 1 to N upon touchstart.
Currently, there is validation in place to ensure that users can only draw lines connecting dots from point 1 to point 2 (..n). However, the issue lies in the lack of validation for straight lines. I am seeking an algorithm to address this problem. Here is my initial thought process:
- To determine if a line is straight between two points (x1,y1) and (x2,y2), calculate all coordinates using the slope formula y = mx + b.
- During touchmove events, verify that the x,y coordinates correspond to one of the calculated points from the previous step before drawing the line.
I am open to suggestions for better approaches or alternative methods to achieve this desired functionality. Any input would be greatly appreciated!