All pastes #995606 Raw Edit

Unbenannt

public text v1 · immutable
#995606 ·published 2008-04-24 10:03 UTC
rendered paste body
using System;
using System.Drawing;
using System.Windows.Forms;

public class Form1 : Form
{ [STAThread] static void Main() { Application.Run( new Form1() ); }
  Font arial18 = new Font( "Arial", 18 );
  Brush whitebrush = SystemBrushes.Window;
  Pen   blackpen   = new Pen( Color.Black, 2 );
  Point[] boden = new Point[70];
  Random rand = new Random();
  int anzahl = 0;
  Boolean hoch = true;
  public Form1()
  { BackColor  = Color.White;
    Text       = "intro1";
    SetStyle( ControlStyles.ResizeRedraw, true );
    StartPosition = FormStartPosition.Manual;
    Top    =  50;
    Left   =  50;
    Width  = 350;
    Height = 232;
  }

  void initBoden()
  {
  boden[0].Y = 200;
  boden[0].X = 0;
  for (int i=1;i<70;i++)
    { boden[i].X = i*5;
      naechsterPunkt(i);
  }
 }

  void naechsterPunkt(int index) {
    if (boden[index-1].Y==200) { 
        boden[index].Y = 195;
        hoch = true; }
      else { 
         if (boden[index-1].Y==150) {
            boden[index].Y = 155;
            hoch = false; 
         } else {
            int r;
            r = rand.Next(100);
            if (r>90) hoch = !hoch;
            if (hoch) boden[index].Y = boden[index-1].Y-5; else boden[index].Y = boden[index-1].Y+5;      
         }
      }
   }

  void zeichneBoden(Graphics g) {
    for (int i = 1;i<boden.Length;i++) {
            g.DrawLine( blackpen, boden[i-1].X, boden[i-1].Y, boden[i].X, boden[i].Y );        
        }
  }

  void moveArray() {
    for (int i=1;i<boden.Length;i++) {
        boden[i-1].Y=boden[i].Y;
        naechsterPunkt(boden.Length-1);
    }
  }
  
  protected override void OnPaint( PaintEventArgs e )
  { Graphics g = e.Graphics;
    if (anzahl==0){
        initBoden();
        zeichneBoden(g);
        anzahl++;
        Invalidate();
    } else {
        for(int i = 0; i<70; i++) {
            System.Threading.Thread.Sleep( 10 );
            moveArray();
            g.Clear(Color.White);
            zeichneBoden(g);
            anzahl++;
        }
    }
  }
}