So I am currently creating a drawing that creates a Snowman, as well as some other objects in the background. I got the drawing part down, it looks just as it should, but I wanted to add a little bit of movement within it. I used Graphics2D to draw all my shapes, lines, ellipses, etc., but I'm not sure how/if I can make the Snowmans arms wave back and forth with the drawLine method.
I provided the code for the entire Snowman here. It's very simple, as I said it just uses Graphics2D to draw everything. The arm1 and arm2 are near the bottom.
public class Snowman {
private int x;
private int y;
private int width;
private int height;
public Snowman(int x, int y, int width, int height) {
this.x=x;
this.y=y;
this.width=width;
this.height=height;
}
public void draw(Graphics g)
{
Graphics2D g2 = (Graphics2D) g;
// the body of the snowman
g2.setColor(Color.WHITE);
g2.fillOval(x+125, y+40, 200, 200);
g2.fillOval(x+75, y+140, 300, 300);
g2.fillOval(x+25, y+290, 400, 400);
// the buttons
g2.setColor(Color.BLACK);
g2.fillOval(x+210, y+210, 40, 40);
g2.fillOval(x+210, y+270, 40, 40);
g2.fillOval(x+210, y+330, 40, 40);
// the eyes and mouth
g2.fillOval(x+190, y+98, 20, 20);
g2.fillOval(x+245, y+98, 20, 20);
g2.drawArc(x+180, y+120, 100, 50, 200, 140);
// arm1
g2.drawLine(x+75, y+270, x, y+90);
//arm2
g2.drawLine(x+375, y+270, x+450, y+90);
// the hat
g2.setColor(Color.BLACK);
g2.fillRect(x+177, y+40, 100, 30);
g2.fillRect(x+202, y, 50, 50);
}
}
Is there a way I can implement something to make them move? Or would I have to draw these another way?