Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 14:08 19 Apr 2024 Privacy Policy
Jump to

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: Canada
Posts: 1082
Posted: 09:35pm 29 Nov 2020
Copy link to clipboard 
Print this post

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 States
Posts: 430
Posted: 12:15am 30 Nov 2020
Copy link to clipboard 
Print this post

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 States
Posts: 324
Posted: 01:00am 30 Nov 2020
Copy link to clipboard 
Print this post

  mclout999 said  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


GWBASIC (for PC clones) and BASICA (for genuine IBM PCs) had commands like that.
 
chris
Regular Member

Joined: 24/08/2020
Location: United Kingdom
Posts: 54
Posted: 03:28pm 30 Nov 2020
Copy link to clipboard 
Print this post

+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 States
Posts: 3008
Posted: 03:35pm 30 Nov 2020
Copy link to clipboard 
Print this post

  chris said  +1 for a fill command being added. Preferably with dither patterns.

Can you explain "dither patterns"?
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8566
Posted: 04:15pm 30 Nov 2020
Copy link to clipboard 
Print this post

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 States
Posts: 430
Posted: 04:31pm 30 Nov 2020
Copy link to clipboard 
Print this post

  matherp said  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
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: Canada
Posts: 1082
Posted: 06:49pm 30 Nov 2020
Copy link to clipboard 
Print this post

  matherp said  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

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 Kingdom
Posts: 8566
Posted: 09:33am 01 Dec 2020
Copy link to clipboard 
Print this post

  Quote  Alas, neither of these does the job of a fill command.


Check 5.06.00b10
 
William Leue
Guru

Joined: 03/07/2020
Location: United States
Posts: 381
Posted: 03:19pm 07 Dec 2020
Copy link to clipboard 
Print this post

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


To reply to this topic, you need to log in.

© JAQ Software 2024