fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace アフィン変換サンプル___
  11. {
  12. public partial class Form1 : Form
  13. {
  14. static PointF[] Arrow = new PointF[] { new PointF(0, 2), new PointF(1.5f, 1), new PointF(1, 1), new PointF(1, -1), new PointF(-1, -1), new PointF(-1, 1), new PointF(-1.5f, 1) };
  15. PointF[] ArrowD = new PointF[Arrow.Count()];
  16.  
  17. double Direction = 0;
  18. float Sc = 32;//Scale. コントロールに同名の何かが会ったから短くした。
  19.  
  20. uint Mode = 3;
  21.  
  22. public Form1()
  23. {
  24. InitializeComponent();
  25. Application.Idle += new EventHandler(OnIdle);
  26. }
  27.  
  28. void OnIdle(object sender, EventArgs e)
  29. {
  30. PointF Move= new PointF(this.ClientSize.Width/2.0f,this.ClientSize.Height/2.0f);
  31.  
  32. for (int i = 0; i < Arrow.Count(); i++)
  33. {
  34. ArrowD[i] = TransForm(Arrow[i], Direction, new SizeF(Sc, Sc), Move);//大変換!!
  35. }
  36. this.Invalidate(false);
  37. System.Threading.Thread.Sleep(15);
  38. }
  39.  
  40. private void Form1_Paint(object sender, PaintEventArgs e)//event
  41. {
  42. Graphics g = e.Graphics;
  43. g.FillPolygon(Brushes.Green, ArrowD);//多角形塗りつぶし。
  44.  
  45. float X = this.ClientSize.Width / 2;
  46. float Y = this.ClientSize.Height / 2;
  47. float L = 8;
  48.  
  49. g.DrawLine(Pens.Black, X - L, Y, X + L, Y);
  50. g.DrawLine(Pens.Black, X, Y - L, X, Y + L);
  51. }
  52.  
  53. private void Form1_MouseMove(object sender, MouseEventArgs e)//event
  54. {
  55. float X = this.ClientSize.Width/2.0f-e.X;
  56. float Y = this.ClientSize.Height/2.0f-e.Y;
  57.  
  58. if ((Mode&1) !=0) Direction = Math.Atan2(Y, X) + ToRadian(90);
  59. if ((Mode&2) !=0) Sc = (float)Math.Sqrt(X * X + Y * Y);
  60.  
  61. }
  62.  
  63. private void Form1_MouseDown(object sender, MouseEventArgs e)//event
  64. {
  65. Mode %= 3;
  66. Mode++;
  67. }
  68.  
  69. double SingleRadian = Math.PI / 180.0;
  70.  
  71. public double ToRadian(double Degree)
  72. {
  73. return SingleRadian * (Degree % 360.0);
  74. }
  75. public double ToDegree(double Radian)
  76. {
  77. return (Radian / SingleRadian) % 360.0;
  78. }
  79. public PointF TransForm(PointF Pos, double RotRadian, SizeF Scale, PointF Move)
  80. {
  81. PointF Ret = new PointF();
  82. double Sin = Math.Sin(RotRadian);
  83. double Cos = Math.Cos(RotRadian);
  84.  
  85. Ret.X = (float)(((Pos.X * Scale.Width) * Cos) - ((Pos.Y * Scale.Height) * Sin) + Move.X);
  86. Ret.Y = (float)(((Pos.X * Scale.Width) * Sin) + ((Pos.Y * Scale.Height) * Cos) + Move.Y);
  87.  
  88. return Ret;
  89. }
  90.  
  91. }
  92. }
  93.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty