2014-01-15 65 views
0

我的代碼繪製了一個圓,然後是從圓的中心到圓的半徑大小的一條線,並且線正在移動1個角度。如何在移動的線後畫一條線索?

現在我想讓這條線在雷達效應之後留下一些線索/痕跡。

private void pictureBox1_Paint(object sender, PaintEventArgs e) 
     { 
      anglecounter += 1; 
      double x = pictureBox1.Size.Width/2 + 256 *Math.Cos(anglecounter * Math.PI/180); 
      double y = pictureBox1.Size.Height/2 +256 * Math.Sin(anglecounter * Math.PI/180); 
      CloudEnteringAlert.Paint(e.Graphics, factor, distance); 
      e.Graphics.DrawLine(
      new Pen(Color.Red, 2f), 
      new Point(pictureBox1.Size.Width/2, pictureBox1.Size.Height/2), 
      new Point((int)x, (int)y)); 

      e.Graphics.DrawEllipse(
       new Pen(Color.Red, 2f), 
       0, 0, pictureBox1.Size.Width, pictureBox1.Size.Height); 
     } 

我該怎麼做?

編輯**

這就是我現在做的我加了窗體頂部:

PointF _pt = new PointF(0F, 0F); 
PointF _pt2 = new PointF(1F, 1F); 
PointF _pt3 = new PointF(2F, 2F); 
Color _lineColor = Color.FromArgb(0, 255, 0); 
private double anglecounter1; 

然後Paint事件現在這個樣子:

private void pictureBox1_Paint(object sender, PaintEventArgs e) 
     { 

      anglecounter += 1; 
      anglecounter1 += 0.5; 
      double x = pictureBox1.Size.Width/2 + 256 *Math.Cos(anglecounter * Math.PI/180); 
      double y = pictureBox1.Size.Height/2 +256 * Math.Sin(anglecounter * Math.PI/180); 
      double x1 = pictureBox1.Size.Width/2 + 256 * Math.Cos(anglecounter1 * Math.PI/180); 
      double y1 = pictureBox1.Size.Height/2 + 256 * Math.Sin(anglecounter1 * Math.PI/180); 
      CloudEnteringAlert.Paint(e.Graphics, factor, distance); 
      e.Graphics.DrawLine(
      new Pen(Color.Red, 2f), 
      new Point(pictureBox1.Size.Width/2, pictureBox1.Size.Height/2), 
      new Point((int)x, (int)y)); 

      e.Graphics.DrawEllipse(
       new Pen(Color.Red, 2f), 
       0, 0, pictureBox1.Size.Width, pictureBox1.Size.Height); 

      // create the fade path and gradient 
      GraphicsPath gp = new GraphicsPath(FillMode.Winding); 
      gp.AddLine(new PointF((float)(pictureBox1.Size.Width/2), (float)(pictureBox1.Size.Height/2)),new PointF((float)x1,(float)y1)); 
      gp.AddCurve(new PointF[] { _pt2, _pt3, _pt }); 
      gp.AddLine(new PointF((float)x, (float)y), new PointF((float)(pictureBox1.Size.Width/2), (float)(pictureBox1.Size.Height/2))); 
      PathGradientBrush pgb = new PathGradientBrush(gp); 
      pgb.CenterPoint = new PointF((float)x1, (float)y1); 
      pgb.CenterColor = Color.FromArgb(128, _lineColor); 
      pgb.SurroundColors = new Color[] { Color.Empty }; 
      // draw the fade path 
      e.Graphics.FillPath(pgb, gp); 
     } 

但如果我在這種情況下沒有錯,那麼線索越慢,那麼線越快。跟蹤/追蹤也在線後面,但也在線前。林不知道,但那就是我看到的。那麼,什麼是錯的?

+0

代替繪製一個半徑的,畫兩條與僅稍微不同的角度。用小一點的角度畫一個比另一個稍微淡一點的。人眼將完成其餘的工作。 – Jon

+1

也許從這裏開始:http://msdn.microsoft.com/en-us/library/7fswd1t7(v=vs.110).aspx –

+0

創建一個餅圖片對象(可能是一個弧+三角形)並填充一個漸變這改變了alpha通道 – clcto

回答

0

另一種選擇是不要每次擦除圖像。取而代之的是,繪製半透明圈比上圖像:

// Initialize some dimensions 
int x = pictureBox1.Bounds.X; 
int y = pictureBox1.Bounds.Y; 
int w = Math.Min(pictureBox1.Bounds.Width, pictureBox1.Bounds.Height); 
int h = w; // Force square 
int centerX = w/2; 
int centerY = h/2; 
float radius = w - centerX; 
Graphics g = pictureBox1.CreateGraphics(); 
// First time draw a solid background then 
// each successive time cover with semi-transparent background 
Brush backGround = firstTime ? new SolidBrush(Color.FromArgb(255, 0, 0, 0)) : new SolidBrush(Color.FromArgb(10, 0, 0, 0)); 
firstTime = false; 
g.FillEllipse(backGround, 0, 0, w, h); 
float lineX = (float)(centerX + (radius * Math.Sin(anglecounter * (Math.PI/180)))); 
float lineY = (float)(centerX + (radius * Math.Cos(anglecounter * (Math.PI/180)))); 
anglecounter -= 1; 
g.DrawLine(new Pen(Color.Green, 3), centerX, centerY, lineX, lineY); 
g.DrawArc(new Pen(Color.Red, 4), new Rectangle(0, 0, w - 1, h - 1), 0, 360); 

產生以下結果: enter image description here