【发布时间】:2019-07-29 17:34:02
【问题描述】:
问题是我在互联网上搜索绘制阿基米德螺旋的方法,但我只找到这样的东西:
所以我不知道如何绘制像第一张图片这样的东西,我已经尝试过以某种方式构建一个螺旋,然后放置相同的螺旋,但以另一种方式,但它没有奏效,我使用的代码来自Java: Draw a circular spiral using drawArc
public class ArchimideanSpiral extends JFrame {
public ArchimideanSpiral()
{
super("Archimidean Spiral");
setSize(500,500);
setVisible(true);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
public void paint(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++) {
width = width + 2 * depth;
y = y - depth;
height = height + 2 * depth;
if (i % 2 == 0) {
g.drawArc(x, y, width, height, startAngle, -arcAngle);
} else {
x = x - 2 * depth;
g.drawArc(x, y, width, height, startAngle, arcAngle);
}
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
new ArchimideanSpiral();
}
}
但是如果我尝试以相反的方式放置相同的螺旋,它不起作用,所以我迷路了。
【问题讨论】: