pravdomil
pravdomil

Reputation: 2969

Filling algorithm from edges to center in JavaScript

I'm create a slicer for RepRap machine.

I got stuck at programming filling algorithm that would climb like this:

animation animation

It's kind of flood fill, but it must go from edge to center like a spiral. The path generated by algorithm is essential for the machine.

Do somebody know how to solve it? Thanks

Answered by phenxd

animation

Upvotes: 3

Views: 168

Answers (1)

phenxd
phenxd

Reputation: 689

What I suggest for you is to try and implement your own variation of the floodfilling algorithm

Though, since you want to paint from the outer bound, instead of checking the up, down, left and right neighbors in the same order everytime, you should do it relatively from the 'direction' you are currently drawing.

Ex.

First pixel is on the left.

check left : skip
check down : draw   

MOVING DOWN   
    check left : skip   
    check down : skip   
    check right : draw   

MOVING RIGHT    
    check down : draw   // We rotated the order by 90 degrees!

etc.

The goal is to always check the pixel on the right of the current direction so that we will always be on the outer bound of our drawing

Upvotes: 1

Related Questions