Lecture/컴퓨터프로그래밍및실습/GFace.java

Retired DISLab
< Lecture | 컴퓨터프로그래밍및실습
Swpark (토론 | 기여) 사용자의 2014년 1월 26일 (일) 09:52 버전
(비교) ← 이전 판 | 현재 판 (비교) | 다음 판 → (비교)
이동: 둘러보기, 찾기
import acm.graphics.*;
 
public class GFace extends GCompound {
 
	/** Construct a new GFace object with the specified dimensions */
	public GFace(double width, double height) {
		head = new GOval(width, height);
		leftEye = new GOval(EYE_WIDTH * width, EYE_HEIGHT * height);
		rightEye = new GOval(EYE_WIDTH * width, EYE_HEIGHT * height);
		nose = createNose(NOSE_WIDTH * width, NOSE_HEIGHT * height);
		mouth = new GRect(MOUTH_WIDTH * width, MOUTH_HEIGHT * height);
 
		add(head, -width / 2, -height / 2);
		add(leftEye, -0.25 * width - EYE_WIDTH * width / 2,
					 -0.25 * height - EYE_HEIGHT * height / 2);
		add(rightEye, 0.25 * width - EYE_WIDTH * width / 2,
					 -0.25 * height - EYE_HEIGHT * height / 2);
		add(nose, 0, 0);
		add(mouth, -MOUTH_WIDTH * width / 2,
				   0.25 * height - MOUTH_HEIGHT * height / 2);
	}
 
	/* Creates a triangle for the nose */
	private GPolygon createNose(double width, double height) {
		GPolygon poly = new GPolygon();
		poly.addVertex(0, -height / 2);
		poly.addVertex(width / 2, height / 2);
		poly.addVertex(-width / 2, height / 2);
		return poly;
	}
 
	/* Constants specifying feature size as a fraction of the head size */
	private static final double EYE_WIDTH 	= 0.15;
	private static final double EYE_HEIGHT	= 0.15;
	private static final double NOSE_WIDTH	= 0.15;
	private static final double NOSE_HEIGHT	= 0.15;
	private static final double MOUTH_WIDTH	= 0.50;
	private static final double MOUTH_HEIGHT = 0.03;
 
	/* Private instance variables */
	private GOval head;
	private GOval leftEye, rightEye;
	private GPolygon nose;
	private GRect mouth;
}
개인 도구
이름공간
변수
행위
둘러보기
구성원
연구
연구실
기타
도구모음
인쇄/내보내기