gpt4 book ai didi

java - 如何使用 Point2D.Double 作为点绘制多边形?

转载 作者:行者123 更新时间:2023-12-01 23:25:09 25 4
gpt4 key购买 nike

无法设置带有小数点坐标的点,因此我调整了比例。这是我的形象。霸天虎标志。

import java.awt.Graphics;

import java.awt.Graphics2D;

import java.awt.Polygon;

import java.awt.Color;

import java.awt.geom.Rectangle2D;

import javax.swing.JComponent;


public class DecepticonComponent extends JComponent

{

public void paintComponent(Graphics g)

{

Graphics2D g2 = (Graphics2D) g;
Rectangle2D.Double background = new Rectangle2D.Double(0,0,610,671);
g2.draw(background);
g2.setColor(Color.black);
g2.fill(background);

Color myNewPurple = new Color(103,28,196);

Polygon centerFace = new Polygon();
centerFace.addPoint(207,25);
centerFace.addPoint(277,137);
centerFace.addPoint(344,137);
centerFace.addPoint(414,25);
centerFace.addPoint(372,284);
centerFace.addPoint(310,335);
centerFace.addPoint(249,284);
g2.draw(centerFace);
g2.setColor(myNewPurple);
g2.fill(centerFace);

Polygon centerTriangle = new Polygon();
centerTriangle.addPoint(292,193);
centerTriangle.addPoint(328,193);
centerTriangle.addPoint(310,249);
g2.draw(centerTriangle);
g2.setColor(Color.black);
g2.fill(centerTriangle);

Polygon robotHead = new Polygon();
robotHead.addPoint(25,25);//1
robotHead.addPoint(95,123);//2
robotHead.addPoint(222,165);//3
robotHead.addPoint(231,228);//4
robotHead.addPoint(109,196);//5
robotHead.addPoint(109,207);//6
robotHead.addPoint(233,242);//7
robotHead.addPoint(237,270);//8
robotHead.addPoint(116,242);//9
robotHead.addPoint(116,253);//10
robotHead.addPoint(235,282);//11
robotHead.addPoint(310,349);//12
robotHead.addPoint(385,282);//11
robotHead.addPoint(507,253);//10
robotHead.addPoint(507,242);//9
robotHead.addPoint(384,270);//8
robotHead.addPoint(388,242);//7
robotHead.addPoint(511,207);//6
robotHead.addPoint(511,193);//5
robotHead.addPoint(390,228);//4
robotHead.addPoint(399,165);//3
robotHead.addPoint(511,123);//2
robotHead.addPoint(581,25);//1
robotHead.addPoint(560,305);//13
robotHead.addPoint(310,641);
robotHead.addPoint(60,305);//13
g2.draw(robotHead);
g2.setColor(myNewPurple);
g2.fill(robotHead);

Polygon eye1 = new Polygon();
eye1.addPoint(123,319);
eye1.addPoint(263,368);
eye1.addPoint(235,431);
g2.draw(eye1);
g2.setColor(Color.black);
g2.fill(eye1);

Polygon eye2 = new Polygon();
eye2.addPoint(497,319);
eye2.addPoint(357,368);
eye2.addPoint(385,431);
g2.draw(eye2);
g2.setColor(Color.black);
g2.fill(eye2);

Polygon chinL = new Polygon();
chinL.addPoint(62,333);
chinL.addPoint(276,620);
chinL.addPoint(84,543);
g2.draw(chinL);
g2.setColor(myNewPurple);
g2.fill(chinL);

Polygon chinR = new Polygon();
chinR.addPoint(558,333);
chinR.addPoint(344,620);
chinR.addPoint(536,543);
g2.draw(chinR);
g2.setColor(myNewPurple);
g2.fill(chinR);
}
}

最佳答案

不适用于 Ploygon,但您可以利用 Shape 的 API 并使用类似 Path2D 的内容。相反

看看Drawing Arbitrary Shapes了解更多详情

关于java - 如何使用 Point2D.Double 作为点绘制多边形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20136841/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com