// A simple ripple test.// I make no warrantees as to it's stability. Use at your own risk.// If you make any improvements on it please send them to me.// Written by: James O'Reilly, SynergyMedia, Inc. james@synergymedia.net//// To compile at the console:// csc.exe /out:.\Ripple.exe /t:exe /r:System.dll Ripple.csusing System;using System.Drawing;using System.Drawing.Drawing2D;using System.Windows.Forms;namespace SynergyMediaInc{class Ripple: Form{RippleObj[] rippleList = new RippleObj[254];int ripplePntr = 0;bool mouseDown = false;Point ptMouse = Point.Empty;Font font1;private Timer timer1 = new Timer();private long ticks = 0;// if you don't know i'm not tellingpublic static void Main(){Application.Run(new Ripple());}public Ripple(){Text = "Ripple";BackColor = Color.Blue;ForeColor = Color.White;ClientSize += ClientSize; // Double the client area.font1 = new Font("Times New Roman", 144);// reduce flickerSetStyle(ControlStyles.UserPaint, true);SetStyle(ControlStyles.AllPaintingInWmPaint, true);SetStyle(ControlStyles.DoubleBuffer, true);// we need a timer to animatetimer1.Interval = 50;timer1.Tick += new System.EventHandler(Timer1OnTick);timer1.Start();}// add a new ripple to the list and flag the mouse as downprotected override void OnMouseDown(MouseEventArgs mea){if (mea.Button == MouseButtons.Left){AddRipple();mouseDown = true;}}// record the current mouse locationprotected override void OnMouseMove(MouseEventArgs mea){ptMouse = new Point(mea.X, mea.Y);}// flag the mouse as up and stop adding ripples to the listprotected override void OnMouseUp(MouseEventArgs mea){if (mea.Button == MouseButtons.Left)mouseDown = false;}// add the recorded mouse point to the ripple listprivate void AddRipple(){rippleList[ripplePntr] = new RippleObj(ptMouse);ripplePntr++;if (ripplePntr >= rippleList.Length)ripplePntr = 0;}// draw the ripplesprotected override void OnPaint(PaintEventArgs pea){Color clr;float w;Graphics g = pea.Graphics;g.SmoothingMode = SmoothingMode.HighQuality;g.Clear(BackColor);// paint the captionfloat cx = g.VisibleClipBounds.Size.Width;float cy = g.VisibleClipBounds.Size.Height;SizeF sizef = g.MeasureString(Text, font1);Brush brush1 = new SolidBrush(Color.DarkRed);g.DrawString(Text, font1, brush1,(cx - sizef.Width) / 2,(cy - sizef.Height) / 2);// loop through the ripple listfor (int i = 0; i < rippleList.Length; i++){if ((rippleList[i] != null) && (rippleList[i].loc != Point.Empty)){// set the transparency and line width according to the radius sizeclr = Color.FromArgb(255-rippleList[i].rad,255,255,255);w = 0.03f * rippleList[i].rad;// draw the ellipseg.DrawEllipse(new Pen(clr, w),rippleList[i].loc.X - rippleList[i].rad,rippleList[i].loc.Y - rippleList[i].rad/4,rippleList[i].rad * 2,rippleList[i].rad/2);// expand the radiusrippleList[i].rad += 10;// see if the ripple is too bigif (rippleList[i].rad > 255){//RemoveRipple(i);rippleList[i].Reset();}}}}// automatically called by the timer according to the interval setprivate void Timer1OnTick(object obj, EventArgs ea){ticks++;// check to see if the user has the button pressed and add a ripple to the list if they doif (mouseDown)AddRipple();// invalidate the graphics object so it will repaintInvalidate();}}// this class defines the make-up of a ripple objectclass RippleObj{public Point loc = Point.Empty; // the location of the ripplepublic int rad = 0; // the size of it's radiuspublic RippleObj(){Reset();}public RippleObj(Point mLoc){Reset();loc = mLoc;}public void Reset(){loc = Point.Empty;rad = 0;}}
James O'Reilly is working with SynergyMedia, Inc.
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: