All pastes #995670 Raw Edit

Etwas

public text v1 · immutable
#995670 ·published 2008-04-24 11:52 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;
  Graphics g, bitmap_g;
  Bitmap bitmap;
  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 )
  { g = e.Graphics;
    if ( bitmap != null ) bitmap.Dispose();
    bitmap = new Bitmap( ClientRectangle.Width, ClientRectangle.Height );
    if ( bitmap_g != null ) bitmap_g.Dispose();
    bitmap_g = Graphics.FromImage( bitmap );
    if (anzahl==0){
        initBoden();
        zeichneBoden(bitmap_g);
        anzahl++;
        Invalidate();
    } else {
        for(int i = 0; i<2000; i++) {
            System.Threading.Thread.Sleep( 24 );
            moveArray();
            bitmap_g.FillRectangle( SystemBrushes.Control, 0, 0, ClientRectangle.Width, ClientRectangle.Height );
            //g.Clear(Color.White);
            zeichneBoden(bitmap_g);
            g.DrawImage(bitmap, 0, 0 );
            anzahl++;
        }
    }
  }
}