|
Masalani yechishning algoritmi va dasturi
|
bet | 18/22 | Sana | 11.09.2024 | Hajmi | 46,67 Kb. | | #270884 |
Bog'liq Multimedia3.2 Masalani yechishning algoritmi va dasturi:
Windows form ilovasini yaratish.
Aylana obyektini yaratish va uni ekranda chizish.
Vaqt funksiyasi yordamida aylananing koordinatalarini o‘zgartirish.
Harakatni amalga oshiruvchi animatsiyani yaratish.
Dastur kodi (C#):
csharp
Копировать код
using System;
using System.Drawing;
using System.Windows.Forms;
public class AnimationForm : Form
{
private Timer timer;
private int xPos = 0;
private int yPos = 100;
private int xSpeed = 5;
public AnimationForm()
{
this.Width = 600;
this.Height = 400;
timer = new Timer();
timer.Interval = 50; // 50ms, animatsiya tezligi
timer.Tick += new EventHandler(UpdateAnimation);
timer.Start();
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
g.Clear(Color.White);
g.FillEllipse(Brushes.Blue, xPos, yPos, 50, 50); // Aylana chizish
}
private void UpdateAnimation(object sender, EventArgs e)
{
xPos += xSpeed;
if (xPos > this.Width || xPos < 0) // Aylana chetlarga yetganda yo‘nalishni o‘zgartirish
{
xSpeed = -xSpeed;
}
Invalidate(); // Ekranni qayta chizish
}
[STAThread]
public static void Main()
{
Application.Run(new AnimationForm());
}
}
Dastur kodining tahlili:
Bu dastur Windows form ilovasi sifatida aylananing ekranda harakatlanishini amalga oshiradi. Timer sinfi yordamida har 50 ms da aylana yangi koordinataga siljiydi va ekranda qayta chiziladi. Dastur ishlayotganda aylana ekranning chegarasiga yetganda harakat yo‘nalishini o‘zgartiradi.
4. Talabalar uchun mavzuga oid metodik ko‘rsatma:
Grafika va animatsiya yaratishda Windows muhiti va GDI+ kutubxonalaridan qanday foydalanishni o‘rganish kerak.
Timer obyektidan foydalanib animatsiya yaratishning texnikalari tushuntiriladi.
Harakat algoritmlari va obyektlar koordinatalarini boshqarish bilan bog‘liq amaliy tajribalarni qo‘llash kerak.
|
| |