Skip to content

Instantly share code, notes, and snippets.

@rbrick
Last active July 1, 2020 23:36
Show Gist options
  • Save rbrick/ef5e4a874c92c87c61379e2f90a3bc81 to your computer and use it in GitHub Desktop.
Save rbrick/ef5e4a874c92c87c61379e2f90a3bc81 to your computer and use it in GitHub Desktop.
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 = cos * 100;
double y = sin * 100;
double travelX = cos * outerRadius;
double travelY = sin * outerRadius;
final double v = (Math.toRadians((i - 1)*angle));
double nextX = Math.cos(v) * outerRadius;
double nextY = Math.sin(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