Interactive visualization: find where a line through two points meets a chosen x-coordinate, with movable y-constraints.
- 2D space: Two draggable points (P1, P2) define the line.
- Target X: A vertical line you move with a slider; the intersection is where the line meets this x.
- Y constraints: Y min / Y max limit where the intersection point is drawn; the yellow point is clamped to this band. When clamped, the dashed path is shown in a different color.
- Export & share: Download the diagram as PNG; the URL updates so you can share or bookmark a configuration.
- Drag either endpoint (P1 or P2) to change the line.
- Use Constraints to set the y-range (band) for the intersection.
- Use Target X to move the vertical line and see the intersection move.
- Use Export as PNG to download the current diagram.
- Copy the URL to share or bookmark a configuration.
The line through two points
So the line is
| Case | Behaviour |
|---|---|
|
Vertical line ( |
No single y at that x; no intersection point is drawn. |
| Outside band | y is clamped to the constraint band; dashed path is shown in a different color. |
Option A: Direct: Open index.html in a browser (some features may be limited with file://).
Option B: Local server:
npx serve .Then open the URL shown (e.g. http://localhost:3000).
| File | Purpose |
|---|---|
index.html |
Entry point: layout, controls, P5 script. |
main.js |
Diagram logic: config, state, intersection math, drawing, UI sync, export, URL state. |
styles.css |
Design tokens, layout, control cards, responsive and reduced-motion rules. |
- P5.js (CDN): Canvas and interaction.
- Vanilla JS: Single IIFE, one global (
IntersectsApp) for the P5 lifecycle. - No build step: JSDoc for types and documentation.
State is encoded in the query string so configurations can be shared or bookmarked:
?x=300&c=2&p1=500,400&p2=200,300
