Learn creative coding writing simple programs
60. Are two circles touching or intersecting?
Use the dist() function to calculate the distance between two points in the screen. Why would you want to do that? Well, you can use the distanceto know if two circles are overlapping. If the distance between the centers of the circles is less than the radius of the first circle plus the radius of the second circle, then they are touching.
The radius of a circle is the distance between the center of the circle and any point in the circle itself.
Code editor
You can make changes to the code below. Then
Reference
background
dist
draw
ellipse
else
float
height
if
mouseX
mouseY
noFill
noise
random
setup
size
stroke
strokeWeight
void
width
background
dist
draw
ellipse
else
float
height
if
mouseX
mouseY
noFill
noise
random
setup
size
stroke
strokeWeight
void
width
Try to stay close to the topic of this episode. Use the Processing forums for help with unrelated Processing projects (or hire me for help ;-)
To indicate that a word in your comment is code, use the `backtick`. Example
Do `float` and `int` smell similar?
To highlight code blocks, surround it with ``` code-fences ``` like this:``` void setup() { size(600, 600); } ```