java drawarc_Java:使用drawArc绘制一个圆形螺旋

你的想法几乎是对的.我做了一些修改.您需要反转角度以绘制螺旋的另一侧并使用固定点来启动角度.

import java.awt.Graphics;

import javax.swing.JPanel;

import javax.swing.JFrame;

public class CircSpiral extends JPanel {

public void paintComponent(Graphics g) {

int x = getSize().width / 2 - 10;

int y = getSize().height/ 2 - 10;

int width = 20;

int height = 20;

int startAngle = 0;

int arcAngle = 180;

int depth = 10;

for (int i = 0; i < 10; i++) {

if (i % 2 == 0) {

// g.drawArc(x + 10, y + 10, width, height, startAngle + 10, -arcAngle);

// x = x - 5;

y = y - depth;

width = width + 2 * depth;

height = height + 2 * depth;

g.drawArc(x, y, width, height, startAngle, -arcAngle);

} else {

// g.drawArc(x + 10, y + 10, width, height, startAngle + 10, arcAngle);

x = x - 2 * depth;

y = y - depth;

width = width + 2 * depth;

height = height + 2 * depth;

g.drawArc(x, y, width, height, startAngle, arcAngle);

}

}

}

public static void main(String[] args) {

CircSpiral panel = new CircSpiral();

JFrame application = new JFrame();

application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

application.add(panel);

application.setSize(300, 300);

application.setVisible(true);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值