Amaliy mashg’ulot. Windows form application da animatsiya yaratish. Buning uchun formaga pictureBox, button va timer uskunalarini qo’yamiz. Formaning ko’rinishi quyidagicha: Dastur kodi quyidagilardan iborat



Download 96,17 Kb.
Sana21.04.2022
Hajmi96,17 Kb.
#569490
Bog'liq
animatsiya yaratish


Amaliy mashg’ulot. Windows form application da animatsiya yaratish. Buning uchun formaga pictureBox, button va timer uskunalarini qo’yamiz.

Formaning ko’rinishi quyidagicha:



Dastur kodi quyidagilardan iborat:

using System;


using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication36


{
public partial class Form1 : Form
{
Graphics chizish; //biz obyekt chizadigan grafika ni e'lon qilamiz
Pen qalam; //biz konturni chizishimiz uchun qalam obyektini e'lon qilamiz
SolidBrush fon; //fonni va chizilgan figuraning ichki tomonlari mos ravishda
SolidBrush soha; // to'ldirish uchun obyekt e'lon qilamiz
int rad; // chizilgan doiralar radiusini saqlash uchun o'zgaruvchi
Random rand;
public Form1()
{
InitializeComponent();
}
void DoiraChizish(int x, int y)
{
int xc, yc;
xc = x - rad;
yc = y - rad;
chizish.FillEllipse(soha, xc, yc, rad, rad);
chizish.DrawEllipse(qalam, xc, yc, rad, rad);

}


private void button1_Click(object sender, EventArgs e)
{
chizish = pictureBox1.CreateGraphics();
fon = new SolidBrush(Color.Aqua);
rad = 40;
chizish.FillRectangle(fon, 0, 0, pictureBox1.Width, pictureBox1.Height); // chizilgan maydonimizni
int x, y;
rand = new Random();
for (int i = 0; i < 15; i++)
{
Color rang = Color.FromArgb(rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255));
soha = new SolidBrush(rang);
qalam = new Pen(Color.FromArgb(rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255)), 2);
x = rand.Next(pictureBox1.Width);
y = rand.Next(pictureBox1.Height);
DoiraChizish(x, y);
}

timer1.Enabled = true; //endi, taymerimizni yoqaylik,


// ya'ni endi Tick hodisasi sodir bo'ladi va On_Tick funksiyasi uni boshqaradi (sukut bo'yicha)
}

private void timer1_Tick(object sender, EventArgs e)


{
//avval chizilgan maydonni fon rangi bilan tozalaymiz
chizish.FillRectangle(fon, 0, 0, pictureBox1.Width, pictureBox1.Height);
// keyin yana tasodifiy doiralar markazlarining koordinatalarini tanlaymiz
// va biz tasvirlab bergan funksiya yordamida ularni chizamiz
int x, y;
for (int i = 0; i < 15; i++)
{
Color rang = Color.FromArgb(rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255));
soha = new SolidBrush(rang);
x = rand.Next(pictureBox1.Width);
y = rand.Next(pictureBox1.Height);
DoiraChizish(x, y);
}
}
}
}
Dastur natijasi:


Joriy nazorat3

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication45


{
public partial class Form1 : Form
{
Graphics chizish;
Pen qalam;
SolidBrush fon;
SolidBrush soha;
Random rand;
int rad,x,y;
bool kattaKichik = true;
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)


{

}
void DoiraChizish(int x, int y, int rad)


{
int xc, yc;
xc = x - rad / 2;
yc = y - rad / 2;
chizish.FillEllipse(soha, xc, yc, rad, rad);
chizish.DrawEllipse(qalam, xc, yc, rad, rad);
}
private void button1_Click(object sender, EventArgs e)
{
chizish = pictureBox1.CreateGraphics();
fon = new SolidBrush(Color.Aqua);

chizish.FillRectangle(fon, 0, 0, pictureBox1.Width, pictureBox1.Height);


int x, y;

rand = new Random();


Color rang = Color.FromArgb(rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255));


soha = new SolidBrush(rang);


qalam = new Pen(Color.FromArgb(rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255)), 2);

x = pictureBox1.Width / 2;


y = pictureBox1.Height / 2;

rad = pictureBox1.Height;


DoiraChizish(x, y, rad);


timer1.Enabled = true;


}


private void timer1_Tick(object sender, EventArgs e)
{
chizish.FillRectangle(fon, 0, 0, pictureBox1.Width, pictureBox1.Height);

Color rang = Color.FromArgb(rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255));


soha = new SolidBrush(rang);

DoiraChizish(x, y, rad);


rand = new Random();

if (kattaKichik)


{
rad -= 30;
if (rad <= 0)
{
kattaKichik = false;
x = rand.Next(0, pictureBox1.Width);
y = rand.Next(0, pictureBox1.Height);
}
}

else
{


rad += 30;
if (rad >= pictureBox1.Height)
{
kattaKichik = true;
x = rand.Next(0, pictureBox1.Width);
y = rand.Next(0, pictureBox1.Height);
}
}

timer1.Enabled = true;


}
}
}

Download 96,17 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish