# How to make an object move in p5 - I want to create the object when the mouse is clicked then it should bounce off the walls. I am a beginner to p5 and am completing this as a homework assignment please help

**URL:** <https://discourse.processing.org/t/how-to-make-an-object-move-in-p5-i-want-to-create-the-object-when-the-mouse-is-clicked-then-it-should-bounce-off-the-walls-i-am-a-beginner-to-p5-and-am-completing-this-as-a-homework-assignment-please-help/50382>\
**Category:** Coding Questions\
**Created:** [December 1, 2026, 11:52am UTC](https://discourse.processing.org/t/how-to-make-an-object-move-in-p5-i-want-to-create-the-object-when-the-mouse-is-clicked-then-it-should-bounce-off-the-walls-i-am-a-beginner-to-p5-and-am-completing-this-as-a-homework-assignment-please-help/50382 "2026-12-01T11:52:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![harshini.kumaran23](https://avatars.discourse-cdn.com/v4/letter/h/eada6e/32.png) [@harshini.kumaran23](https://discourse.processing.org/u/harshini.kumaran23)\
**Post date:** [December 1, 2026, 11:52am UTC](https://discourse.processing.org/t/how-to-make-an-object-move-in-p5-i-want-to-create-the-object-when-the-mouse-is-clicked-then-it-should-bounce-off-the-walls-i-am-a-beginner-to-p5-and-am-completing-this-as-a-homework-assignment-please-help/50382/1 "2026-12-01T11:52:11Z")

</div>

let XCoord;  
let YCoord;  
let molecules = ;  
let i;

function setup() {  
createCanvas(windowWidth, windowHeight);  
background(0);  
// XCoord = frameCount % width

}

function mousePressed() {  
XCoord = mouseX;  
YCoord = mouseY;  
hydrochloric\_acid()

}

function update\_position(m) {  
velocity = p5.Vector.random2D().mult(random(2, 5));  
XCoord = XCoord + i;  
YCoord = YCoord + i;  
i++;  
if(i\>600) {  
i=0;  
}  
}

function hydrochloric\_acid(x, y, diameter, rgb) {  
fill(255, 140, 255)  
ellipse(XCoord, YCoord, 50)  
fill(160, 28, 252)  
ellipse(XCoord + 26.5, YCoord + 26.5, 25)  
update\_position()

}

var cl = {

r: 0,  
g: 0,  
b: 0

}
