# Can someone explain this Pulsate code to me

// Pulsate the size of the selected menu entry.
double time = gametime.TotalGameTime.TotalSeconds;
float pulsate = (float)Math.Sin(time * 6) + 1;
scale = new Scale(1 + pulsate * 0.05f,1 + pulsate * 0.05f);


I grabbed it from the XNA GameState sample and just curious.

Looks like it's using a sine wave to change the scale of an object. Sine ranges from -1 to +1, so adding one to the pulsate variable puts the range at 0 to 2. Then adding 1 to (pulstae * 0.05f) Puts the range at 1 to 1.10.
• @Setheron: No, sin(t)'s period is 2PI seconds, so sin(6*t) gives you a pulse every 2PI/6 seconds, which is slightly less often than once a second. – Eric Apr 27 '12 at 17:20