使用GDI+实现光束效果
2007-03-08 12:08
381 查看
使用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();
}
}
}
相关文章推荐
- Asp.net 使用GDI+实现alpha透明效果
- 在WindowsXP下使用GDI+1.1实现模糊等高级效果
- 使用GDI+实现圆形进度条控件的平滑效果
- 使用jQuery.animate实现简单的页面切换效果
- 使用openSpeDiv方法实现Ecshop登录弹窗框效果
- Android使用ListView实现滚轮的动画效果
- 不使用left-join等多表关联查询,只用单表查询和Java程序,简便实现“多表查询”效果
- 在网络7层协议中,如果想使用UDP协议达到TCP协议的效果,可以在哪层做文章?(QQ 为什么采用 UDP 协议,而不采用 TCP 协议实现?)
- [Android] PorterDuff使用实例----实现新浪微博图片下载效果
- ViewFlipper的简单使用实现图片轮播效果
- OpenGL 使用混合来实现半透明效果
- 使用AjaxPro实现ajax效果
- CSS实现的排行榜效果,不使用OL
- 使用javascript实现拖拽效果
- Android中如何使用ViewPager实现类似laucher左右拖动效果
- Android---使用ViewPager来实现屏幕滑动效果
- [Egret学习笔记 七]使用skewX skewY实现图片翻转效果
- 使用viewGroupe实现左右拖到的效果
- Android提高篇之自定义dialog实现processDialog“正在加载”效果、使用Animation实现图片旋转
- Android shape的使用实现圆角,虚线,渐变等效果