ID:1953955
 
(See the best response by Kaiochao.)
Code:
mob/proc
ChannelSpell(_words)
src.icon_state = "casting"
var _verdict = TRUE
//show channeling bar if(_words >= 30)
while(_words--)
//adjust channeling bar
if(src.dead)//cancel or interrupts
_verdict = FALSE
break
sleep(src.castSpeed)//starts at 20 can level-up to 1

src.icon_state = null
return _verdict


Problem description:


Looking to create something much like either of the above two examples. It doesn't have to be fancy looking. Just something resource-efficient as it will be called quite often.

I can think of 2 ways to do it (both using image()):
1) Use drawbox(), drawing as % per loop.
2) Use an icon overlay datum, with states named 1-100 (representing percent values), and changing as needed per loop.

But as this bar will appear any time the spell is medium to long in cast-time, I'm concerned modifying icon_state so often will be expensive? Is there a better way? Are my concerns rational?

(Side note, I'm assuming there are no major concerns with the proc as a whole?)
Best response
Using a single square icon and a single call to animate(), you can make its size change smoothly from any width to any other width. I would also make this square either a HUD object or an image object.

You should experiment with transform matrices. They let you very efficiently resize and rotate graphics without having to create and save each frame as an icon.
That is actually a great solution. Use animate and transform so that its just called once per spell.

Thanks!

Side question (optional) about matrices, and I realise google and the reference are both things, but is there a recommended place to learn how they work? Esp. with client.color using ostensibly the same mechanic.
In response to ZOMGbies
client.color and atom.color use a color matrix to transform pixels from one color space to another.

atom.transform uses affine transformation to effectively transform the positions of each pixel. This diagram shows examples of the kinds of transformations you can do in DM.

The matrices in that diagram are represented in DM by a /matrix object with variables a through f:
a b c
d e f
0 0 1

Translate, Scale, and Rotate are all /matrix procs, which you can look up in the DM Reference. Shear isn't, but it can be done by creating a matrix with non-zero b or d elements.

They are both matrices, although the color matrix can be different sizes so in BYOND they are represented by a /list object, where the transformation matrix is a /matrix object. The mathematics is exactly the same between them.