<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>You had me at "Hello World!" : Water Ripples</title><link>http://blogs.msdn.com/nikola/archive/tags/Water+Ripples/default.aspx</link><description>Tags: Water Ripples</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Building the Reallistic Water Ripples Sample in Silverlight</title><link>http://blogs.msdn.com/nikola/archive/2008/07/04/building-the-reallistic-water-ripples-sample-in-silverlight.aspx</link><pubDate>Fri, 04 Jul 2008 20:26:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8690195</guid><dc:creator>nikola</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/nikola/comments/8690195.aspx</comments><wfw:commentRss>http://blogs.msdn.com/nikola/commentrss.aspx?PostID=8690195</wfw:commentRss><description>&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Georgia size=3&gt;In this tutorial:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Georgia size=3&gt;- creating and rendering water ripples&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Georgia size=3&gt;- optimized image generation&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Georgia size=3&gt;- JPEG decoding component for Silverlight&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;A href="http://www.nokola.com/sources/water.zip"&gt;&lt;FONT face=Georgia color=#0000ff size=3&gt;Source code for this sample&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Georgia size=3&gt; &lt;/FONT&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;IFRAME style="WIDTH: 532px; HEIGHT: 446px" src="http://silverlight.services.live.com/invoke/61093/RainDrops/iframe.html" frameBorder=0 scrolling=no mce_src="http://silverlight.services.live.com/invoke/61093/RainDrops/iframe.html"&gt;&lt;/IFRAME&gt;&lt;/P&gt;
&lt;H2 style="MARGIN: 10pt 0in 0pt"&gt;&lt;FONT face="Trebuchet MS" color=#4f81bd size=4&gt;Algorithm&lt;/FONT&gt;&lt;/H2&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Georgia size=3&gt;The algorithm is based on &lt;/FONT&gt;&lt;A href="http://freespace.virgin.net/hugo.elias/graphics/x_water.htm"&gt;&lt;FONT face=Georgia size=3&gt;Hugo Elias’ 2D water tutorial&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Georgia size=3&gt;. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Georgia size=3&gt;On each render step we have the state of the water for the current frame and the previous frame.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Georgia size=3&gt;The state is stored in two 2-dimensional arrays of integers that are as big as the image.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Georgia size=3&gt;For each pixel position of the image we store the height of the water (or wave) in that position. 0 means “sea level”. Larger than 0 means that we have a raised wave, less than zero means that we have wave below “sea level”. We need information for both raised and low waves in order to be able to combine them.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Georgia size=3&gt;On each render step we use data from the current frame (Buffer2) and the previous frame (Buffer1) and &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;write the results into Buffer1.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=CodeCxSpFirst style="MARGIN: 6pt 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;damping = some non-integer between 0 and 1 (I use 0.94)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;for every non-edge element:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;loop&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Buffer2[x, y] = (Buffer1[x-1,y]&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Buffer1[x+1,y]&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Buffer1[x,y+1]&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Buffer1[x,y-1]) / 2 - Buffer2[x,y]&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9" face="Courier New" size=3&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;Buffer2[x,y] = Buffer2[x,y] * damping&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;end loop&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9" face="Courier New" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Swap the buffers &lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Display Buffer1&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=CodeCxSpLast style="MARGIN: 0in 0in 6pt"&gt;&lt;FONT size=3&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;end loop&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;o:p&gt;&lt;FONT face=Georgia size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Georgia size=3&gt;You can go ahead and look at Hugo’s explanation about why does this work, or continue reading here.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Georgia size=3&gt;Because the 2 buffers contain consecutive steps for the water, we can get the water velocity at a given location [x, y] by subtracting: Buffer2[x, y] – Buffer1[x, y]&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Georgia size=3&gt;Also we want the waves to spread out, so we smooth the buffers on every frame:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=CodeCxSpFirst style="MARGIN: 6pt 0in 0pt"&gt;&lt;SPAN style="mso-fareast-font-family: 'Times New Roman'; mso-bidi-language: AR-SA"&gt;&lt;FONT size=3&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Smoothed[x,y] = (Buffer1[x-1, y] +&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-fareast-font-family: 'Times New Roman'; mso-bidi-language: AR-SA"&gt;&lt;FONT size=3&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Buffer1[x+1, y] +&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-fareast-font-family: 'Times New Roman'; mso-bidi-language: AR-SA"&gt;&lt;FONT size=3&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Buffer1[x, y-1] +&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeCxSpLast style="MARGIN: 0in 0in 6pt"&gt;&lt;SPAN style="mso-fareast-font-family: 'Times New Roman'; mso-bidi-language: AR-SA"&gt;&lt;FONT size=3&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Buffer1[x, y+1]) / 4&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;o:p&gt;&lt;FONT face=Georgia size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Georgia size=3&gt;In the actual algorithm we multiply the smoothed value by 2 in order to decrease the effect of velocity.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Georgia size=3&gt;And last, the waves lose energy as they travel:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 6pt 0in"&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9" face="Courier New" size=3&gt;Buffer2[x,y] = Buffer2[x,y] * damping&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;o:p&gt;&lt;FONT face=Georgia size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;H2 style="MARGIN: 10pt 0in 0pt"&gt;&lt;FONT face="Trebuchet MS" color=#4f81bd size=4&gt;Rendering the Water&lt;/FONT&gt;&lt;/H2&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Georgia size=3&gt;The render buffer contains heights of the water in each pixel. We’ll render it using shading and refraction. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Georgia size=3&gt;The &lt;B style="mso-bidi-font-weight: normal"&gt;shading&lt;/B&gt; variable below determines the direction and intensity of the light. For example, if you set shading = xoffset, you’ll get light straight from the left. I decided to set the light at the bottom-right part of the screen.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=CodeCxSpFirst style="MARGIN: 6pt 0in 0pt"&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9" face="Courier New" size=3&gt;For every non-edge pixel in the buffer&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Xoffset = buffer[x-1, y] – buffer[x+1, y]&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Yoffset = buffer[x, y-1] – buffer[x, y+1]&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9" face="Courier New" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&lt;FONT size=3&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; mso-no-proof: yes; mso-bidi-language: AR-SA"&gt;shading = (xoffset - yoffset) / 2&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;&lt;o:p&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9" face="Courier New" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9" face="Courier New" size=3&gt;// note: x+xoffset and y+yoffset do not wrap around the texture&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9" face="Courier New" size=3&gt;t = texture[x+Xoffset, y+Yoffset] &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;&lt;o:p&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9" face="Courier New" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9" face="Courier New" size=3&gt;resultColor = t + Shading&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9" face="Courier New" size=3&gt;// make sure the color is within limits&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9" face="Courier New" size=3&gt;resultColor = SaturateTo255Max(resultColor) &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;&lt;o:p&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9" face="Courier New" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9" face="Courier New" size=3&gt;plot pixel at (x,y) with color resultColor&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=CodeCxSpLast style="MARGIN: 0in 0in 6pt"&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9" face="Courier New" size=3&gt;End loop&lt;/FONT&gt;&lt;/P&gt;
&lt;H2 style="MARGIN: 10pt 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Trebuchet MS" color=#4f81bd size=4&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/H2&gt;
&lt;H2 style="MARGIN: 10pt 0in 0pt"&gt;&lt;FONT face="Trebuchet MS" color=#4f81bd size=4&gt;Creating Drops/Splashes&lt;/FONT&gt;&lt;/H2&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Georgia size=3&gt;I made a simple function to create a circular splash, although you can create different splashes to simulate dropping irregular shapes into the water or other motion effects (e.g. star, line or use the letters of your name).&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Georgia size=3&gt;The function creates a splash given its radius at location (cx, cy). The splash begins below water level and rises above at the end.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=CodeCxSpFirst style="MARGIN: 6pt 0in 0pt"&gt;&lt;SPAN style="mso-no-proof: yes; mso-bidi-language: AR-SA"&gt;&lt;FONT size=3&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9"&gt;&lt;FONT face="Courier New"&gt;Splash(cx, cy, radius):&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="COLOR: blue; mso-no-proof: yes; mso-bidi-language: AR-SA"&gt;for&lt;/SPAN&gt;&lt;SPAN style="mso-no-proof: yes; mso-bidi-language: AR-SA"&gt; each y from (cy - radius) to (cy + radius)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-no-proof: yes; mso-bidi-language: AR-SA"&gt;&lt;FONT size=3&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;for&lt;/SPAN&gt; each x from (cx - radius) to (cx + radius)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-no-proof: yes; mso-bidi-language: AR-SA"&gt;&lt;FONT size=3&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;dist = distance from point (x,y) to (cx, cy)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-no-proof: yes; mso-bidi-language: AR-SA"&gt;&lt;FONT size=3&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (dist &amp;lt; radius) &lt;SPAN style="COLOR: green"&gt;// if within splash circle&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-no-proof: yes; mso-bidi-language: AR-SA"&gt;&lt;FONT size=3&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;buffer1[x, y] = 255 - (512 * 1 - dist / radius)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-no-proof: yes; mso-bidi-language: AR-SA"&gt;&lt;FONT size=3&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;end &lt;SPAN style="COLOR: blue"&gt;if&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeCxSpMiddle style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-no-proof: yes; mso-bidi-language: AR-SA"&gt;&lt;FONT size=3&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;end loop&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeCxSpLast style="MARGIN: 0in 0in 6pt"&gt;&lt;SPAN style="mso-no-proof: yes; mso-bidi-language: AR-SA"&gt;&lt;FONT size=3&gt;&lt;FONT style="BACKGROUND-COLOR: #d9d9d9"&gt;&lt;FONT face="Courier New"&gt;end loop&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;o:p&gt;&lt;FONT face=Georgia size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;H2 style="MARGIN: 10pt 0in 0pt"&gt;&lt;FONT face="Trebuchet MS" color=#4f81bd size=4&gt;The Silverlight Side&lt;/FONT&gt;&lt;/H2&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Georgia size=3&gt;The rendering loop is called every 60ms and does this:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Bullets style="MARGIN: 0in 0in auto 27pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; mso-fareast-font-family: Arial; mso-bidi-font-size: 11.0pt"&gt;&lt;SPAN style="mso-list: Ignore"&gt;1.&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3&gt;Add a random splash (rain drop) on the image&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Bullets style="MARGIN: 0in 0in auto 27pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; mso-fareast-font-family: Arial; mso-bidi-font-size: 11.0pt"&gt;&lt;SPAN style="mso-list: Ignore"&gt;2.&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3&gt;Calculate the next frame to render&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Bullets style="MARGIN: 0in 0in auto 27pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; mso-fareast-font-family: Arial; mso-bidi-font-size: 11.0pt"&gt;&lt;SPAN style="mso-list: Ignore"&gt;3.&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3&gt;Display the next frame&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Georgia size=3&gt;There are 3 components used to render each frame:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT size=3&gt;&lt;FONT face=Georgia&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;Renderer&lt;/B&gt; has the “raw” buffers of integers containing wave height for each pixel in the frame. On each frame the renderer mixes its raw buffer with the background image (decoded using &lt;B style="mso-bidi-font-weight: normal"&gt;FluxJpeg.Core.Image&lt;/B&gt; component) and outputs each it to a dynamic image generation surface (&lt;B style="mso-bidi-font-weight: normal"&gt;EditableImage&lt;/B&gt;).&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;H2 style="MARGIN: 10pt 0in 0pt"&gt;&lt;FONT face="Trebuchet MS" color=#4f81bd size=4&gt;Links&lt;/FONT&gt;&lt;/H2&gt;
&lt;P class=MsoNoSpacing style="MARGIN: 0in 0in 0pt"&gt;&lt;A href="http://freespace.virgin.net/hugo.elias/graphics/x_water.htm"&gt;&lt;FONT face=Georgia size=3&gt;Original 2D water algorithm (Hugo Elias)&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Georgia size=3&gt;This is the algorithm used as a base for the sample.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNoSpacing style="MARGIN: 0in 0in 0pt"&gt;&lt;A href="http://blogs.msdn.com/jstegman/archive/2008/04/21/dynamic-image-generation-in-silverlight.aspx"&gt;&lt;FONT face=Georgia size=3&gt;Dynamic image generation (Joe Stegman)&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P class=MsoNoSpacing style="MARGIN: 0in 0in 0pt"&gt;&lt;A href="http://blogs.msdn.com/nikola/archive/2008/07/02/optimizing-joe-stegman-s-dynamic-image-generation-in-silverlight-twice-the-speed.aspx"&gt;&lt;FONT face=Georgia size=3&gt;Optimized dynamic image generation based on Joe's (Nokola)&lt;/FONT&gt;&lt;/A&gt;&lt;FONT size=3&gt;&lt;FONT face=Georgia&gt; &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Georgia size=3&gt;I’m using optimized version of Joe’s algorithm to render the effect on screen.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNoSpacing style="MARGIN: 0in 0in 0pt"&gt;&lt;A href="http://fluxcapacity.net/open-source/"&gt;&lt;FONT face=Georgia size=3&gt;Silverlight JPEG encoder/decoder in C# - FJCore on fluxcapacity.net&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Georgia size=3&gt; &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Georgia size=3&gt;The binary is used to decode the JPEG image in Silverlight.&lt;/FONT&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;FONT face=Georgia size=3&gt;&lt;FONT face="Trebuchet MS" color=#4f81bd size=4&gt;&lt;FONT face=Arial color=#1f497d size=3&gt;&lt;FONT face=Georgia color=#000000&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8690195" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/nikola/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/nikola/archive/tags/Sample/default.aspx">Sample</category><category domain="http://blogs.msdn.com/nikola/archive/tags/Source+Code/default.aspx">Source Code</category><category domain="http://blogs.msdn.com/nikola/archive/tags/Water+Ripples/default.aspx">Water Ripples</category><category domain="http://blogs.msdn.com/nikola/archive/tags/Rain+Drops/default.aspx">Rain Drops</category></item></channel></rss>