2 Attachment(s)
Filling awkward shapes with color
Hi,
forgive me if this question is too general/noobish/stupid, but i've never attempting this before and so i had to ask.
Anyway, basically i wanted to know if it was possible to fill nonstandard shapes with color. I know how to draw a rectangle/triangle/circle/etc with a color, but the shape i'm making is not a standard shape like that.
For instance, what kind of shape is this lol?
Attachment 1083
Just to give you some background as to what i'm doing, basically i'm going to take the map of the united states, and i want to be able to fill the states with different colors. I know i can prefill the shapes with color in photoshop, but that doesnt seem very efficient especially if im going to need multiple colors.
Is there another way to do it? what techniques can i use to achieve this.
I want to be able to click on any state on the map and change its color.
thanks. :)
EDIT: Idk why that other California stencil below is attached to my post...
Re: Filling awkward shapes with color
Quote:
For instance, what kind of shape is this lol?
It could be an instance of Polygon. There are methods in the Graphics2D class to draw and fill these things. And to use them as the clipping region for other painting operations.
The other way to go would be to regard the shape as a bitmapped image. In that case you would paint it wherever you want it.
The distinction is between vector and raster graphics and you have to consider what would be more appropriate in your circumstances. How easy will it be to get the data? Will the shape scale or undergo other transformations? Do you want "hit detection"? etc
Oracle's Tutorial has a whole section on 2D graphics which will be useful in either case.
Re: Filling awkward shapes with color
Thank you very much, that gives me a great place to start.
How can i regard that as a vector image? I'm more comfortable using vector images than bitmaps. Are the techniques to fill it, essentially the same?
EDIT: Okay so i read a bit, but i dont see how i the polygon can help me fill such a complex shape like the states.
Re: Filling awkward shapes with color
Quote:
Originally Posted by
clydefrog
i dont see how i the polygon can help me fill such a complex shape like the states.
Polygon implements Shape. And presuming you are using Swing (based upon the category this is posted in), you can use the Graphics2D methods to draw or fill any Shape.
Re: Filling awkward shapes with color
okay i'll take another look, thanks for the reply.
is there an example i can look at? I cant seem to find anything on the web about filling in complicated and asymmetrical shapes like California lol.