5月 15, 2010

Java Graphics5

Java Graphics5
螺旋線

import java.awt.Graphics;
import javax.swing.JPanel;
public class SpiralArc extends JPanel
{
public void paintComponent( Graphics g )
{
super.paintComponent( g );
final int offset = 40; // 間距
final int shamt = 20; // shift amount
int radius = 20; // 半徑
int x = getWidth() / 2; // x座標
int y = getHeight() / 2; // y座標

while( x > -10 || ( y - radius ) > -10 )
{
g.drawArc( x, y-radius, radius*2, radius*2, 180, -180 ); // 上半圓
radius += shamt;
x -= offset;
g.drawArc( x, y-radius, radius*2, radius*2, 0, -180 ); // 下半圓
radius += shamt;
}
}
}

以上為使用 Java 所繪製出來的圖形程式碼,僅供學習參考
程式碼是我自己寫出來的,如有雷同、純屬巧合
如有任何疑問,歡迎留言一同討論!

沒有留言:

張貼留言

歡迎留言~登入身分再留言方便後續意見交流喔!
當然,沒登入也可以留言!