# Collision detection sketch running extremely slow

**URL:** <https://discourse.processing.org/t/collision-detection-sketch-running-extremely-slow/40844>\
**Category:** Coding Questions\
**Created:** [February 6, 2023, 1:33pm UTC](https://discourse.processing.org/t/collision-detection-sketch-running-extremely-slow/40844 "2023-02-06T13:33:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bdooley](https://avatars.discourse-cdn.com/v4/letter/b/7cd45c/32.png) [@bdooley](https://discourse.processing.org/u/bdooley)\
**Post date:** [February 6, 2023, 1:33pm UTC](https://discourse.processing.org/t/collision-detection-sketch-running-extremely-slow/40844/1 "2023-02-06T13:33:43Z")

</div>

Hi,

I’m working on a sketch drawing circles and squares that slowly fall to the bottom of the window and begin to stack. I first got things to work using matter.js here:

[https://editor.p5js.org/bdooley7/sketches/yY5Ej6Sso](https://editor.p5js.org/bdooley7/sketches/yY5Ej6Sso)

and now am trying to get the same effect without it:

[https://editor.p5js.org/bdooley7/sketches/1-AXB2LKk](https://editor.p5js.org/bdooley7/sketches/1-AXB2LKk)

I am now running into a problem with the sketch running extremely slow/glitchy after drawing even just one or two shapes. I think this may have to do with the shapes being added in the draw() function every X frame and then checking for collisions, although I am not sure…

I would greatly appreciate any help. Thank you in advance!
