Filling a line design (is it Possible?)
Author |
Message |
Naxirn
|
Posted: Sat Jun 20, 2009 5:19 pm Post subject: Filling a line design (is it Possible?) |
|
|
I've just started java recently, and I was getting into the graphics part of it. I was wondering if there was anyway to fill in a location with a color (like Turing's draw.fill command) in java.
What I pretty much did was create an isometric square using a bunch of drawlines and was hoping to fill it with a certain color, is there anyway to do this?
OR
is there a way to create an Isometric square with fill options besides using drawline commands?
[I'm using NetBeans 6.5.1 and JDK 5, and importing java.awt, java.swing atm] |
|
|
|
|
|
Sponsor Sponsor
|
|
|
DtY
|
Posted: Sat Jun 20, 2009 6:24 pm Post subject: RE:Filling a line design (is it Possible?) |
|
|
Is there a method to draw a filled polygon?
Filling a closed area is very inefficient, but if you want to, the algorithm is something like this (pseudo code):
code: | function fillarea(x, y, srcCol, dstCol) {
/* scrCol is the current colour to search for */
if pixel @ [x,y] is srcCol {
set pixel @ [x,y] to dstCol
fillarea(x+1, y, srcCol, dstCol)
fillarea(x-1, y, scrCol, dstCol)
fillarea(x, y+1, srcCol, dstCol)
fillarea(x, y-1, srcCol, dstCol)
}
} |
There are more efficient methods, but they are harder to implement, and still would run slower than something that just drew a filled polygon.
[edit] indented |
|
|
|
|
|
Naxirn
|
Posted: Sat Jun 20, 2009 6:42 pm Post subject: Re: RE:Filling a line design (is it Possible?) |
|
|
Thanks Dty, found the polygon you were talking about, solve my problems. Thanks again! |
|
|
|
|
|
|
|