回転の仕方について質問させていただきます。
rotateメソッドを使って原点対象に回転させることは出来たのですが、x軸対象やy軸対象に回転させるにはどうすればいいのでしょうか?
このx軸y軸に回転する方法を教えていただきたいです。
よろしくお願いします。
追記
原点対象のプログラムを載せておきます
コード public class MainActivity extends Activity implements Runnable{ Handler handler = new Handler(); Thread thread; CanvasView canvasview; Cherry cherry; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); canvasview = new CanvasView(this); setContentView(canvasview); cherry = new Cherry(); canvasview.getCherry(cherry); cherry.start(); thread = new Thread(this); thread.start(); } public void run(){ handler.post(new Runnable() { @Override public void run(){ canvasview.invalidate(); handler.postDelayed(this, 1); } }); } }
コード public class CanvasView extends View{ Cherry cherry; public CanvasView(Context context) { super(context); } public void getCherry(Cherry cherry){ this.cherry = cherry; } @Override public void onDraw(Canvas canvas){ canvas.translate(1000, 200); canvas.rotate(cherry.angle); canvas.drawRect(-50, -100, 50, 100, cherry.paint); }
コード public class Cherry extends Thread{ Paint paint = new Paint(); Path path = new Path(); int angle = 0; public void run(){ paint.setColor(Color.MAGENTA); paint.setStyle(Paint.Style.FILL); for(int i = 0; i < 360; i++){ try{ Thread.sleep(5); } catch(InterruptedException e){ } angle = angle + 1; } } }
回答2件
あなたの回答
tips
プレビュー