gpt4 book ai didi

java - 画曲线,有什么建议

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

大家好,我需要以粗体绘制曲线,主要是那些以 N - S 开头的曲线,如果可能的话,还有 350-10 340-20 的曲线,依此类推。我尝试过 QuadCurve2D 和 drawArc,但这些都不起作用。有没有办法避免使用drawPolyline(xPoints, yPoints, WIDTH),因为只绘制一条线就需要数百对。

enter image description here

这是代码的一部分,以避免您浪费时间自行测试:

        public class PaintMyQuad extends JPanel {

@Override
protected void paintComponent(Graphics g) {

super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g.create();

QuadCurve2D.Double curve = new QuadCurve2D.Double(200,0,200,100,200,200);
QuadCurve2D.Double curve1 = new QuadCurve2D.Double(200,0,180,100,200,200);
QuadCurve2D.Double curve2 = new QuadCurve2D.Double(200,0,160,100,200,200);
//etc
g2d.setColor(Color.RED);
g2d.draw(curve);
g2d.draw(curve1);
g2d.draw(curve2);
g2d.drawOval(100,100,200,200);
g2d.drawArc(100,100, 100, 200, 90, 180);
g2d.drawArc(100, 100, 100, 200, 180, 360);
g2d.drawArc(100, 100, 0, 200, 90, 180);
g2d.drawRect(100, 100, 200, 200);

最佳答案

如果您需要粗线,请尝试这样做:

....
Graphics2D g2d = (Graphics2D)g;

BasicStroke pen1 = new BasicStroke(5); // this is stroke with 5px width,
g2d.setStroke(pen1);

g2d.drawArc(100,100, 100, 200, 90, 180);
g2d.drawArc(100, 100, 100, 200, 180, 360);
...

为两种类型的线条绘制 2 个笔划,然后使用它。

关于java - 画曲线,有什么建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19699781/

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