Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Методпособие ДРП - версия 6

.pdf
Скачиваний:
3
Добавлен:
02.06.2015
Размер:
2.33 Mб
Скачать

e.Graphics.DrawLine(pen, t, calc(t, less), t + 1, calc(t + 1, less));

}

}

private void timer_Tick(object sender, EventArgs e)

{

float prev_x = x, prev_y = y;

if (x + 10 < ClientSize.Width) x += 5;

counter += 1f;

y = calc(x, counter);

if (x == prev_x || 40 - counter == 0) timer.Stop();

Refresh();

}

private void btnStart_Click(object sender, EventArgs e)

{

x = 0; y = 0; counter = 0; timer.Start();

}

}

Листинг 3.5 - Программные коды файла FormBall.cs

public partial class FormBall : Form

{

public FormBall()

{

InitializeComponent();

}

int x, y, yMax, yStep, counter;

private void FormBall_Shown(object sender, EventArgs e)

{

btnStart_Click(sender, e);

}

private void timer_Tick(object sender, EventArgs e)

{

if (x + 10 < ClientSize.Width) x += 5;

if (counter == 4)

{

yMax -= yStep; y = yMax; counter = 0;

}

else

{

if (counter == 2) y = 0;

else

y = yMax / 2;

}

counter++;

if (yMax == 0) timer.Stop();

Refresh();

}

private void btnStart_Click(object sender, EventArgs e)

{

counter = 0;

x = 50; y = 0; yMax = 160; yStep = 40; timer.Start();

}

private void FormBall_Paint(object sender, PaintEventArgs e)

{

e.Graphics.TranslateTransform(0, this.Height / 2); e.Graphics.DrawLine(new Pen(Color.Black, 5), 0, 22, this.Width, 22); e.Graphics.FillEllipse(Brushes.Red, x, -y, 20, 20);

}

}

Листинг 3.6 - Программные коды файла FormPlanet.cs

public partial class FormPlanet : Form

{

public FormPlanet()

{

InitializeComponent();

f1 = new Random().Next(15);

f2 = new Random().Next(250);

f3 = new Random().Next(360); step1 = 3;

step2 = 2; step3 = 1; radius1 = 100; radius2 = 150; radius3 = 230;

}

float f1, f2, f3;

float step1, step2, step3; float radius1, radius2, radius3;

float x, y;

private void calc(float f, float radius, out float x, out float y)

{

x = (float)(radius * Math.Cos(f * Math.PI/180));

y = (float)(radius * Math.Sin(f * Math.PI / 180));

}

private void timer_Tick(object sender, EventArgs e)

{

f1 += step1; if (f1 > 360) f1 -= 360;

f2 += step2; if (f2 > 360) f2 -= 360;

f3 += step3; if (f3 > 360) f3 -= 360;

Refresh();

}

private void FormPlanet_Paint(object sender, PaintEventArgs e)

{

e.Graphics.FillEllipse(Brushes.Yellow, ClientSize.Width / 2 - 40, ClientSize.Height / 2 - 40, 80, 80);

calc(f1, radius1, out x, out y);

e.Graphics.FillEllipse(Brushes.Green, ClientSize.Width / 2 - x, ClientSize.Height / 2 -

y, 20, 20);

calc(f2, radius2, out x, out y);

e.Graphics.FillEllipse(Brushes.Red, ClientSize.Width / 2 - x, ClientSize.Height / 2 - y,

25, 25);

calc(f3, radius3, out x, out y);

e.Graphics.FillEllipse(Brushes.Blue, ClientSize.Width / 2 - x, ClientSize.Height / 2 -

y, 35, 35);

}

}

Лабораторная работа №4. Творческая работа

Цель работы: создать приложение с графическим интерфейсом демонстрирующее какой-либо процесс на выбор студента с предварительным согласованием с преподавателем.

План работы: студент должен придумать какой-либо процесс, согласовать его с преподавателем и реализовать в виде анимации.