PIbd-23_Polevoy_S.V._SelfPr.../DrawingSquaredRollers.java

112 lines
6.9 KiB
Java
Raw Normal View History

2022-10-08 22:22:51 +04:00
import java.awt.*;
public class DrawingSquaredRollers implements IDrawingRollers {
private RollersCount rollersCount;
private Color color;
public DrawingSquaredRollers(int rollersCount, Color bodyColor) {
setRollersCount(rollersCount);
color = bodyColor;
}
public void setRollersCount(int num) {
if (num <= 4) {
rollersCount = RollersCount.Four;
} else if (num >= 6) {
rollersCount = RollersCount.Six;
} else {
rollersCount = RollersCount.Five;
}
}
public void draw(Graphics2D g, int x, int y, int artilleryWidth, int artilleryHeight) {
g.setColor(color != null ? color : Color.BLACK);
g.fillOval(x + artilleryWidth / 20, y + artilleryHeight * 7 / 15, artilleryWidth * 4 / 20, artilleryHeight * 10 / 32);
g.fillOval(x + artilleryWidth * 15 / 20, y + artilleryHeight * 7 / 15, artilleryWidth * 4 / 20, artilleryHeight * 10 / 32);
switch (rollersCount) {
case Six: {
g.fillOval(x + artilleryWidth * 8 / 20, y + artilleryHeight * 10 / 16, artilleryWidth * 2 / 20, artilleryHeight * 6 / 32);
}
case Five: {
g.fillOval(x + artilleryWidth * 10 / 20, y + artilleryHeight * 10 / 16, artilleryWidth * 2 / 20, artilleryHeight * 6 / 32);
}
case Four: {
g.fillOval(x + artilleryWidth * 5 / 20, y + artilleryHeight * 9 / 16, artilleryWidth * 3 / 20, artilleryHeight * 8 / 32);
g.fillOval(x + artilleryWidth * 12 / 20, y + artilleryHeight * 9 / 16, artilleryWidth * 3 / 20, artilleryHeight * 8 / 32);
}
}
drawOrnament(g, x, y, artilleryWidth, artilleryHeight);
}
private void drawOrnament(Graphics2D g, int x, int y, int artilleryWidth, int artilleryHeight) {
g.setStroke(new BasicStroke(1));
g.setColor(Color.BLACK);
Polygon bigRollerFirstPattern = new Polygon();
bigRollerFirstPattern.addPoint(x + artilleryWidth / 20 + 1, y + artilleryHeight * 7 / 15 + artilleryHeight * 5 / 32);
bigRollerFirstPattern.addPoint(x + artilleryWidth * 3 / 20, y + artilleryHeight * 7 / 15 + 1);
bigRollerFirstPattern.addPoint(x + artilleryWidth * 5 / 20 - 1, y + artilleryHeight * 7 / 15 + artilleryHeight * 5 / 32);
bigRollerFirstPattern.addPoint(x + artilleryWidth * 3 / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 10 / 32 - 1);
g.drawPolygon(bigRollerFirstPattern);
bigRollerFirstPattern.translate(artilleryWidth * 14 / 20, 0);
g.drawPolygon(bigRollerFirstPattern);
Polygon bigRollerSecondPattern = new Polygon();
bigRollerSecondPattern.addPoint(x + artilleryWidth * 2 / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 5 / 64);
bigRollerSecondPattern.addPoint(x + artilleryWidth * 4 / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 5 / 64);
bigRollerSecondPattern.addPoint(x + artilleryWidth * 4 / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 15 / 64);
bigRollerSecondPattern.addPoint(x + artilleryWidth * 2 / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 15 / 64);
g.drawPolygon(bigRollerSecondPattern);
bigRollerSecondPattern.translate(artilleryWidth * 14 / 20, 0);
g.drawPolygon(bigRollerSecondPattern);
Polygon smallRollerFirstPattern = new Polygon();
smallRollerFirstPattern.addPoint(x + artilleryWidth * 8 / 20, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32);
smallRollerFirstPattern.addPoint(x + artilleryWidth * 9 / 20, y + artilleryHeight * 10 / 16);
smallRollerFirstPattern.addPoint(x + artilleryWidth * 10 / 20, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32);
smallRollerFirstPattern.addPoint(x + artilleryWidth * 9 / 20, y + artilleryHeight * 10 / 16 + artilleryHeight * 6 / 32);
Polygon smallRollerSecondPattern = new Polygon();
smallRollerSecondPattern.addPoint(x + artilleryWidth * 8 / 20 + artilleryWidth * 2 / 80, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32 - artilleryHeight * 3 / 64);
smallRollerSecondPattern.addPoint(x + artilleryWidth * 9 / 20 + artilleryWidth * 2 / 80, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32 - artilleryHeight * 3 / 64);
smallRollerSecondPattern.addPoint(x + artilleryWidth * 10 / 20 - artilleryWidth * 2 / 80, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32 + artilleryHeight * 3 / 64);
smallRollerSecondPattern.addPoint(x + artilleryWidth * 8 / 20 + artilleryWidth * 2 / 80, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32 + artilleryHeight * 3 / 64);
switch(rollersCount) {
case Six: {
g.drawPolygon(smallRollerFirstPattern);
g.drawPolygon(smallRollerSecondPattern);
}
case Five: {
smallRollerFirstPattern.translate(artilleryWidth * 2 / 20, 0);
smallRollerSecondPattern.translate(artilleryWidth * 2 / 20, 0);
g.drawPolygon(smallRollerFirstPattern);
g.drawPolygon(smallRollerSecondPattern);
}
case Four: {
Polygon mediumRollerFirstPattern = new Polygon();
mediumRollerFirstPattern.addPoint(x + artilleryWidth * 5 / 20, y + artilleryHeight * 9 / 16 + artilleryHeight * 4 / 32);
mediumRollerFirstPattern.addPoint(x + artilleryWidth * 5 / 20 + artilleryWidth * 3 / 40, y + artilleryHeight * 9 / 16);
mediumRollerFirstPattern.addPoint(x + artilleryWidth * 5 / 20 + artilleryWidth * 3 / 20, y + artilleryHeight * 9 / 16 + artilleryHeight * 4 / 32);
mediumRollerFirstPattern.addPoint(x + artilleryWidth * 5 / 20 + artilleryWidth * 3 / 40, y + artilleryHeight * 9 / 16 + artilleryHeight * 8 / 32);
g.drawPolygon(mediumRollerFirstPattern);
mediumRollerFirstPattern.translate(artilleryWidth * 7 / 20, 0);
g.drawPolygon(mediumRollerFirstPattern);
Polygon mediumRollerSecondPattern = new Polygon();
mediumRollerSecondPattern.addPoint(x + artilleryWidth * 5 / 20 + artilleryWidth * 3 / 80, y + artilleryHeight * 9 / 16 + artilleryHeight * 2 / 32);
mediumRollerSecondPattern.addPoint(x + artilleryWidth * 5 / 20 + artilleryWidth * 9 / 80, y + artilleryHeight * 9 / 16 + artilleryHeight * 2 / 32);
mediumRollerSecondPattern.addPoint(x + artilleryWidth * 5 / 20 + artilleryWidth * 9 / 80, y + artilleryHeight * 9 / 16 + artilleryHeight * 6 / 32);
mediumRollerSecondPattern.addPoint(x + artilleryWidth * 5 / 20 + artilleryWidth * 3 / 80, y + artilleryHeight * 9 / 16 + artilleryHeight * 6 / 32);
g.drawPolygon(mediumRollerSecondPattern);
mediumRollerSecondPattern.translate(artilleryWidth * 7 / 20, 0);
g.drawPolygon(mediumRollerSecondPattern);
}
}
}
public void setColor(Color color) {
this.color = color;
}
2022-10-08 22:22:51 +04:00
}