使用GDI+实现光束效果

                使用GDI+实现光束效果 

                                                                        作者 jlgzw

//--------------------------------------------------------------------------------------------------------------
//   RandomRound.cs    @ 2007 by jl gzw
//--------------------------------------------------------------------------------------------------------------
using System;
using System.Drawing;
using System.Windows.Forms;

namespace RandomRound
{
    public class RandomRound : Form
    {
        //圆的大小
        const int cxWidth = 50;
        const int cyHeight = 50;
        //点的数目
        const int iPtNum = 360;
        //圆移动的偏移量
        int cxMove = 5;
        int cyMove = 5;
        //圆的坐标
        int  x, y;
        //窗口的中心点
        static Point CenterPt;

        static void Main()
        { 
            Application.Run(new RandomRound());
        }
        public RandomRound()
        {
            this.Text = "RandomRound";
            this.BackColor = Color.Black;

            CenterPt = new Point(ClientRectangle.Width / 2, ClientSize.Height / 2);

            Timer timer = new Timer();
            timer.Interval = 100;
            timer.Tick += new EventHandler(TimerOnTick);
            timer.Start();
        }
        protected override void OnResize(EventArgs e)
        {
            x = ClientSize.Width / 2;
            y = ClientSize.Height / 2;           
        }
        void TimerOnTick(object obj, EventArgs ea)
        {
            Random rand = new Random();

            Graphics grfx = CreateGraphics();
  
            grfx.Clear(Color.Black);                 

            x += cxMove;
            y += cyMove;

            if((x + cxWidth >= ClientSize.Width) || (x <= 0))
                cxMove = -cxMove;
            if ((y + cyHeight >= ClientSize.Height) || (y <= 0))
                cyMove = -cyMove;

            Color color = Color.FromArgb(rand.Next(256), rand.Next(256), rand.Next(256));
   
            PointF[] aptf = new PointF[iPtNum];

            for (int i = 0; i < iPtNum; i++)
            {
                double dAng = i * 2 * Math.PI / (iPtNum - 1);

                aptf[i].X =x + (cxWidth - 1) / 2f * (1 + (float)Math.Cos(dAng));
                aptf[i].Y =y + (cyHeight - 1) / 2f * (1 + (float)Math.Sin(dAng));

                grfx.DrawLine(new Pen(color),CenterPt, aptf[i]);
            }

            grfx.FillPolygon(new SolidBrush(color), aptf);

            grfx.Dispose();
        }
 
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值