/*
* File: GFace.java
* ----------------
* This file defines a compound GFace class.
*/
import acm.program.*;
import acm.graphics.*;
import java.awt.*;
public class Gface extends GraphicsProgram {
public static final double PHI = 1.618;
/** Runs the program */
public void run() {
setSize (800, 800);
Snowman frosty = new Snowman();
Tree smallTree = new Tree();
for(int i = 0; i < 10; i++) {
pause(1000);
frosty.move(20,50);
}
}
class Tree{
private Treetrunk trunk;
private PineNeedles needles;
public Tree(){
trunk = new Treetrunk();
needles = new PineNeedles();
}
}
class Snowman {
private Snowbody body;
private Face face;
private Arms arms;
public Snowman() {
body = new Snowbody();
face = new Face();
arms = new Arms();
}
void move(int xdir, int ydir) {
body.move(xdir, ydir);
face.move(xdir, ydir);
arms.move(xdir, ydir);
}
}
class Treetrunk{
private GRect trunk;
Treetrunk(){
trunk = new GRect(100, 200, 50, 100 / PHI);
trunk.setFilled(true);
trunk.setColor(Color.BLACK);
add(trunk);
}
}
class PineNeedles{
private GPolygon treebottom, treemiddle, treetop;
PineNeedles(){
GPolygon treebottom = new GPolygon();
treebottom.addEdge(127, 175);
treebottom.addEdge(-80, 40);
treebottom.addEdge(150, 0);
treebottom.setFilled(true);
treebottom.setColor(Color.GREEN);
add(treebottom);
GPolygon treemiddle = new GPolygon();
treemiddle.addEdge(127, 150);
treemiddle.addEdge(-80, 40);
treemiddle.addEdge(150, 0);
treemiddle.setFilled(true);
treemiddle.setColor(Color.GREEN);
add(treemiddle);
GPolygon treetop = new GPolygon();
treetop.addEdge(127, 125);
treetop.addEdge(-80, 40);
treetop.addEdge(150, 0);
treetop.setFilled(true);
treetop.setColor(Color.GREEN);
add(treetop);
}
}
class Arms{
private GLine right_Bicept, left_Bicept, right_forarm, left_forarm;
Arms(){
right_Bicept = new GLine (300, 180, 280, 170);
right_Bicept.setColor(Color.BLACK);
add(right_Bicept);
left_Bicept = new GLine (400, 179, 420, 170);
left_Bicept.setColor(Color.BLACK);
add(left_Bicept);
right_forarm = new GLine (280, 170, 310, 150);
right_forarm.setColor(Color.BLACK);
add(right_forarm);
left_forarm = new GLine (420, 170, 395, 150);
left_forarm.setColor(Color.BLACK);
add(left_forarm);
}
void move(int xdir, int ydir) {
right_Bicept.move(xdir, ydir);
left_Bicept.move(xdir, ydir);
right_forarm.move(xdir, ydir);
left_forarm.move(xdir, ydir);
}
}
class Face{
private GOval Right_Eye, Left_Eye;
Face(){
Right_Eye = new GOval (330, 120, 5, 5);
Right_Eye.setFilled(true);
Right_Eye.setColor(Color.BLACK);
add(Right_Eye);
Left_Eye = new GOval (360, 120, 5, 5);
Left_Eye.setFilled(true);
Left_Eye.setColor(Color.BLACK);
add(Left_Eye);
}
void move(int xdir, int ydir) {
Right_Eye.move(xdir, ydir);
Left_Eye.move(xdir, ydir);
}
}
class Snowbody {
private GOval ovalbottom, ovalmiddle, ovaltop;
Snowbody() {
ovalbottom = new GOval(300, 170 + 50 / PHI, 100, 100 / PHI);
ovalbottom.setFilled(true);
ovalbottom.setColor(Color.LIGHT_GRAY);
add(ovalbottom);
ovalmiddle = new GOval (300, 120 + 50 / PHI, 100, 100 / PHI);
ovalmiddle.setFilled(true);
ovalmiddle.setColor(Color.LIGHT_GRAY);
add(ovalmiddle);
ovaltop = new GOval (300, 70 + 50 / PHI, 100, 100 / PHI);
ovaltop.setFilled(true);
ovaltop.setColor(Color.LIGHT_GRAY);
add(ovaltop);
}
void move(int xdir, int ydir) {
ovalbottom.move(xdir, ydir);
ovalmiddle.move(xdir, ydir);
ovaltop.move(xdir, ydir);
}
}
}