# New to P5 - basic object question

**URL:** https://discourse.processing.org/t/new-to-p5-basic-object-question/9207
**Category:** Coding Questions
**Created:** [March 11, 2019, 10:29pm UTC](https://discourse.processing.org/t/new-to-p5-basic-object-question/9207 "2019-03-11T22:29:04Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![cryptogee](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/cryptogee/32/4099_2.png) [@cryptogee](https://discourse.processing.org/u/cryptogee)
#### Post date: [March 11, 2019, 10:29pm UTC](https://discourse.processing.org/t/new-to-p5-basic-object-question/9207/1 "2019-03-11T22:29:04Z")

</div>

Hi, I’ve just discovered P5 today, I have some coding experience, however it is mainly theoretical/following along. Now I’m trying to make it on my own!

Okay, so I have drawn a basic background with a couple of ellipses in it. I am trying to get it so that every time I press my mouse over one of the ellipses, I leave behind a small ‘pebble’.

I have got it so that my mouse changes colour, however it does not leave an object behind when I click. My code is below, I’m pretty sure I shouldn’t be using if/else statements, so please point me in the right direction.

Thanks

```auto
function setup() {
  let canvas = createCanvas(600, 400);
	canvas.position(300, 50);

}

function draw() {
	background(0, 128, 0);

	fill (128, 128, 128);
	ellipse(width/2, height/4, 100, 100);
	ellipse(width/7, height/4, 100, 100);
	
	if (mouseIsPressed) {
		fill(0);
		
	} else {
		fill(255);
	}
	
	ellipse(mouseX, mouseY, 25, 25);
}

```

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [March 11, 2019, 10:45pm UTC](https://discourse.processing.org/t/new-to-p5-basic-object-question/9207/2 "2019-03-11T22:45:12Z")

</div>

you can delete `background`, then the points will stay permanently

you can use something like

```auto
if(dist(mouseX,mouseY, width/2, height/4) < 45) {
    ellipse(mouseX, mouseY, 25, 25);
}

```

to judge whether mouse was clicked in the right place. You only want to draw the ellipse in this case!

---

<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: [March 12, 2019, 1:03am UTC](https://discourse.processing.org/t/new-to-p5-basic-object-question/9207/3 "2019-03-12T01:03:02Z")

</div>

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

---

<div class="post-metadata">

### Author: ![cryptogee](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/cryptogee/32/4099_2.png) [@cryptogee](https://discourse.processing.org/u/cryptogee)
#### Post date: [March 12, 2019, 5:11pm UTC](https://discourse.processing.org/t/new-to-p5-basic-object-question/9207/4 "2019-03-12T17:11:55Z")

</div>

Many, many, many thanks!
