using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.Load += new EventHandler(Form1_Load);
}
const int cw = 400;
const int ch = 400;
Bitmap[] bmp = new Bitmap[2];
int screen = 0;
PictureBox pictureBox1 = new PictureBox();
Timer timer1 = new Timer();
GraphicsPath gp = new GraphicsPath();
private void Form1_Load(object sender, EventArgs e)
{
this.ClientSize = new Size(cw, ch);
this.Controls.Add(pictureBox1);
pictureBox1.Dock = DockStyle.Fill;
bmp[0] = new Bitmap(cw, ch, PixelFormat.Format32bppArgb);
bmp[1] = new Bitmap(cw, ch, PixelFormat.Format32bppArgb);
PointF[] tp = new PointF[]
{
new PointF(0.0f,10.0f),
new PointF(10.0f,0.0f),
new PointF(0.0f,-10.0f),
};
gp.AddLine(0.0f, 0.0f, 20.0f, 0.0f);
gp.AddPolygon(tp);
timer1.Interval = 1000 / 60;
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Enabled = true;
}
const float vec = 5.0f;
float vx;
float vy;
int phase = 0;
Random
rand = new Random
(); double baseangle;
double angle = 0.0;
int count = 0;
PointF p = new PointF(200.0f, 200.0f);
private void timer1_Tick(object sender, EventArgs e)
{
switch (phase)
{
//思考フェーズ
case 0:
baseangle
= rand.
Next(0, 90)-45; phase = 1;
break;
//回転フェーズ
case 1:
if (baseangle != 0)
{
if (baseangle > 0)
{
angle++;
baseangle--;
}
else
{
angle--;
baseangle++;
}
}
else
{
double subangle = angle / (180 / Math.PI);
vx = vec * (float)Math.Cos(subangle);
vy = vec * (float)Math.Sin(subangle);
phase = 2;
}
break;
//移動フェーズ
case 2:
if (count < 20)
{
p.X += vx;
p.Y += vy;
count++;
if (p.X < 20 || p.X >= cw-20 || p.Y < 20 || p.Y >= ch-20)
{
count = 0;
baseangle = 180;
phase = 1;
}
}
else
{
count = 0;
phase = 0;
}
break;
default:
break;
}
this.Text = phase.ToString();
//double angle = 45.0;// / (180.0 / Math.PI);
using (Graphics g = Graphics.FromImage(bmp[screen]))
{
g.SmoothingMode = SmoothingMode.AntiAlias;
g.FillRectangle(Brushes.White, 0, 0, cw, ch);
Matrix m = new Matrix();
m.Translate(p.X, p.Y);
m.Rotate((float)angle);
g.Transform = m;
g.DrawPath(Pens.Blue, gp);
}
pictureBox1.Image = bmp[screen];
screen ^= 1;
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uQ29sbGVjdGlvbnMuR2VuZXJpYzsKdXNpbmcgU3lzdGVtLkNvbXBvbmVudE1vZGVsOwp1c2luZyBTeXN0ZW0uRGF0YTsKdXNpbmcgU3lzdGVtLkRyYXdpbmc7CnVzaW5nIFN5c3RlbS5MaW5xOwp1c2luZyBTeXN0ZW0uVGV4dDsKdXNpbmcgU3lzdGVtLldpbmRvd3MuRm9ybXM7CnVzaW5nIFN5c3RlbS5EcmF3aW5nLkRyYXdpbmcyRDsKdXNpbmcgU3lzdGVtLkRyYXdpbmcuSW1hZ2luZzsKCm5hbWVzcGFjZSBXaW5kb3dzRm9ybXNBcHBsaWNhdGlvbjEKewogICAgcHVibGljIHBhcnRpYWwgY2xhc3MgRm9ybTEgOiBGb3JtCiAgICB7CiAgICAgICAgcHVibGljIEZvcm0xKCkKICAgICAgICB7CiAgICAgICAgICAgIEluaXRpYWxpemVDb21wb25lbnQoKTsKICAgICAgICAgICAgdGhpcy5Mb2FkICs9IG5ldyBFdmVudEhhbmRsZXIoRm9ybTFfTG9hZCk7CiAgICAgICAgfQogICAgICAgIGNvbnN0IGludCBjdyA9IDQwMDsKICAgICAgICBjb25zdCBpbnQgY2ggPSA0MDA7CiAgICAgICAgQml0bWFwW10gYm1wID0gbmV3IEJpdG1hcFsyXTsKICAgICAgICBpbnQgc2NyZWVuID0gMDsKICAgICAgICBQaWN0dXJlQm94IHBpY3R1cmVCb3gxID0gbmV3IFBpY3R1cmVCb3goKTsKICAgICAgICBUaW1lciB0aW1lcjEgPSBuZXcgVGltZXIoKTsKCiAgICAgICAgR3JhcGhpY3NQYXRoIGdwID0gbmV3IEdyYXBoaWNzUGF0aCgpOwogICAgICAgIHByaXZhdGUgdm9pZCBGb3JtMV9Mb2FkKG9iamVjdCBzZW5kZXIsIEV2ZW50QXJncyBlKQogICAgICAgIHsKICAgICAgICAgICAgdGhpcy5DbGllbnRTaXplID0gbmV3IFNpemUoY3csIGNoKTsKICAgICAgICAgICAgdGhpcy5Db250cm9scy5BZGQocGljdHVyZUJveDEpOwogICAgICAgICAgICBwaWN0dXJlQm94MS5Eb2NrID0gRG9ja1N0eWxlLkZpbGw7CgogICAgICAgICAgICAKICAgICAgICAgICAgYm1wWzBdID0gbmV3IEJpdG1hcChjdywgY2gsIFBpeGVsRm9ybWF0LkZvcm1hdDMyYnBwQXJnYik7CiAgICAgICAgICAgIGJtcFsxXSA9IG5ldyBCaXRtYXAoY3csIGNoLCBQaXhlbEZvcm1hdC5Gb3JtYXQzMmJwcEFyZ2IpOwoKICAgICAgICAgICAgUG9pbnRGW10gdHAgPSBuZXcgUG9pbnRGW10KICAgICAgICAgICAgewogICAgICAgICAgICAgICAgbmV3IFBvaW50RigwLjBmLDEwLjBmKSwKICAgICAgICAgICAgICAgIG5ldyBQb2ludEYoMTAuMGYsMC4wZiksCiAgICAgICAgICAgICAgICBuZXcgUG9pbnRGKDAuMGYsLTEwLjBmKSwKICAgICAgICAgICAgfTsKICAgICAgICAgICAgZ3AuQWRkTGluZSgwLjBmLCAwLjBmLCAyMC4wZiwgMC4wZik7CiAgICAgICAgICAgIGdwLkFkZFBvbHlnb24odHApOwoKICAgICAgICAgICAgdGltZXIxLkludGVydmFsID0gMTAwMCAvIDYwOwogICAgICAgICAgICB0aW1lcjEuVGljayArPSBuZXcgRXZlbnRIYW5kbGVyKHRpbWVyMV9UaWNrKTsKICAgICAgICAgICAgdGltZXIxLkVuYWJsZWQgPSB0cnVlOwogICAgICAgIH0KICAgICAgICBjb25zdCBmbG9hdCB2ZWMgPSA1LjBmOwogICAgICAgIGZsb2F0IHZ4OwogICAgICAgIGZsb2F0IHZ5OwogICAgICAgIGludCBwaGFzZSA9IDA7CiAgICAgICAgUmFuZG9tIHJhbmQgPSBuZXcgUmFuZG9tKCk7CiAgICAgICAgZG91YmxlIGJhc2VhbmdsZTsKICAgICAgICBkb3VibGUgYW5nbGUgPSAwLjA7CiAgICAgICAgaW50IGNvdW50ID0gMDsKICAgICAgICBQb2ludEYgcCA9IG5ldyBQb2ludEYoMjAwLjBmLCAyMDAuMGYpOwogICAgICAgIHByaXZhdGUgdm9pZCB0aW1lcjFfVGljayhvYmplY3Qgc2VuZGVyLCBFdmVudEFyZ3MgZSkKICAgICAgICB7CiAgICAgICAgICAgIHN3aXRjaCAocGhhc2UpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIC8v5oCd6ICD44OV44Kn44O844K6CiAgICAgICAgICAgICAgICBjYXNlIDA6CiAgICAgICAgICAgICAgICAgICAgYmFzZWFuZ2xlID0gcmFuZC5OZXh0KDAsIDkwKS00NTsKICAgICAgICAgICAgICAgICAgICBwaGFzZSA9IDE7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAvL+Wbnui7ouODleOCp+ODvOOCugogICAgICAgICAgICAgICAgY2FzZSAxOgogICAgICAgICAgICAgICAgICAgIGlmIChiYXNlYW5nbGUgIT0gMCkKICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChiYXNlYW5nbGUgPiAwKQogICAgICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBhbmdsZSsrOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgYmFzZWFuZ2xlLS07CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBhbmdsZS0tOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgYmFzZWFuZ2xlKys7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgZG91YmxlIHN1YmFuZ2xlID0gYW5nbGUgLyAoMTgwIC8gTWF0aC5QSSk7CiAgICAgICAgICAgICAgICAgICAgICAgIHZ4ID0gdmVjICogKGZsb2F0KU1hdGguQ29zKHN1YmFuZ2xlKTsKICAgICAgICAgICAgICAgICAgICAgICAgdnkgPSB2ZWMgKiAoZmxvYXQpTWF0aC5TaW4oc3ViYW5nbGUpOwogICAgICAgICAgICAgICAgICAgICAgICBwaGFzZSA9IDI7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgLy/np7vli5Xjg5Xjgqfjg7zjgroKICAgICAgICAgICAgICAgIGNhc2UgMjoKICAgICAgICAgICAgICAgICAgICBpZiAoY291bnQgPCAyMCkKICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgIHAuWCArPSB2eDsKICAgICAgICAgICAgICAgICAgICAgICAgcC5ZICs9IHZ5OwogICAgICAgICAgICAgICAgICAgICAgICBjb3VudCsrOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAocC5YIDwgMjAgfHwgcC5YID49IGN3LTIwIHx8IHAuWSA8IDIwIHx8IHAuWSA+PSBjaC0yMCkKICAgICAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgY291bnQgPSAwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgYmFzZWFuZ2xlID0gMTgwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGhhc2UgPSAxOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgIGNvdW50ID0gMDsKICAgICAgICAgICAgICAgICAgICAgICAgcGhhc2UgPSAwOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdGhpcy5UZXh0ID0gcGhhc2UuVG9TdHJpbmcoKTsKICAgICAgICAgICAgLy9kb3VibGUgYW5nbGUgPSA0NS4wOy8vIC8gKDE4MC4wIC8gTWF0aC5QSSk7CiAgICAgICAgICAgIHVzaW5nIChHcmFwaGljcyBnID0gR3JhcGhpY3MuRnJvbUltYWdlKGJtcFtzY3JlZW5dKSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgZy5TbW9vdGhpbmdNb2RlID0gU21vb3RoaW5nTW9kZS5BbnRpQWxpYXM7CiAgICAgICAgICAgICAgICBnLkZpbGxSZWN0YW5nbGUoQnJ1c2hlcy5XaGl0ZSwgMCwgMCwgY3csIGNoKTsKCiAgICAgICAgICAgICAgICBNYXRyaXggbSA9IG5ldyBNYXRyaXgoKTsKICAgICAgICAgICAgICAgIG0uVHJhbnNsYXRlKHAuWCwgcC5ZKTsKICAgICAgICAgICAgICAgIG0uUm90YXRlKChmbG9hdClhbmdsZSk7CiAgICAgICAgICAgICAgICBnLlRyYW5zZm9ybSA9IG07CiAgICAgICAgICAgICAgICBnLkRyYXdQYXRoKFBlbnMuQmx1ZSwgZ3ApOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHBpY3R1cmVCb3gxLkltYWdlID0gYm1wW3NjcmVlbl07CiAgICAgICAgICAgIHNjcmVlbiBePSAxOwogICAgICAgIH0KICAgIH0KfQo=