, Visual C#

       


30.1. .

// :

float x = 0;

float y0 = 49;

float y1 = 0;

float k = 10;

float b = -5;

// dx ::

private const float dx = 2;

// y=f(x):

private float f()

{

// NextDouble

// double, x:

Random myRandom = new Random();

x = Convert.ToSingle(myRandom.NextDouble());

// y=f(x):

y1 = y0 + k * x + b;

// y=f(x):

if (y1 > 98.9) y1 = 98.9f;

if (y1 < 0.999) y1 = 0.999f;

return y1;

}

30.2. Form1_Load.

private void Form1_Load(object sender, EventArgs e)

{

// myGraphics,

// PictureBox1 :

Bitmap myBitmap = new Bitmap(pictureBox1.Width,

pictureBox1.Height);

Graphics myGraphics = Graphics.FromImage(myBitmap);

myGraphics.ScaleTransform(1, -100.0f /

pictureBox1.Height);

myGraphics.TranslateTransform(0, -100);

// :

Pen myPen = new Pen(Color.Blue, 1);

int i;

for (i = 10; i <= 100; i+=10)

myGraphics.DrawLine(myPen,

0, i, pictureBox1.Width, i);

//

// PictureBox1:

pictureBox1.Image = myBitmap;

// , myGraphics:

myGraphics.Dispose();

}

Timer ( ). Form1.cs , .

30.3. Timer1_Tick.

private void timer1_Tick(object sender, EventArgs e)


{
// :
Bitmap myBitmap = new Bitmap(pictureBox1.Width,
pictureBox1.Height);
Graphics g = Graphics.FromImage(myBitmap);
g.DrawImage(pictureBox1.Image, -dx, 0);
// :
g.ScaleTransform(1, -100.0F / pictureBox1.Height);
g.TranslateTransform(0, -100);
Pen myPen = new Pen(Color.Blue, 1);
int i;
for (i = 10; i <= 100; i+=10)
g.DrawLine(myPen, pictureBox1.Width - dx, i,
pictureBox1.Width, i);
//
// f():
y1 = f();
// :
Pen myPen2 = new Pen(Color.Black, 1);
g.DrawLine(myPen2,
pictureBox1.Width - 1 - dx, y0,
pictureBox1.Width - 1, y1);
y0 = y1;
//
// PictureBox1:
pictureBox1.Image = myBitmap;
}









Forekc.ru
, , , , , , , , , ,