|
|
y=sinθでx軸をラジアンにしてπ(180度)で1つの波、2π(360度)で1周期なので2つの波。
先生が作ってくれた。Star.javaを少し変えて下のソースで実行したら波っぽくなりました。これでいいのかな???
// <applet code="Nami.class" width="200" height="133"></applet>
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
public class Nami extends Applet {
public void paint(Graphics g) {
g.setColor(Color.blue);
fillStar(g, 0, 100, 10);
}
/**
* 波を描画するメソッド
* g : 描画するグラフィック
* x : 波の2番目の点のx座標
* y : 波の2番目のy座標
* size : 星のサイズ
*/
public void fillStar(Graphics g, int x, int y, int size) {
// アンチエイリアスで斜め線をきれいにする
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
// 星の頂点の数
int[] xPoint = new int[660];
int[] yPoint = new int[660];
// 始点の頂点座標
xPoint[0] = 0;
yPoint[0] = 133;
// 終点の頂点座標
xPoint[659] = 200;
yPoint[659] = 133;
for (int i = 1; i < 659; i++) {
xPoint[i] = x + (int)(Math.toRadians(1.8 * i ) * size);
yPoint[i] = y + (int)Math.round(Math.sin(Math.toRadians(1.8 * i )) * size);
System.out.println(xPoint[i] + ", " + yPoint[i]);
}
// 波の描画
g2.fillPolygon(xPoint, yPoint, 660);
}
}
|
|