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. using System.Drawing.Drawing2D;
  10. using System.Drawing.Imaging;
  11.  
  12. namespace WindowsFormsApplication1
  13. {
  14. public partial class Form1 : Form
  15. {
  16. public Form1()
  17. {
  18. InitializeComponent();
  19. this.Load += new EventHandler(Form1_Load);
  20. }
  21. const int cw = 400;
  22. const int ch = 400;
  23. Bitmap[] bmp = new Bitmap[2];
  24. int screen = 0;
  25. PictureBox pictureBox1 = new PictureBox();
  26. Timer timer1 = new Timer();
  27.  
  28. GraphicsPath gp = new GraphicsPath();
  29. private void Form1_Load(object sender, EventArgs e)
  30. {
  31. this.ClientSize = new Size(cw, ch);
  32. this.Controls.Add(pictureBox1);
  33. pictureBox1.Dock = DockStyle.Fill;
  34.  
  35.  
  36. bmp[0] = new Bitmap(cw, ch, PixelFormat.Format32bppArgb);
  37. bmp[1] = new Bitmap(cw, ch, PixelFormat.Format32bppArgb);
  38.  
  39. PointF[] tp = new PointF[]
  40. {
  41. new PointF(0.0f,10.0f),
  42. new PointF(10.0f,0.0f),
  43. new PointF(0.0f,-10.0f),
  44. };
  45. gp.AddLine(0.0f, 0.0f, 20.0f, 0.0f);
  46. gp.AddPolygon(tp);
  47.  
  48. timer1.Interval = 1000 / 60;
  49. timer1.Tick += new EventHandler(timer1_Tick);
  50. timer1.Enabled = true;
  51. }
  52. const float vec = 5.0f;
  53. float vx;
  54. float vy;
  55. int phase = 0;
  56. Random rand = new Random();
  57. double baseangle;
  58. double angle = 0.0;
  59. int count = 0;
  60. PointF p = new PointF(200.0f, 200.0f);
  61. private void timer1_Tick(object sender, EventArgs e)
  62. {
  63. switch (phase)
  64. {
  65. //思考フェーズ
  66. case 0:
  67. baseangle = rand.Next(0, 90)-45;
  68. phase = 1;
  69. break;
  70. //回転フェーズ
  71. case 1:
  72. if (baseangle != 0)
  73. {
  74. if (baseangle > 0)
  75. {
  76. angle++;
  77. baseangle--;
  78. }
  79. else
  80. {
  81. angle--;
  82. baseangle++;
  83. }
  84. }
  85. else
  86. {
  87. double subangle = angle / (180 / Math.PI);
  88. vx = vec * (float)Math.Cos(subangle);
  89. vy = vec * (float)Math.Sin(subangle);
  90. phase = 2;
  91. }
  92. break;
  93. //移動フェーズ
  94. case 2:
  95. if (count < 20)
  96. {
  97. p.X += vx;
  98. p.Y += vy;
  99. count++;
  100. if (p.X < 20 || p.X >= cw-20 || p.Y < 20 || p.Y >= ch-20)
  101. {
  102. count = 0;
  103. baseangle = 180;
  104. phase = 1;
  105. }
  106. }
  107. else
  108. {
  109. count = 0;
  110. phase = 0;
  111. }
  112. break;
  113. default:
  114. break;
  115. }
  116. this.Text = phase.ToString();
  117. //double angle = 45.0;// / (180.0 / Math.PI);
  118. using (Graphics g = Graphics.FromImage(bmp[screen]))
  119. {
  120. g.SmoothingMode = SmoothingMode.AntiAlias;
  121. g.FillRectangle(Brushes.White, 0, 0, cw, ch);
  122.  
  123. Matrix m = new Matrix();
  124. m.Translate(p.X, p.Y);
  125. m.Rotate((float)angle);
  126. g.Transform = m;
  127. g.DrawPath(Pens.Blue, gp);
  128. }
  129. pictureBox1.Image = bmp[screen];
  130. screen ^= 1;
  131. }
  132. }
  133. }
  134.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty