ID:822149
 
(See the best response by Alathon.)
Code:
turf
var/currentc="#FFFFFF"
proc
Flood()

var/O = src.currentc
var/icon/G = icon(src.icon)
src.icon = G.Blend(usr.coloring, ICON_OVERLAY)
src.icon = G
var/turf/Blank/N = locate(src.x+1, src.y, src.z)
var/turf/Blank/Z = locate(src.x, src.y+1, src.z)
var/turf/Blank/X = locate(src.x-1, src.y, src.z)
var/turf/Blank/Y = locate(src.x, src.y-1, src.z)
if(N)
if(N.currentc == O)
var/icon/F = icon(N.icon)
N.icon = F.Blend(usr.coloring, ICON_OVERLAY)
N.icon = F
N.Flood()
if(Z)
if(Z.currentc == O)
var/icon/F = icon(Z.icon)
Z.icon = F.Blend(usr.coloring, ICON_OVERLAY)
Z.icon = F
Z.Flood()
if(X)
if(X.currentc == O)
var/icon/F = icon(X.icon)
X.icon = F.Blend(usr.coloring, ICON_OVERLAY)
X.icon = F
X.Flood()
if(Y)
if(Y.currentc == O)
var/icon/F = icon(Y.icon)
Y.icon = F.Blend(usr.coloring, ICON_OVERLAY)
Y.icon = F
Y.Flood()


Problem description:
Basically what happens here is that a certain turf gets it's color change through the blend command, and it changes the colors of the surrounding turfs if they have the same color.
This ends up with a straight line going right or if I place a spawn() before each part, it is extremely slow.

So what you have here, is recursion, and possibly an infinite loop.

if(N) will call N.Flood, in N.Flood it will call N.Flood again until all of the Ns are done. It will then go and do the Z.Flood, The Z.Flood will call N.Flood, which will probably call N.Flood (until it runs out), and Z.Flood. (You get the point?)

Now when you spawn it, it does the same amount of work, but it puts them in a process queue, so it runs really slow. Icon processes really are not the fastest to begin with, but with the possible recursion and looping, it will slow it down all the more.

I think in this case, I would add all the turfs to a list (if its in the list no need to call flood on it again), color just one icon, and then loop through all the turfs in the list to change their icon to the new icon. (So minimal icon processes also.)

I'm not sure if this solution would work for you, so let me know if it doesn't and you want some help coming up with one to suit you.
I actually just realized that my code was wrong. I think there is currently noway to make it work without lag.
Adding these turfs to a certain turfs would also need a loop to add the surrounding ones.
Besides, what I meant here is a flood like the one in the paint and all. So if an unfilled circle is drawn, and the inner color is different from the color of the circle's boundary, and so it colors the inside, yet not the circle's boundary and the outside/surrounding.
In response to Alitron123 (#2)
Best response
You don't seem to be setting 'currentc' for the turfs that you color. I'd suggest extracting the coloring logic out into a separate proc, and using that to color, so that you can't forget to do so again :)
Yes, that is exactly why my code was screwed.
Don't forget to ignore flood-fill commands started on a turf that is already the selected color, or your current setup will still create an infinite loop.

Also, does each turf actually have a different icon? Or are they all just square "pixel" icons? If the latter, I would suggest having them all share one blended icon, instead of re-blending for each turf.
Yeah, they all have the same icons. I figured the problem, it is now working well, but it is a bit laggy. I am going to edit a bit until I am able to get it to work.