Open this sketch in P5 Web Editor →
Drag the yellow circle in the canvas below. Watch how it changes color when its center point enters the blue "beside" zones. Notice the crosshairs showing the exact center point and coordinates being tracked.
BESIDE means positioned next to something, typically to the left or right. In this example, "beside" is determined by checking if an object's center point falls within defined rectangular zones adjacent to the main object.
To create "beside" relationships on screen:
if (x < leftBound) { return false; }
- Check if X coordinate is too far leftif (x > rightBound) { return false; }
- Check if X coordinate is too far rightif (y < topBound) { return false; }
- Check if Y coordinate is too highif (y > bottomBound) { return false; }
- Check if Y coordinate is too lowlet leftZoneX = mainObject.x - mainObject.width/2 - zoneWidth/2;
let rightZoneX = mainObject.x + mainObject.width/2 + zoneWidth/2;
let leftBound = leftZoneX - zoneWidth/2;
let rightBound = leftZoneX + zoneWidth/2;
if (x < leftBound) { return false; }
if (x > rightBound) { return false; }
if (y < topBound) { return false; }
if (y > bottomBound) { return false; }
return true; // Point is inside zone
if (dist(mouseX, mouseY, circle.x, circle.y) < radius) {
circle.dragging = true; }