title: Plasma effect in WinForms, how to create continous loop
body: <p>I'm trying to create some simple graphics (&quot;plasma&quot; effect) with C# and Winforms.
  I have two classes in my code, (main)Form1 and Plasmadraw.</p>
  <p>In Plasmadraw I have following setup:</p>
  <pre><code>class Plasmadraw
  {
  
      int y;
      int x;
      double i;
     
      double pii = 3.1415;
  
      public void Draw(Graphics gfx, int addition)
      {
  
          
          for (int i = 0; i &lt; 23040; i++)
          {
  
             
              x = x + 10;
  
              if (x == 1920)
              {
                  x = 0;
                  y = y + 10;
              }
  
              if (y == 1200)
              {
                  y = 0;
              }
  
              double v = Math.Sin((x * 0.5) + i * 0.001 * addition);
              double c = v * pii;
              double d = c + (2 * pii / 3);
              double f = c + (6 * pii / 3);
              double r = 255 * Math.Abs(Math.Sin(c));
              double g = 255 * Math.Abs(Math.Sin(d));
              double b = 255 * Math.Abs(Math.Sin(f));
  
              int r1 = (int)r;
              int g1 = (int)g;
              int b1 = (int)b;
  
              Color e = Color.FromArgb(r1, g1, b1);
  
              SolidBrush brush = new SolidBrush(e);
              Rectangle rect = new Rectangle(x, y, 10, 10);
              gfx.FillRectangle(brush, rect);
  
          }
          
  
      }
  }
  </code></pre>
  <p>and then in Form1 I have Paint event:</p>
  <pre><code> private void Form1_Paint(object sender, PaintEventArgs e)
   {
       Plasmadraw plasmaeffect = new Plasmadraw();
  
       for (int a = 0; a &lt; 30; a++)
       {
            
           plasmaeffect.Draw(e.Graphics, a);
  
           Invalidate();
       }
  </code></pre>
  <p>Is this somehow completely wrong way to build the logic ? I've managed to create some graphics effects (moving sprites etc.) by creating a list and then running through the list with Foreach in Paint event (&amp; Invalidate()). However, I'd like to learn some new way to do things, rather than copying the old way.</p>