# How to get the color of a square or rectangle etc

**URL:** <https://discourse.processing.org/t/how-to-get-the-color-of-a-square-or-rectangle-etc/46851>\
**Category:** Beginners\
**Created:** [August 4, 2025, 6:47pm UTC](https://discourse.processing.org/t/how-to-get-the-color-of-a-square-or-rectangle-etc/46851 "2025-08-04T18:47:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![krczyk](https://avatars.discourse-cdn.com/v4/letter/k/f0a364/32.png) [@krczyk](https://discourse.processing.org/u/krczyk)\
**Post date:** [August 4, 2025, 6:47pm UTC](https://discourse.processing.org/t/how-to-get-the-color-of-a-square-or-rectangle-etc/46851/1 "2025-08-04T18:47:58Z")

</div>

size(500, 500);  
background(111, 0, 0);  
fill(0, 125, 0);  
square(100, 100, 100);  
color c = get(150, 150);  
println(red(c));  
println(green(c));  
println(blue(c));

The result of get() is the color of the background, not of the square.

---

<div class="post-metadata">

**Author:** ![ProcessingOrg](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/processingorg/32/18341_2.png) [@ProcessingOrg](https://discourse.processing.org/u/ProcessingOrg)\
**Post date:** [August 4, 2025, 8:08pm UTC](https://discourse.processing.org/t/how-to-get-the-color-of-a-square-or-rectangle-etc/46851/2 "2025-08-04T20:08:10Z")

</div>

You might want to try adding `pixelDensity(1)` at the top of your sketch.

---

<div class="post-metadata">

**Author:** ![krczyk](https://avatars.discourse-cdn.com/v4/letter/k/f0a364/32.png) [@krczyk](https://discourse.processing.org/u/krczyk)\
**Post date:** [August 4, 2025, 8:52pm UTC](https://discourse.processing.org/t/how-to-get-the-color-of-a-square-or-rectangle-etc/46851/3 "2025-08-04T20:52:09Z")

</div>

Voila! Thank you very much!
