六边形战士

代码

 效果如下

 

好的,以下是使用Java绘制马龙六边形战士的蛛网图,并输出为图片的代码: ```java import java.awt.Color; import java.awt.Graphics; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; public class MaLongHexagonGraph { private static final int WIDTH = 1000; private static final int HEIGHT = 1000; private static final int PADDING = 100; private static final int SIDES = 6; private static final double ANGLE = 2 * Math.PI / SIDES; private static final double RADIUS = 200; private static final double SCALE_FACTOR = 0.8; private static final int[] VALUES = {100, 98, 95, 92, 85, 80}; public static void main(String[] args) { BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB); Graphics g = image.getGraphics(); g.setColor(Color.WHITE); g.fillRect(0, 0, WIDTH, HEIGHT); int centerX = WIDTH / 2; int centerY = HEIGHT / 2; int[] xPoints = new int[SIDES]; int[] yPoints = new int[SIDES]; for (int i = 0; i < SIDES; i++) { double angle = i * ANGLE; int x = (int) Math.round(centerX + RADIUS * Math.cos(angle)); int y = (int) Math.round(centerY + RADIUS * Math.sin(angle)); xPoints[i] = x; yPoints[i] = y; } g.setColor(Color.BLACK); for (int i = 0; i < SIDES; i++) { int x1 = xPoints[i]; int y1 = yPoints[i]; int x2 = xPoints[(i + 1) % SIDES]; int y2 = yPoints[(i + 1) % SIDES]; g.drawLine(x1, y1, x2, y2); } for (int i = 0; i < SIDES; i++) { double angle = i * ANGLE; double scaleFactor = VALUES[i] / 100.0 * SCALE_FACTOR; int x = (int) Math.round(centerX + RADIUS * scaleFactor * Math.cos(angle)); int y = (int) Math.round(centerY + RADIUS * scaleFactor * Math.sin(angle)); g.fillOval(x - 5, y - 5, 10, 10); } g.dispose(); try { ImageIO.write(image, "png", new File("malong.png")); } catch (IOException e) { e.printStackTrace(); } } } ``` 运行以上代码,会生成一个名为 `malong.png` 的图片文件,内容为马龙六边形战士的蛛网图。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值