# Change the scale of a sprite

**URL:** <https://forum.code.org/t/change-the-scale-of-a-sprite/15898>\
**Category:** Unit and Lesson Discussion\
**Tags:** csd-unit-3, csd-unit-3-lesson-9\
**Created:** [April 27, 2018, 8:18pm UTC](https://forum.code.org/t/change-the-scale-of-a-sprite/15898 "2018-04-27T20:18:51Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![kammie.dill](https://avatars.discourse-cdn.com/v4/letter/k/eb8c5e/32.png) [@kammie.dill](https://forum.code.org/u/kammie.dill)\
**Post date:** [April 27, 2018, 8:18pm UTC](https://forum.code.org/t/change-the-scale-of-a-sprite/15898/1 "2018-04-27T20:18:51Z")

</div>

I have a question about the scale of sprites. We were playing around with making the sprites grow and shrink. I noticed that when you are decreasing the value of the scale property, once the value becomes a negative number, the sprite begins to get bigger.

So instead of adding and subtracting from the scale, I told my students to multiply and divide.  
For example:  
To grow the sprite - sprite.scale = sprite.scale \* 1.05;  
To shrink the sprite - sprite.scale = sprite.scale / 1.05;

That way, the scale never becomes a negative number and continues to shrink infinitely.

My question is, why does the sprite get larger once the number is negative? Does the code actually take the absolute value of the number? Just curious.

---

<div class="post-metadata">

**Author:** ![bradleywellsashley](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/bradleywellsashley/32/522_2.png) [@bradleywellsashley](https://forum.code.org/u/bradleywellsashley)\
**Post date:** [April 30, 2018, 12:34am UTC](https://forum.code.org/t/change-the-scale-of-a-sprite/15898/2 "2018-04-30T00:34:17Z")

</div>

Kammie,

Calling in backup - will hopefully have an answer for you soon!

Brad

---

<div class="post-metadata">

**Author:** ![jold](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/jold/32/5811_2.png) [@jold](https://forum.code.org/u/jold)\
**Post date:** [April 30, 2018, 6:41pm UTC](https://forum.code.org/t/change-the-scale-of-a-sprite/15898/3 "2018-04-30T18:41:47Z")

</div>

I sort of assumed it took the absolute value of the number. Its fun when students subtract from the value in the draw loop and then all sudden the sprite gets bigger. Its a great opportunity to talk about math with students who don’t always enjoy math class.

---

<div class="post-metadata">

**Author:** ![andrea.burgess](https://avatars.discourse-cdn.com/v4/letter/a/fbc32d/32.png) [@andrea.burgess](https://forum.code.org/u/andrea.burgess)\
**Post date:** [March 26, 2020, 10:12pm UTC](https://forum.code.org/t/change-the-scale-of-a-sprite/15898/4 "2020-03-26T22:12:34Z")

</div>

Did we ever get a definitive answer on this?

---

<div class="post-metadata">

**Author:** ![andrea.burgess](https://avatars.discourse-cdn.com/v4/letter/a/fbc32d/32.png) [@andrea.burgess](https://forum.code.org/u/andrea.burgess)\
**Post date:** [March 26, 2020, 10:12pm UTC](https://forum.code.org/t/change-the-scale-of-a-sprite/15898/5 "2020-03-26T22:12:45Z")

</div>

Did we ever get a definitive answer on this?

---

<div class="post-metadata">

**Author:** ![mwood](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/mwood/32/4941_2.png) [@mwood](https://forum.code.org/u/mwood)\
**Post date:** [March 27, 2020, 3:33am UTC](https://forum.code.org/t/change-the-scale-of-a-sprite/15898/6 "2020-03-27T03:33:21Z")

</div>

I don’t know that I can say that my answer is definitive, but in my experience, it doesn’t just get bigger, but it flips the sprite inside out. There are other ways around it such as using a conditional statement that tells the sprite to shrink until the scale is 0, but I have seen some unexpected results before and have had to help some of my students realize that they needed to make sure the value didn’t get below zero or have a contingency plan in place if it did happen.

Mike

---

<div class="post-metadata">

**Author:** ![nixnaxa](https://avatars.discourse-cdn.com/v4/letter/n/eb9ed0/32.png) [@nixnaxa](https://forum.code.org/u/nixnaxa)\
**Post date:** [November 2, 2022, 11:18am UTC](https://forum.code.org/t/change-the-scale-of-a-sprite/15898/7 "2022-11-02T11:18:17Z")

</div>

Yes, even i have seen that when we reduce the value of scale as in “sprite.scale = sprite.scale - 0.005” or something like that, it doesn’t reach 0 . Somewhere through the course of this repeated reduction it changes its value like below: Not sure why…curious about this behaviour

- 0.3765

- 0.3715

- 0.3665

- 0.3615

- 0.3565

- 0.3515

- 0.3465

- 0.34149999999999997

- 0.33649999999999997

- 0.33149999999999996

- 0.32649999999999996

- 0.32149999999999995

- 0.31649999999999995

- 0.31149999999999994

- 0.30649999999999994

- 0.30149999999999993

- 0.29649999999999993

---

<div class="post-metadata">

**Author:** ![mwood](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/mwood/32/4941_2.png) [@mwood](https://forum.code.org/u/mwood)\
**Post date:** [November 2, 2022, 2:17pm UTC](https://forum.code.org/t/change-the-scale-of-a-sprite/15898/8 "2022-11-02T14:17:04Z")

</div>

@nixnaxa,

Yes. You have discovered that computers actually have a hard time doing math with decimals. [Here’s an article with more information on that!](https://blog.codinghorror.com/why-do-computers-suck-at-math/)

Mike

---

<div class="post-metadata">

**Author:** ![nixnaxa](https://avatars.discourse-cdn.com/v4/letter/n/eb9ed0/32.png) [@nixnaxa](https://forum.code.org/u/nixnaxa)\
**Post date:** [November 4, 2022, 5:25am UTC](https://forum.code.org/t/change-the-scale-of-a-sprite/15898/9 "2022-11-04T05:25:05Z")

</div>

Thank you so much for the reply!  
Read through the article you shared, very interesting!  
Thanks again 🙂

---

<div class="post-metadata">

**Author:** ![deboltbrittany](https://avatars.discourse-cdn.com/v4/letter/d/e9a140/32.png) [@deboltbrittany](https://forum.code.org/u/deboltbrittany)\
**Post date:** [October 5, 2023, 8:18pm UTC](https://forum.code.org/t/change-the-scale-of-a-sprite/15898/10 "2023-10-05T20:18:47Z")

</div>

Isn’t this happening because once the sprite reaches 0, it is then subtracting a negative number which cancels out into adding?
