// Poly.java // 2-Dimensional Polygon Manipuration Class // 2次元 多角形 変形&描画 クラス // Copyright (C) 1996, 1997 Y.Nagatani // nagatani@eken.phys.nagoya-u.ac.jp import java.applet.*; import java.awt.*; public class Poly { public Applet parent; public int width, height; public int points; public double x[], y[]; public double x0, y0, scale, rotate; public Color color; Poly (Applet parent, int width, int height, int points) { this.parent = parent; this.width = width; this.height = height; this.points = points; x = new double[points]; y = new double[points]; for (int n = 0 ; n < points ; n++) { double arg = 2.0 * Math.PI * n / points; setForm (n, 0.5 * Math.cos(arg), -0.5 * Math.sin(arg)); } setTranslate (0.5, 0.5); setScale (0.8); setRotate (0); color = Color.black; } public void paint (Graphics g) { int X[] = new int[points], Y[] = new int[points]; double sin = Math.sin (rotate), cos = Math.cos (rotate); for (int n = 0 ; n < points ; n++) { double x1 = cos * x[n] + sin * y[n], y1 = - sin * x[n] + cos * y[n]; X[n] = (int) ((x0 + scale * x1) * width); Y[n] = (int) ((y0 + scale * y1) * height); } g.setColor (color); g.fillPolygon (X, Y, points); } public void setForm (int point, double x, double y) { if (0 <= point && point < points) { this.x[point] = x; this.y[point] = y; } else { System.out.println ("Poly: Point Domain Error\n"); } } public void setTranslate (double x0, double y0) { this.x0 = x0; this.y0 = y0; } public void setScale (double scale) { this.scale = scale; } public void setRotate (double rotate) { this.rotate = rotate; } public void setColor (Color color) { this.color = color; } }