-
-
Save YoungOG/81c212aced345b35adaa5671534c0448 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) throws IOException { | |
final BufferedImage image = new BufferedImage(1024, 1024, BufferedImage.TYPE_INT_ARGB); | |
final Graphics graphics = image.getGraphics(); | |
int center = image.getWidth() / 2; | |
int outerRadius = 512; | |
int segments = 18; | |
int angle = 360 / segments; | |
graphics.setColor(Color.BLACK); | |
graphics.setFont(graphics.getFont().deriveFont(8.5f)); | |
for (int i = segments; i > 0; i--) { | |
final double cos = Math.cos(Math.toRadians(i*angle)); | |
final double sin = Math.sin(Math.toRadians(i*angle)); | |
double x = sin * 100; | |
double y = cos * 100; | |
double travelX = sin * outerRadius; | |
double travelY = cos * outerRadius; | |
final double v = (Math.toRadians((i - 1)*angle)); | |
double nextX = Math.sin(v) * outerRadius; | |
double nextY = Math.cos(v) * outerRadius; | |
Polygon polygon = new Polygon(); | |
polygon.addPoint((int) x + center, (int) y + center); // the tip | |
polygon.addPoint((int) travelX + center, (int) travelY + center); | |
polygon.addPoint((int) nextX + center, (int) nextY + center); | |
// image.setRGB((int) x + center, (int) y + center, Color.BLACK.getRGB()); | |
graphics.setColor(Color.PINK); | |
graphics.drawPolygon(polygon.xpoints, polygon.ypoints, polygon.npoints); | |
graphics.setColor(Color.BLACK); | |
graphics.fillPolygon(polygon); | |
// graphics.drawLine((int) x + center, (int) y + center, (int) travelX + center, (int) travelY + center); | |
// graphics.drawString("" + (i), (int) x + center, (int) y + center); | |
// graphics.drawString("aP " + (i + 1), (int) nextX + center, (int) nextY + center); | |
// image.setRGB((int) travelX + center, (int) travelY + center, Color.RED.getRGB()); | |
// image.setRGB((int) nextX + center, (int) nextY + center, Color.BLUE.getRGB()); | |
} | |
// graphics.dispose(); | |
ImageIO.write(image, "png", new File("test.png")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment