ID:273731
 
I'm not sure if there is a library or demo on this (and if there is, please point it out to me), but I would like to know how to dynamically create an icon. For example, let's say I wanted to create myself a grass icon, but I am too lazy to icon it the traditional way, and wanted to create a grass icon through the programming using a bunch of randomly place multi-green-shaded pixels. How would I go about doing this?

I took a quick look at the icon procs listed by the Reference and saw the GetPixel proc. I think I would be using this proc, but am unsure of how to utilize it. This is something I have never done, sadly.
For example, for a grass icon, you might use the DrawBox() proc and fill it with random values of green.

for every coordinate in icon
decide on a random, green color value
use DrawBox to fill that coordinate with a rectangle of that color
In response to Toadfish
And then how would I save such icon as an actual .dmi file?

Would I do this to create the random values?
var/icon/i = new
i.DrawBox(rgb(0,rand(100,200),0),1,1,32,32)
In response to Spunky_Girl
I'm pretty sure we have such procs as ftp for saving. You would do something like "usr << ftp(icon file)".

To decide on a random color value, you can do something like rgb(0,rand(100,200),0). However, you want to randomise the value again for every box. So no, your example won't work, it will create one big green rectangle. You need to loop through every coordinate.
In response to Toadfish
var/icon/i = new
for(var/y=1,y<=32,y++)
for(var/x=1,x<=32,x++)
i.DrawBox(rgb(0,rand(100,200),0),x,y)
usr<<ftp(i,"Dynamic Grass.dmi")

This is all I would have to do?

EDIT
The ftp proc is not what I want, I don't think. It didn't work. I tried doing a savefile instead, but that did not work either.
var/savefile/s = new("Dynamic Grass.dmi")
s << i
In response to Spunky_Girl
    var/icon/i = new('blank.dmi') // icon with one empty icon state
for (var/x = 1, x <= 32, x++)
for (var/y = 1, y <= 32, y++)
var/random = rgb(0, rand(100,200), 0)
i.DrawBox(random, x, y)
usr << ftp(i, "grass.dmi")
In response to Toadfish
Ohhh... I was using the same file that that I did in the icon/new proc, in the ftp proc. Thank you so much, Toadfish :)