AhmedElyamani Posted January 9, 2012 Share Posted January 9, 2012 Hello I was wondering how does the Color Bucket tool Works? Like if i want my plugin to include some kind of filling the area of the same color. like this maybe: Thanks A lot ! if you can't help just please tell me an idea or anything , i greatly appreciate it Ahmed Quote Link to comment Share on other sites More sharing options...
nitenurse79 Posted January 9, 2012 Share Posted January 9, 2012 This link Here explains the paintbucket Ahmed. Hope this of use to you Quote Link to comment Share on other sites More sharing options...
jim100361 Posted January 10, 2012 Share Posted January 10, 2012 If you're working utilizing layers that have 3 complete circles, when you use the paint bucket, it will fill the entire circle. The layers will need to be merged together so that the lines of the circles act as a sort of "barrier" for the paint and in this way it won't flood over into the "football" shaped (for lack of a better term) intersecting areas (as in your example). Also, the paint bucket works with the primary selected color. So, since you already drew the circles with black, simply select the paintbucket tool and then click inside the area you want filled and it will fill with the black. To fill the other areas with other colors, simply change the primary color and click on your next area. Quote Link to comment Share on other sites More sharing options...
Ego Eram Reputo Posted January 10, 2012 Share Posted January 10, 2012 I believe that Ahmed is asking how the Fill tool works programmatically. I'm guessing that the pixels neighboring the 'location' are recursively checked for similarity to the 'location' pixel (remember there is a tolerance slider to consider). If neighboring pixels are within tolerance, they are added to a list and also recursively checked for neighboring pixels. I'm sure those with more in depth knowledge will be able to provide a more accurate description. Quote ebook: Mastering Paint.NET | resources: Plugin Index | Stereogram Tut | proud supporter of Codelab plugins: EER's Plugin Pack | Planetoid | StickMan | WhichSymbol+ | Dr Scott's Markup Renderer | CSV Filetype | dwarf horde plugins: Plugin Browser | ShapeMaker Link to comment Share on other sites More sharing options...
AhmedElyamani Posted January 10, 2012 Author Share Posted January 10, 2012 Thanks for help Nitenurse39 and jim100361 ,But like EER said , i need it programmatically. I believe that Ahmed is asking how the Fill tool works programmatically. I'm guessing that the pixels neighboring the 'location' are recursively checked for similarity to the 'location' pixel (remember there is a tolerance slider to consider). If neighboring pixels are within tolerance, they are added to a list and also recursively checked for neighboring pixels. I'm sure those with more in depth knowledge will be able to provide a more accurate description. Thanks a lot EER , i understand this point , but how would the loop look like ? i first tried to use for loops but it was very slow , I need to know how to do the loop Quote Link to comment Share on other sites More sharing options...
Rick Brewster Posted January 10, 2012 Share Posted January 10, 2012 Just search for "flood fill algorithm". Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html Link to comment Share on other sites More sharing options...
AhmedElyamani Posted February 8, 2012 Author Share Posted February 8, 2012 Just search for "flood fill algorithm". Thanks. okay i've been able to write a somewhat method for my Flood Fill Algorithm , however , i still only need to understand the Tolerance Part. This line of Pseudo code that needs edits : // this checks for the exact same color if (color!=pcolor) {exit;} Okay, How is the Tolerance probably done ? Kinda tried to use google but failed.. Thanks again. Quote Link to comment Share on other sites More sharing options...
Rick Brewster Posted February 8, 2012 Share Posted February 8, 2012 The algorithm looks at a pixel and determines whether to fill it and keep going, or to stop. The tolerance values determines the cut-off point for that. Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html Link to comment Share on other sites More sharing options...
AhmedElyamani Posted February 8, 2012 Author Share Posted February 8, 2012 The algorithm looks at a pixel and determines whether to fill it and keep going, or to stop. The tolerance values determines the cut-off point for that. sorry, but probably i don't understand . okay this is my pseudo code: { //pseudo code //argument0 = x //argument1 = y //argument2 is the color to fill with // old color is the color of the mouse pixel when click , it's set before // exit; means stop executing for (i = 0; i < room_width; i+=1) for (h = 0; h < room_height; h+=1) {floodChecked[i,h] = false;} /*this line is what needs edit*/ if (getpixel(argument0,argument1) !=/*as said above , old color is the color of the first pixel when mouse clicking...i want to reaplace that with tolerance*/ oldColor) exit; if (argument0<0)||(argument0>rect.Width)||(argument1<0)||(argument1>rect.Height) exit; if (floodChecked[argument0,argument1]== true ) exit; /*color*/setColor(argument2); /*drawing*/drawPixel(argument0,argument1); floodChecked[argument0,argument1]=true // this recalls the script DrawFlood(argument0-1,argument1,argument2) DrawFlood(argument0+1,argument1,argument2) DrawFlood(argument0,argument1+1,argument2) DrawFlood(argument0,argument1-1,argument2) } i just want to replace that line or that variable "oldcolor" , with a somewhat lines that applies tolerance . How ? I mean , what is the relationship between the original color and the other color ,say like tolerance 50% . Thanks . Ahmed. Quote Link to comment Share on other sites More sharing options...
Rick Brewster Posted February 8, 2012 Share Posted February 8, 2012 Right now your similarity function is just simple equality, e.g. (A == B ) ? proceed : stop. I think Paint.NET uses Euclidean distance between the pixels. If you imagine R, G, B as being X, Y, Z values then you want the length of the line between the two pixels in 3-dimensional space, e.g. sqrt((r1-r0)^2 + (g1-g0)^2 + (b1-b0)^2). The maximum distance between any two points (colors) will be the distance between white and black, or sqrt((255-0)^2 + (255-0)^2 + (255-0)^2), or ~441.67. If you then take this distance and divide by ~441.67 you'll end up with a value between 0 and 1. If your tolerance is 0 to 100, then multiply by 100 to get a value from 0-100. Then, compare this value to tolerance and if it's less than that you proceed, else you stop. Smaller numbers mean more similarity, larger numbers mean less similarity. (A == B ) ? proceed : stop turns into ((Distance(A, B ) / Distance(White, Black) * 100) < Tolerance ? proceed : stop That's the gist of it, in pseudo code anyway. You'll have to experiment to find what exactly works well. Maybe something other than Euclidean distance is what you actually want, but the key is to transform the problem into one that uses a similarity function. 2 Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.