Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : CMM2: Fill Command?
Author | Message | ||||
vegipete Guru Joined: 29/01/2013 Location: CanadaPosts: 1082 |
Would it be possible to have a graphics fill command? The simplest command would look like "FILL x,y,colour" It would, on the active write page, change the pre-existing colour at x,y to the specified colour, then recursively change every adjacent pixel (up/down/left/right) with the same pre-existing colour as the initial x,y to the new colour. The following would work, except of course it overflows the MMBasic recursion depth in no time. MMBASIC code: SUB FILL(x,y,col) oldcol = PIXEL(x,y) PIXEL(x,y,col) IF PIXEL(x,y-1) = oldcol THEN FILL(x,y-1,col) IF PIXEL(x,y+1) = oldcol THEN FILL(x,y+1,col) IF PIXEL(x-1,y) = oldcol THEN FILL(x-1,y,col) IF PIXEL(x+1,y) = oldcol THEN FILL(x+1,y,col) END SUB A slightly more advanced version would change any colour until a boundary colour is reached. This version is dangerous because any hole in the boundary would allow the flood to really go nuts. A variation on this, perhaps of minimal value, would change all pixels of a given colour in a region (a box or full screen or rounded box or circle or ?) to a new colour. This differs from the previous in that the colour to change might not be contiguous. This version could do things like changing text colour in a region, or even the background colour behind text. The PIXEL_AND/OR/XOR could kind of do this, but not very easily. Or maybe not. And a "IF PIXEL(x,y)=oldcol THEN PIXEL x,y,col" in a loop is painfully slow. Just some thoughts. Visit Vegipete's *Mite Library for cool programs. |
||||
mclout999 Guru Joined: 05/07/2020 Location: United StatesPosts: 430 |
I liked flood fill commands that also allowed pattern fills(tiling of a graphic), or directional radiant fills. Can anyone remember Basic with those kinds of fills? I remember DarkBasic Pro had these kinds of fills.(now open source if you want to check it out.) https://github.com/TheGameCreators/Dark-Basic-Pro Edited 2020-11-30 10:58 by mclout999 |
||||
toml_12953 Guru Joined: 13/02/2015 Location: United StatesPosts: 324 |
GWBASIC (for PC clones) and BASICA (for genuine IBM PCs) had commands like that. |
||||
chris Regular Member Joined: 24/08/2020 Location: United KingdomPosts: 54 |
+1 for a fill command being added. Preferably with dither patterns. As Vegipete said, filling pixel by pixel is going to be painfully slow in BASIC, so it's the type of general purpose graphic operation that seems to cry out for a custom command. |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3008 |
Can you explain "dither patterns"? PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8566 |
In 8 bit colour modes you can do what you want nearly instantaneously using the map command. You can also fill any described shape using the polygon command |
||||
mclout999 Guru Joined: 05/07/2020 Location: United StatesPosts: 430 |
Can someone provide some example code as that sounds interesting and useful but I haven't the foggiest how that would work. I will look at those commands but it would be nice to have a code example. Thanks. |
||||
vegipete Guru Joined: 29/01/2013 Location: CanadaPosts: 1082 |
Alas, neither of these does the job of a fill command. The map command changes how a every pixel of a given number is displayed. It doesn't change the value of a particular pixel, or group of contiguous pixels. The polygon command is only useful for known shapes. ----------- The intended use is the fill command in a paint program. It is a user level operation, not a programmer operation. So the programmer can't know what shape the user might choose to fill, whether there are islands in the filled region, whether other sections of the image have the same colour which won't be changed, etc. I'm still searching for good, non-recursive algorithm. I'm sure I remember something in an old magazine somewhere, I just haven't found it yet. Visit Vegipete's *Mite Library for cool programs. |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8566 |
Check 5.06.00b10 |
||||
William Leue Guru Joined: 03/07/2020 Location: United StatesPosts: 381 |
You can get around the recursion limit by implementing an explicit stack and using iteration instead of recursion. Any simply recursive algorithm can be made iterative. -Bill |
||||
Print this page |