Drawing question...

How can I draw a filled in triangle using java.awt.Graphics?
I want to draw one triangle pointing up, one pointing down, one pointing left and one pointing right...
cupOjavaAsked:
Who is Participating?
 
imladrisConnect With a Mentor Commented:
I can think of two options. The first and simplest would be to use a graphic (a .GIF of .JPEG) can be drawn very easily using the drawImage method. A graphic has to be square, of course, but the remaining space can be set to be transparent.

The second approach would be simply a series of lines. The bottom one is n pixels wide, the next one up n-2 pixels wide (or n-4, it would depend on how "steep" it is).

If you're having trouble with the transparency in the first option (you have to output with Photoshop, or something, and do it just so), or the second is too slow, and you want to use an offscreen buffer to save the image in, you will also need a filter to make relevant sections of the image transparent.

Feel free to ask for further details if you decide to try one of these.


0
All Courses

From novice to tech pro — start learning today.