How to draw heart using java awt libaray? I am using Java AWT Libaray and I need to draw a heart for my game. How can I do this using AWT?
Here what I was thinking:
Had to write this code for something I'm doing and it works well enough. Draws a triangle at x and y with the specified width and height using graphics g.
// Draw a heart.
public void drawHeart(Graphics g, int x, int y, int width, int height) {
int[] triangleX = {
x - 2*width/18,
x + width + 2*width/18,
(x - 2*width/18 + x + width + 2*width/18)/2};
int[] triangleY = {
y + height - 2*height/3,
y + height - 2*height/3,
y + height };
g.fillOval(
x - width/12,
y,
width/2 + width/6,
height/2);
g.fillOval(
x + width/2 - width/12,
y,
width/2 + width/6,
height/2);
g.fillPolygon(triangleX, triangleY, triangleX.length);
}