# Color transformation and resizing from center

**URL:** <https://forum.kirupa.com/t/color-transformation-and-resizing-from-center/248971>\
**Category:** Uncategorized\
**Created:** [January 14, 2008, 6:56am UTC](https://forum.kirupa.com/t/color-transformation-and-resizing-from-center/248971 "2008-01-14T06:56:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![substance](https://avatars.discourse-cdn.com/v4/letter/s/c6cbf5/32.png) [@substance](https://forum.kirupa.com/u/substance)\
**Post date:** [January 14, 2008, 6:56am UTC](https://forum.kirupa.com/t/color-transformation-and-resizing-from-center/248971/1 "2008-01-14T06:56:12Z")

</div>

I’m working on health bars for a small game i’m working on and I have run into two small problems.

The first is the sizing of the healthbar itself, doing something like this

```php
healthbar.width = (currentHealth / maxHealth) * maxSize

```

Will move the bar, but I want it to scale from the center. If I understand correctly, resizing scales from the registration point but how I would change the registration point of a dynamic shape?

The second thing is the re-coloring of the bar as you lose health. Right now I’m using

```php
hbar.transform.colorTransform = new ColorTransform(1, 1, 1, 1, ((maxHealth - currentHealth) / maxHealth ) * 255, (currentHealth / maxHealth) * 255, 0, 0);

```

Which works OK but I want it to work something like this:

> at full health (100%) there should be 255 green, 0 red and 0 blue  
> at half health (50%) there should be 255 green, 255 red and 0 blue  
> at 0 health there should be 0 green, 255 red and 0 blue

Here’s a chart for the visual people.

```php

l <0----------50----------100>
RED 255 255 0
GREEN 0 255 255

```
