花びらが落ちていく、というようなプログラムを作っています。
コード public class Applet3D extends Applet implements Runnable{ int AppletX = 1000; //アプレットサイズ(x方向) int AppletY = 1000; //アプレットサイズ(y方向) int sakuraCount = 10; //表示する桜の枚数 Sakura sakura[] = new Sakura[sakuraCount]; Thread thread; Random rnd = new Random(); /*初期メソッド*/ public void init(){ setSize(AppletX, AppletY); for(int i = 0; i < sakuraCount; i++){ sakura[i] = new Sakura(rnd.nextInt(1000), 0, 1000*i); sakura[i].start(); } thread = new Thread(this); thread.start(); } /*描画メソッド*/ public void paint(Graphics g1){ Graphics2D g2 = (Graphics2D)g1; GeneralPath path = new GeneralPath(); for(int i = 0; i < sakuraCount; i++){ path.moveTo(sakura[i].Screen_vData[0][0], sakura[i].Screen_vData[0][1]); path.quadTo(sakura[i].Screen_cData[0][0], sakura[i].Screen_cData[0][1], sakura[i].Screen_vData[1][0], sakura[i].Screen_vData[1][1]); path.quadTo(sakura[i].Screen_cData[1][0], sakura[i].Screen_cData[1][1], sakura[i].Screen_vData[0][0], sakura[i].Screen_vData[0][1]); path.closePath(); } g2.setColor(Color.pink); g2.fill(path); } /*再描画を行うメソッド*/ public void run(){ for(int i = 0; i < 1000; i++){ repaint(); try{ Thread.sleep(10); } catch(InterruptedException e){ } } } }
コード public class Sakura extends Thread{ int Vertex_data[][] = { { 1, 1, 0}, //点P0 { -1, -1, 0} }; //点P1 //頂点データ double Screen_vData[][] = new double[2][3]; //表示頂点データ int Control_data[][] = { {-1, 1, 0}, //点P0から点P1 {1, -1, 0} }; //点P1から点P0 //曲線描くときのコントロールデータ double Screen_cData[][] = new double[2][3]; //表示コントロールデータ int scale = 10; //描画倍数 double phi; //x軸周りの回転角 double theta; //y軸周りの回転角 Point point; //表示したい点の座標 int time; //開始時間 /*Sakuraクラスのコンストラクタ*/ public Sakura(int pointX, int pointY, int time){ this.time = time; phi = 0; theta = 0; point = new Point(pointX, pointY); } /*runメソッド*/ public void run(){ try{ Thread.sleep(time); } catch(InterruptedException e){ } for(int i = 0; i < 1000; i++){ try{ Thread.sleep(5); } catch(InterruptedException e){ } phi += Math.PI /50; //角度変更処理 theta += Math.PI / 50; //角度変更処理 point.y += 1; //落下処理 setRotPosition(); } } /*回転後、座標を更新するメソッド*/ public void setRotPosition(){ for(int i = 0; i < Vertex_data.length; i++){ //回転後の頂点座標 double rvx = Vertex_data[i][0] * Math.cos(theta) + Vertex_data[i][2] * Math.sin(theta); double rvy = Vertex_data[i][0] * Math.sin(phi) * Math.sin(theta) + Vertex_data[i][1] * Math.cos(phi) - Vertex_data[i][2] * Math.cos(phi) * Math.cos(theta); double rvz = - Vertex_data[i][0] * Math.cos(phi) * Math.sin(theta) + Vertex_data[i][1] * Math.sin(phi) + Vertex_data[i][2] * Math.cos(phi) * Math.cos(theta); //回転後のコントロールデータ double rcx = Control_data[i][0] * Math.cos(theta) + Control_data[i][2] * Math.sin(theta); double rcy = Control_data[i][0] * Math.sin(phi) * Math.sin(theta) + Control_data[i][1] * Math.cos(phi) - Control_data[i][2] * Math.cos(phi) * Math.cos(theta); double rcz = - Control_data[i][0] * Math.cos(phi) * Math.sin(theta) + Control_data[i][1] * Math.sin(phi) + Control_data[i][2] * Math.cos(phi) * Math.cos(theta); Screen_vData[i][0] = point.x + (rvx * scale); Screen_vData[i][1] = point.y - (rvy * scale); Screen_vData[i][2] = rvz * scale; Screen_cData[i][0] = point.x + (rcx * scale); Screen_cData[i][1] = point.y - (rcy * scale); Screen_cData[i][2] = rcz * scale; } } }
このプログラムで、落下する花びらの枚数を5枚くらいにすると綺麗に描画されるのですが、100枚とか枚数を増やすと花びらの色が薄くなったり、画面がかくかくになったりと綺麗に描画されません。
枚数を増やすと処理が多くなってこのようなことになってしまうと思うのですが、少しでも綺麗に描画する方法はないのでしょうか?
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/06/01 00:16