ID:142351
 
Code:
map_to_icon
proc
GenerateState(x, y, z)
var/list/pixels[1024]

var
pixel_x = x
pixel_y = y

for(var/a = 1, a <= 1024, a ++)
pixels[a] = GenerateTurfColor(pixel_x, pixel_y, z)

pixel_x += x_ratio
if(pixel_x > (32 * x_ratio))
pixel_x = x

pixel_y += y_ratio

var
x_shift = 0
y_shift = 0

icon/state = new('Templates.dmi', "blank")

for(var/a in pixels)
var/icon/pixel = GeneratePixel(x_shift, y_shift, a)
state.Blend(pixel, ICON_ADD)

world << "\t\icon[pixel]"
world << "\t\icon[state]\n"

x_shift ++
if(x_shift >= 32)
x_shift = 0

y_shift ++

AddState(state)
total_states ++

GeneratePixel(x, y, rgb)
var/icon/i = new('Templates.dmi', "pixel")

i.Shift(EAST, x)
i.Shift(NORTH, y)
i.Blend(rgb, ICON_ADD)

return i


Problem description:
Alright, the pixel is generated (I've made a 16x16 square, actually, to test), and its getting shifted and modified with the right color. Problem is, when I try to blend the icon with state, nothing happens. The modified pixel icon is output, but the state icon isn't.
The problem here might be the fact that you're using the ICON_ADD function. ICON_ADD will compare (much like binary OR) the two pixels of each icon, and if the pixel in either icon is transparent, the result will be transparent.

I believe if you use the ICON_OR (which, contrary to the name, is like binary AND) function, you'll get the desired results.
In response to Volte
Actually, that made me look back on my previous version of this. Turns out ICON_OVERLAY is what I used.
I sense two problems with your code. Both are subtle.

Popisfizzy wrote:
Code:
>               if(pixel_x > (32 * x_ratio))
> pixel_x = x
>
> pixel_y += y_ratio


In this snippet, you're checking if(pixel_x > (32 * x_ratio)). This would be fine if pixel_x started at 1, but it actually starts at x, so I believe you want to check if(pixel_x >= (x + 32*x_ratio)), if my math is correct.


>           for(var/a in pixels)
> var/icon/pixel = GeneratePixel(x_shift, y_shift, a)
> state.Blend(pixel, ICON_ADD)


The problem here is a simple misuse of the second argument to icon.Blend(). You want to use ICON_OVERLAY; instead, you're using ICON_ADD, which means that the transparent regions of the icons are ORed together, and if either is transparent on a given pixel (presumably, state will be, considering it comes from a blank state), the resulting pixel is transparent.

Edit: Rats, I started this post before Volte posted his, and he covered one of my two points before I managed to get it in. Cheater!