I believe you’ve got it from here perhaps:
What do you mean by that? This sketch is already cross-mode.
That is, the same code runs on both offline Java Mode (Processing’s IDE) & online JavaScript Mode (Pjs): ProcessingJS.org
DIAM stands for diameter and SPD stands for speed.
d >> 1
gets the half of d, which stands for diameter btW. Thus r is radius.
B/c the sketch is using the default ellipseMode(CENTER);
:
The default mode is ellipseMode(CENTER) , which interprets the first two parameters of ellipse() as the shape’s center point, while the third and fourth parameters are its width and height.
And the coordinate pair origin of an ellipse() is its CENTER, knowing the RADIUS of it is essential for collision checks:
In this specific sketch, the collision check is to constrain() the ellipse() within the sketch’s rectangular canvas when we move it:
x = constrain(x + v*(int(isRight) - int(isLeft)), r, width - r);
Again I don’t get what you mean. B/c we can totally copy & paste the whole code in Processing IDE’s Java Mode in order to run it offline.