Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Flood fill
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Pseudocode === This is a pseudocode implementation of an optimal fixed-memory flood-fill algorithm written in structured English: ; The variables * <code>cur</code>, <code>mark</code>, and <code>mark2</code> each hold either pixel coordinates or a null value ** NOTE: when <code>mark</code> is set to null, do not erase its previous coordinate value. Keep those coordinates available to be recalled if necessary. * <code>cur-dir</code>, <code>mark-dir</code>, and <code>mark2-dir</code> each hold a direction (left, right, up, or down) * <code>backtrack</code> and <code>findloop</code> each hold Boolean values * <code>count</code> is an integer ; The algorithm : NOTE: All directions (front, back, left, right) are relative to <code>cur-dir</code> set cur to starting pixel set cur-dir to default direction clear mark and mark2 (set values to null) set backtrack and findloop to false '''while''' front-pixel is empty '''do''' move forward '''end while''' jump to START MAIN LOOP: move forward '''if''' right-pixel is inside '''then''' '''if''' backtrack is true '''and''' findloop is false '''and''' either front-pixel '''or''' left-pixel is inside '''then''' set findloop to true '''end if''' turn right PAINT: move forward '''end if''' START: '''set''' ''count'' to number of non-diagonally adjacent pixels filled (front/back/left/right ONLY) '''if''' ''count'' '''is not''' 4 '''then''' '''do''' turn right '''while''' front-pixel is inside '''do''' turn left '''while''' front-pixel is not inside '''end if''' '''switch''' ''count'' case 1 '''if''' backtrack is true '''then''' set findloop to true '''else if''' findloop is true '''then''' '''if''' mark is null '''then''' restore mark '''end if''' '''else if''' front-left-pixel and back-left-pixel are both inside '''then''' clear mark set cur jump to PAINT '''end if''' end case case 2 '''if''' back-pixel is not inside '''then''' '''if''' front-left-pixel is inside '''then''' clear mark set cur jump to PAINT '''end if''' '''else if''' mark is not set '''then''' set mark to cur set mark-dir to cur-dir clear mark2 set findloop and backtrack to false '''else''' '''if''' mark2 is not set '''then''' '''if''' cur is at mark '''then''' '''if''' cur-dir is the same as mark-dir '''then''' clear mark turn around set cur jump to PAINT '''else''' set backtrack to true set findloop to false set cur-dir to mark-dir '''end if''' '''else if''' findloop is true '''then''' set mark2 to cur set mark2-dir to cur-dir '''end if''' '''else''' '''if''' cur is at mark '''then''' set cur to mark2 set cur-dir to mark2-dir clear mark and mark2 set backtrack to false turn around set cur jump to PAINT '''else''' if cur at mark2 '''then''' set mark to cur set cur-dir and mark-dir to mark2-dir clear mark2 '''end if''' '''end if''' '''end if''' end case case 3 clear mark set cur jump to PAINT end case case 4 set cur done end case '''end switch''' end MAIN LOOP
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Flood fill
(section)
Add topic