У меня есть такие классы: package bear; import java.awt.; public class Eyes { private…
- User
У меня есть такие классы: package bear;
import java.awt.*;
public class Eyes { private int x; private int y; private int width; private int height; private int xMouse; // Позиция взгляда по оси X private int yMouse; // Позиция взгляда по оси Y
// Конструктор public Eyes( int x, int y, int width, int height) { this.x = x; this.y = y; this.width = width; this.height = height; this.xMouse = x; // Изначально устанавливаем в позицию глаз this.yMouse = y; // Изначально устанавливаем в позицию глаз } // Установить позицию взгляда по оси X public void setXMouse(int x) { this.xMouse = x; } // Установить позицию взгляда по оси Y public void setYMouse(int y) { this.yMouse = y; } // Установить ширину глаза public void setWidth(int width) { this.width = width; } // Установить высоту глаза public void setHeight(int height) { this.height = height; } // Метод для рисования глаза public void draw(final Graphics gr) { Graphics2D g = (Graphics2D) gr; // Рисуем белок глаза g.setColor(Color.WHITE); g.fillOval(this.x + width * 100 / 350, this.y + height * 130 / 550, width * 40 / 350, height * 40 / 550); g.fillOval(this.x + width * 210 / 350, this.y + height * 130 / 550, width * 40 / 350, height * 40 / 550); // Рисуем зрачок g.setColor(Color.BLACK); int pupilWidth = width / 2; // Ширина зрачка int pupilHeight = height / 2; // Высота зрачка // Вычисляем положение зрачка в зависимости от позиции взгляда int pupilX = x + (xMouse - x) * (width - pupilWidth) / width + (width - pupilWidth) / 2; int pupilY = y + (yMouse - y) * (height - pupilHeight) / height + (height - pupilHeight) / 2; g.fillOval(pupilX, pupilY, pupilWidth, pupilHeight); }} package bear;
import java.awt.*; import java.awt.geom.GeneralPath; import java.util.Arrays;
public class Body { // то, что не шевелится private final Color background; private int x; private int y; private int width; private int height; private Color firstColor; private Color secondColor;
public Body(int x, int y, int width, int height, Color firstColor, Color secondColor, Color background) { this.x = x; this.y = y; this.width = width; this.height = height; this.firstColor = firstColor; this.secondColor = secondColor; this.background = background; } public void setX(int x) { this.x = x; } public void setY(int y) { this.y = y; } public void setWidth(int width) { this.width = width; } public void setHeight(int height) { this.height = height; } public void setColor(Color color) { this.firstColor = color; } // Рисуем фигуру public void draw(final Graphics gr) { Graphics2D g = (Graphics2D) gr; g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // тело. Разбито на 2 овала - голова и тушука в дальнейшеим соединяем все вместе с помощью простых линий int xOval1 = (int) (this.x + width * 0.1); int yOval1 = (int) (this.y + height * 1 / 55); int widthOval1 = width * 280 / 350; int heightOval1 = (int) height * 285 / 500; int xOval2 = (int) (this.x); int yOval2 = (int) (this.y + height * 280 / 550); int widthOval2 = width; int heightOval2 = (int) height * 270 / 550; GeneralPath bodyPath = new GeneralPath(); bodyPath.moveTo(xOval1, yOval1 + heightOval1 / 2); bodyPath.lineTo(xOval1 + widthOval1, yOval1 + heightOval1 / 2); bodyPath.lineTo(xOval2 + widthOval2, yOval2 + heightOval2 / 2); bodyPath.lineTo(xOval2 + (float) widthOval2 / 2, yOval2 + heightOval2); bodyPath.lineTo(xOval2 + (float) widthOval2 / 2, yOval2 + heightOval2); bodyPath.lineTo(xOval2, yOval2 + (float) heightOval2 / 2); bodyPath.closePath(); BasicStroke bs = new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL); //уши g.setColor(this.firstColor); g.fillOval(this.x + width * 250 / 350, this.y + height * 20 / 550, width * 30 / 350, height * 50 / 550); g.fillOval(this.x + width * 70 / 350, this.y + height * 15 / 550, width * 30 / 350, height * 50 / 550); g.setColor(Color.black); g.drawOval(this.x + width * 250 / 350, this.y + height * 20 / 550, width * 30 / 350, height * 50 / 550); g.drawOval(this.x + width * 70 / 350, this.y + height * 15 / 550, width * 30 / 350, height * 50 / 550); // прорисовка овалов g.setColor(this.firstColor); g.fill(bodyPath); g.fillOval(xOval2, yOval2, widthOval2, heightOval2); g.fillOval(xOval1, yOval1, widthOval1, heightOval1); g.setColor(Color.BLACK); //нос g.fillOval(this.x + width * 145 / 350, yOval1 + heightOval1 / 2, width * 60 / 350, height * 25 / 550); // глаза (белки, зрачки будут в др. классе) g.setColor(Color.WHITE); g.fillOval(this.x + width * 100 / 350, this.y + height * 130 / 550, width * 40 / 350, height * 40 / 550); g.fillOval(this.x + width * 210 / 350, this.y + height * 130 / 550, width * 40 / 350, height * 40 / 550); // контуры овалов, с учетом, что нам надо только полукруги.. g.setStroke(bs); g.setColor(Color.BLACK); g.drawOval(this.x + width * 100 / 350, this.y + height * 130 / 550, width * 40 / 350, height * 40 / 550); g.drawOval(this.x + width * 210 / 350, this.y + height * 130 / 550, width * 40 / 350, height * 40 / 550); /* g.fillOval(this.x + width * 110 / 350, this.y + height * 140 / 550, width * 20 / 350, height * 20 / 550); g.fillOval(this.x + width * 220 / 350, this.y + height * 140 / 550, width * 20 / 350, height * 20 / 550); - Assistant