• Dastur kodi (C)
  • Dastur kodining tahlili
  • 4. Talabalar uchun mavzuga oid metodik ko‘rsatma
  • Masalani yechishning algoritmi va dasturi




    Download 46,67 Kb.
    bet18/22
    Sana11.09.2024
    Hajmi46,67 Kb.
    #270884
    1   ...   14   15   16   17   18   19   20   21   22
    Bog'liq
    Multimedia

    3.2 Masalani yechishning algoritmi va dasturi:

    1. Windows form ilovasini yaratish.

    2. Aylana obyektini yaratish va uni ekranda chizish.

    3. Vaqt funksiyasi yordamida aylananing koordinatalarini o‘zgartirish.

    4. 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.


    Download 46,67 Kb.
    1   ...   14   15   16   17   18   19   20   21   22




    Download 46,67 Kb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    Masalani yechishning algoritmi va dasturi

    Download 46,67 Kb.