im looking for a colour fill routine

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
User avatar
777
Manic Miner
Posts: 542
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

im looking for a colour fill routine

Post by 777 »

all the other routines just fill in one colour, i.e white. i need to be able to change the fill color form basic. any ideas? i would prefer a tap file if thats ok...
i started programming the spectrum when i was 8 :-

1 plot rnd*255,rnd*175
2 goto 1

http://zxspeccy.great-site.net/
User avatar
spider
Dynamite Dan
Posts: 1107
Joined: Wed May 01, 2019 10:59 am
Location: Derby, UK
Contact:

Re: im looking for a colour fill routine

Post by spider »

If you have a routine it might be easier to modify that to suit (possibly)

Assuming its a piece of code doing the 'filling' (probably an LDIR or suchlike) and you want to change it from Basic then in most cases the easy way would be to use a POKE or two to change the fill byte colour.

Would need to see the routine / link of it etc to see if its suitable to do this or not.
User avatar
777
Manic Miner
Posts: 542
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

Re: im looking for a colour fill routine

Post by 777 »

here

https://spectrumcomputing.co.uk/entry/2 ... ll_Routine

and heres another

Code: Select all

; scanline fill by John Metcalf
; call with d=x-coord, e=y-coord

; set end marker

fill:
  ld l,255
  push hl

; calculate bit position of pixel

nextrun:
  ld a,d
  and 7
  inc a
  ld b,a
  ld a,1
bitpos:
  rrca
  djnz bitpos
  ld c,b
  ld b,a

; move left until hitting a set pixel or the screen edge

seekleft:
  ld a,d
  or a
  jr z,goright
  dec d
  rlc b
  call scrpos
  jr nz,seekleft

; move right until hitting a set pixel or the screen edge,
; setting pixels as we go. Check rows above and below and
; save their coordinates to fill later if necessary

seekright:  
  rrc b
  inc d
  jr z,rightedge
goright:
  call scrpos
  jr z,rightedge
  ld (hl),a
  inc e
  call checkadj
  dec e
  dec e
  call checkadj
  inc e
  jr seekright

; check to see if there's another row waiting to be filled

rightedge:
  pop de
  ld a,e
  inc a
  jr nz,nextrun
  ret  

; calculate the pixel address and whether or not it's set

scrpos:
  ld a,e
  and 248
  rra
  scf
  rra
  rra
  ld l,a
  xor e
  and 248
  xor e
  ld h,a
  ld a,l
  xor d
  and 7
  xor d
  rrca
  rrca
  rrca
  ld l,a
  ld a,b
  or (hl)
  cp (hl)
  ret

; check and save the coordinates of an adjacent row

checkadj:
  sla c
  ld a,e
  cp 192
  ret nc
  call scrpos+1
  ret z
  inc c
  bit 2,c
  ret nz
  pop hl
  push de
  jp (hl)
i started programming the spectrum when i was 8 :-

1 plot rnd*255,rnd*175
2 goto 1

http://zxspeccy.great-site.net/
AndyC
Dynamite Dan
Posts: 1467
Joined: Mon Nov 13, 2017 5:12 am

Re: im looking for a colour fill routine

Post by AndyC »

"Colour" fill on a Spectrum is a messy, complicated business and you probably need to more accurately specify what you want. The attribute system means it isn't necessarily as simple as doing a standard fill routine because (depending on the specification) you may need to switch between filling in INK or PAPER pixels as you transition between characters. Also you may (or may not) need to check bounding conditions based not only on the state of a pixel bit but also what colour that translates to - e.g. if there is an area of Red PAPER next to and area of Red INK and I try to fill it with Green, do both areas end up Green? Are they both INK, both PAPER or a combination of the two...
User avatar
777
Manic Miner
Posts: 542
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

Re: im looking for a colour fill routine

Post by 777 »

AndyC wrote: Tue Jul 27, 2021 11:03 pm "Colour" fill on a Spectrum is a messy, complicated business and you probably need to more accurately specify what you want. The attribute system means it isn't necessarily as simple as doing a standard fill routine because (depending on the specification) you may need to switch between filling in INK or PAPER pixels as you transition between characters. Also you may (or may not) need to check bounding conditions based not only on the state of a pixel bit but also what colour that translates to - e.g. if there is an area of Red PAPER next to and area of Red INK and I try to fill it with Green, do both areas end up Green? Are they both INK, both PAPER or a combination of the two...
ok, thank you.
i started programming the spectrum when i was 8 :-

1 plot rnd*255,rnd*175
2 goto 1

http://zxspeccy.great-site.net/
User avatar
WhatHoSnorkers
Manic Miner
Posts: 264
Joined: Tue Dec 10, 2019 3:22 pm

Re: im looking for a colour fill routine

Post by WhatHoSnorkers »

there's a nice routine called "region fill" in "40 Best Machine Code Routines for the ZX Spectrum" by Hardman and Hewson. You get the bytes in, poke te x and y co-ordinates into the printer buffer and then call it. It will fill the area with INK pixels.

As other folks have said, this may not necessarily get you what you want. Say you have a black screen, white ink, representing outer space.

You want to draw a magenta circle (easy!) and then fill it in using the routine. It will do it, but depending on the size of the circle you'll need to either PLOT INK 3 a few times, or POKE the attribute bytes as the attribute bytes are not updated by the routine.
I have a little YouTube channel of nonsense
https://www.youtube.com/c/JamesOGradyWhatHoSnorkers
User avatar
TMD2003
Rick Dangerous
Posts: 2047
Joined: Fri Apr 10, 2020 9:23 am
Location: Airstrip One
Contact:

Re: im looking for a colour fill routine

Post by TMD2003 »

