leave marks by drawing on texture

Hey all :slight_smile:
I’m trying to write a script, where you can leave marks on texture in a specific color. I already found a script from Eric
which is able to draw circles on a texture:

static function Circle (tex : Texture2D, cx : int, cy : int, r : int, col : Color) {
var y = r;
var d = 1/4 - r;
var end = Mathf.Ceil(r/Mathf.Sqrt(2));

for (x = 0; x <= end; x++) {
tex.SetPixel(cx+x, cy+y, col);
tex.SetPixel(cx+x, cy-y, col);
tex.SetPixel(cx-x, cy+y, col);
tex.SetPixel(cx-x, cy-y, col);
tex.SetPixel(cx+y, cy+x, col);
tex.SetPixel(cx-y, cy+x, col);
tex.SetPixel(cx+y, cy-x, col);
tex.SetPixel(cx-y, cy-x, col);

d += 2x+1;
if (d > 0) {
d += 2 - 2
y–;
}
}
}

The problem is, that they are just circles and I would like to fill them.
He said a flood-fill algorithm would work, but it’s my first time working
with unity, so I would be very pleased if anybody could tell me how to
translate this algorithm to unity, particularly to the code above…

Thanks a lot for any kind of help.

Lena

Hi,

try something like that :

void FillCircle (Texture2D tex,int cx ,int cy,int r,Color col) {
for (int x = -r; x < r ; x++)
{
int height = (int)Mathf.Sqrt(r * r - x * x);
for (int y = -height; y < height; y++)
{
tex.SetPixel(x + cx, y + cy, col);
}
}
}