# Bug in my code\_ Circle Overlap

**URL:** <https://discourse.processing.org/t/bug-in-my-code-circle-overlap/43716>\
**Category:** Coding Questions\
**Created:** [January 19, 2024, 6:11am UTC](https://discourse.processing.org/t/bug-in-my-code-circle-overlap/43716 "2024-01-19T06:11:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jiji](https://avatars.discourse-cdn.com/v4/letter/j/2bfe46/32.png) [@Jiji](https://discourse.processing.org/u/Jiji)\
**Post date:** [January 19, 2024, 6:11am UTC](https://discourse.processing.org/t/bug-in-my-code-circle-overlap/43716/1 "2024-01-19T06:11:02Z")

</div>

Hi y’all,  
I am trying to make a test when 2 circles overlapped, then it should change color background. But for some reason, the background always changes color when the circles are closed and not overlapped yet. Unless I changed the ellipse to ellipse(this.x, this.y, this.r\*2) instead of this.r.  
Can you help me with this issue?  
Thank you!

\<  
class bubble{

constructor(x,y,r){  
this.x=x;  
this.y=y;  
this.r=r;  
}

display(){  
noFill();  
stroke(0);  
strokeWeight(1);  
ellipse(this.x,this.y,this.r);  
}

intersect(other){  
let d = dist(this.x, this.y, other.x, other.y);  
return d \< this.r + other.r;  
}  
}

let bubble1;  
let bubble2;

function setup() {  
createCanvas(800, 400);  
bubble1 = new bubble(100, 200,100);  
bubble2 = new bubble(400, 200, 100);  
}

function draw() {  
background(220);

if (bubble1.intersect(bubble2)){  
background(200, 0, 100);  
}  
bubble1.display();  
bubble2.display();  
bubble2.x=mouseX;  
bubble2.y=mouseY;  
}

>

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [January 19, 2024, 6:27am UTC](https://discourse.processing.org/t/bug-in-my-code-circle-overlap/43716/2 "2024-01-19T06:27:37Z")

</div>

[https://CrHallberg.com/CollisionDetection/Website/circle-circle.html](https://CrHallberg.com/CollisionDetection/Website/circle-circle.html)

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [January 19, 2024, 11:38am UTC](https://discourse.processing.org/t/bug-in-my-code-circle-overlap/43716/3 "2024-01-19T11:38:25Z")

</div>

Check the documentation for ellipse to draw a circle then the third parameter is the circle diameter not the radius

---

<div class="post-metadata">

**Author:** ![Jiji](https://avatars.discourse-cdn.com/v4/letter/j/2bfe46/32.png) [@Jiji](https://discourse.processing.org/u/Jiji)\
**Post date:** [January 19, 2024, 4:10pm UTC](https://discourse.processing.org/t/bug-in-my-code-circle-overlap/43716/4 "2024-01-19T16:10:25Z")

</div>

Ohh I got it! . Thank you so much!