WhatHoSnorkers wrote: Fri Aug 06, 2021 8:34 pm there's a nice routine called "region fill" in "40 Best Machine Code Routines for the ZX Spectrum" by Hardman and Hewson. You get the bytes in, poke te x and y co-ordinates into the printer buffer and then call it. It will fill the area with INK pixels.
This flood fill routine is all you'll ever need. I can confirm it works flawlessly.
Spectribution: Dr. Jim's Sinclair computing pages.
Features my own programs, modified type-ins, RZXs, character sets & UDGs, and QL type-ins... so far!
User avatar
WhatHoSnorkers
Manic Miner
Posts: 264
Joined: Tue Dec 10, 2019 3:22 pm

Re: im looking for a colour fill routine

Post by WhatHoSnorkers »

Image

Image

I did these flags using the fill routine. set the ink and paper colour, draw three circles. fill.

set the ink and paper colour. draw four stars. fill.
I have a little YouTube channel of nonsense
https://www.youtube.com/c/JamesOGradyWhatHoSnorkers
Alcoholics Anonymous
Microbot
Posts: 194
Joined: Mon Oct 08, 2018 3:36 am

Re: im looking for a colour fill routine

Post by Alcoholics Anonymous »

Most fill subroutines are not practical as they are recursive depth first fills. Filling an area could take the entire memory of the machine to complete. The scan line fill by John Metcalf mentioned here is better as long as a true flood fill is not required as it could leave unfilled areas depending on whether the shape is convex or not.

I wrote this one many years ago ( https://spectrumcomputing.co.uk/entry/2 ... Flood_Fill ) after seeing Chris Pile's lightning fast filler in YS (I think?). I still remember his name all these years later because of how fast that thing ran. Chris Pile's was also not practical since it could possibly use a large chunk of the memory when filling but the speed impressed. His idea was to fill whole bytes instead of a pixel at a time. My version did the same but changed the algorithm to breadth first so memory requirement was only around 300 bytes for arbitrary fill regions. The version in the link above does a pattern fill instead of a solid fill and the cost is reduced speed (but it's still way faster than pixel at a time fillers) and increased memory requirement to about 900 bytes. Changing the code to apply colour is straightforward but as this thread is old, I'm only going to mention these things rather than do actual work :)
User avatar
Einar Saukas
Bugaboo
Posts: 3219
Joined: Wed Nov 15, 2017 2:48 pm

Re: im looking for a colour fill routine

Post by Einar Saukas »

Do you still have the solid fill version with lower memory requirement? It would be nice to add it to this entry too.

And perhaps instructions in PDF format. Nobody uses DOC anymore :)
User avatar
Nitrowing
Manic Miner
Posts: 632
Joined: Mon Sep 21, 2020 8:38 pm
Location: Cleethorpes

Re: im looking for a colour fill routine

Post by Nitrowing »

Einar Saukas wrote: Wed Sep 01, 2021 2:38 pm
And perhaps instructions in PDF format. Nobody uses DOC anymore :)
Ahem.
Doc can be opened and edited/converted to any format, PDF... not so much!
User avatar
Sokurah
Manic Miner
Posts: 289
Joined: Tue Nov 14, 2017 10:38 am
Contact:

Re: im looking for a colour fill routine

Post by Sokurah »

Einar Saukas wrote: Wed Sep 01, 2021 2:38 pm Nobody uses DOC anymore :)
True ... most people probaly use DOCX these days :lol:
Website: Tardis Remakes / Mostly remakes of Arcade and ZX Spectrum games.
My games for the Spectrum: Dingo, The Speccies, The Speccies 2, Vallation & Sqij.
Twitter: Sokurah
User avatar
TMD2003
Rick Dangerous
Posts: 2047
Joined: Fri Apr 10, 2020 9:23 am
Location: Airstrip One
Contact:

Re: im looking for a colour fill routine

Post by TMD2003 »

ODT all the way here.

The only DOC files I've dealt with recently were Quill files on the QL.
Spectribution: Dr. Jim's Sinclair computing pages.
Features my own programs, modified type-ins, RZXs, character sets & UDGs, and QL type-ins... so far!
User avatar
rastersoft
Microbot
Posts: 151
Joined: Mon Feb 22, 2021 3:55 pm

Re: im looking for a colour fill routine

Post by rastersoft »

TMD2003 wrote: Wed Sep 01, 2021 11:39 pm ODT all the way here.
That remembers me that, in Spanish, the letters "ODT" are spelled much like as the Spanish translation of "F*** you" :-D

It's the nerd version of "Eau D'Ete", an eau de cologne that started being announced some Christmas ago that, when pronounced in Spanish, also sounded like that... I can imagine the marketing people going crazy: "but... but... can we at least CHANGE the name here, in Spain? People will think that it's a present for a break up!" :lol: :lol: :lol:

(yes, pure off-topic, but...)
Alcoholics Anonymous
Microbot
Posts: 194
Joined: Mon Oct 08, 2018 3:36 am

Re: im looking for a colour fill routine

Post by Alcoholics Anonymous »

Einar Saukas wrote: Wed Sep 01, 2021 2:38 pm Do you still have the solid fill version with lower memory requirement? It would be nice to add it to this entry too.
And perhaps instructions in PDF format. Nobody uses DOC anymore :)
The source code is in fragments in the doc. I spent a few mins on it:

https://drive.google.com/file/d/0B6XhJJ ... TH7AK6hGiw

PDF in there and the tap file is updated to contain all the listings. fig-5 is the behaved black fill. fig-4 is the misbehaved but very fast black fill.
User avatar
Einar Saukas
Bugaboo
Posts: 3219
Joined: Wed Nov 15, 2017 2:48 pm

Re: im looking for a colour fill routine

Post by Einar Saukas »

Thank you!!!
Post Reply