Click here to Skip to main content
15,890,506 members
Articles / Programming Languages / C#
Article

Wave or Lake effect control

Rate me:
Please Sign up or sign in to vote.
4.60/5 (17 votes)
11 Jun 20032 min read 85.7K   3.5K   64   7
Implementation of wave or lake effect in C#

Image 1

Introduction

The WaveControl control allows you to include the lake effect that has been available on web pages for the past 6 or 7 years, from groups like Anfy (www.anfy.com). With a name like Lyquidity, and corny as it is, liquid motion effects are used in splash screens and in some marketing materials. We wanted to include the wave or lake effect to the repertoire but were unable to find a C# implementation so we decided to create one ourselves.

The control

WaveControl inherits from System.Windows.Forms.Control and so implements its own painting to animate the rippling water effect. The actions taken by the control are to:

  • Load an image
  • Create an inverted copy of the image
  • Create the frames for animation
  • Run the animation

The real work is done in the DrawLakeEffect() method. This method creates a frame of the animation at a time. There are plenty of notes in this method explaining what it does and how its done, so no explanation is included here (at least for now).

The animation is controlled by a timer and on each tick a frame is drawn onto the controls surface. Though the frame rate is fixed (you can change that), the user can control the number of frames generated and so the length of the animation. Other aspects of the animation that can be controlled include, the wave height, the number of ripples and the damping factor used.

A default image is displayed (mine), but an alternative image can be passed to the control. The control will size itself to the width of the image and 2 * the height.

VS.NET version

We use VS.NET 2003 for development work, so the .sln and .csproj files are in this format and cannot be opened in the earlier version of VS.NET. The good news is that no VS.NET 2003 specific features are used, so creating a project for the earlier will be straightforward. The one thing to bear in mind is that WaveControl.cs uses an unsafe {} block while generating the animation frames, so you will need to set this configuration property to true before the code will compile.

Things that could be done

The Anfy control includes randomization features to simulate wind and to give a more natural appearance and adding such effects would be good. The use of a timer works just fine, but encapsulating the painting in a thread would be better.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United Kingdom United Kingdom
Independent software development for clients including Microsoft. Design and development of modules for financial reporting and business intelligence.

Comments and Discussions

 
GeneralMy vote of 1 Pin
HaflBit20-Mar-10 22:53
HaflBit20-Mar-10 22:53 
GeneralOverall nice control Pin
Catalin Murariu9-Feb-07 4:04
Catalin Murariu9-Feb-07 4:04 
GeneralMemory leak or not Pin
akorolev1020-Mar-04 6:13
akorolev1020-Mar-04 6:13 
GeneralRe: Memory leak or not Pin
Bill Seddon20-Mar-04 22:24
Bill Seddon20-Mar-04 22:24 
GeneralEnhancement Pin
Ed Din ar Qadiyyeh31-Aug-03 19:28
Ed Din ar Qadiyyeh31-Aug-03 19:28 
GeneralNice work but.. Pin
TheGlynn12-Jun-03 5:48
TheGlynn12-Jun-03 5:48 
GeneralRe: Nice work but.. Pin
Bill Seddon12-Jun-03 5:54
Bill Seddon12-Jun-03 5:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.