circle (50, 50, 35); {radusi 35 bo’lgan aylana chizish}
floodfill (50, 50, 4); {aylana ichiga rang bilan to’ldirish, bo’yaladigan chegara rangi rangli qalam bilan bir xil bo’lishi kerak}
Takrorlash chun materiallar:
RANGLAR PALITRASI:
256·256·256 = 16 777 216
Amaliy vazifalar:
1.Uy rasmini chizish dasturini tuzing.
2. Mashina chizish dasturini tuzing.
3. Geometrik figuralarni rasmini chizish dasturini tuzing.
4. Ixtiyoriy rasmni chizish dasturini tuzing.
Amaliy ish uchun topshiriqlar:
Quyidagi dasturni kiriting va rasmni hosil qiling:
Tabiat quynidagi uyni va u yerda turgan darahtni chizish dasturi.
#include
#include
#include
class Fon
{
public:
Fon();
};
Fon::Fon()
{
setfillstyle(6,GREEN);
bar(0,0,getmaxx(),getmaxy());
setfillstyle(1,1);
bar(0,0,getmaxx(),150);
setfillstyle(1,14);
fillellipse(600,50,50,50);
setfillstyle(1,1);
fillellipse(500,390,200,50);
};
class Tree
{
int x,y;
public:
Tree(int X,int Y) {x=X;y=Y;}
void ShowTree();
};
/*Uy sinfini qo’shamiz*/
class Dom
{
int x,y; //Uyni chizishni boshlang’ich koordinatalari
public:
Dom(int X,int Y) {x=X;y=Y;} //Конструктор класса принимает параметры
void ShowHome(); //Chizuvchi Uy klassi metodi
};
void Tree::ShowTree()
{
y=y+getmaxy();
//Рисую ствол и ветви
moveto(x,y-150); lineto(x,y-300);
moveto(x,y-(150+75)); lineto(x+70,y-(150+75)-70);
moveto(x+20,y-(150+75)-20); lineto(x+70,y-(150+75)-20);
moveto(x+40,y-(150+75)-40); lineto(x+45,y-(150+75)-70);
moveto(x,y-(150+75)-40); lineto(x+20,y-(150+75)-65);
moveto(x,y-(150+75)-10); lineto(x-30,y-(150+75)-20);
moveto(x,y-(150+75)-30); lineto(x-25,y-(150+75)-40);
//Рисую листву
setfillstyle(1,GREEN);
fillellipse(x,y-300,5,5);
fillellipse(x+20,y-290,7,7);
fillellipse(x+45,y-300,3,7);
fillellipse(x+75,y-300,10,10);
fillellipse(x+20,y-255,5,10);
fillellipse(x+70,y-247,10,10);
fillellipse(x-30,y-247,10,10);
fillellipse(x-30,y-267,7,7);
fillellipse(x-15,y-270,5,9);
}
/*Uyni chizish metodi klassdan tashqarida berilgan */
void Dom::ShowHome()
{
setfillstyle(3,3); //Rang berish stilini o’rnatish
bar3d(x-150,y,x-50,y-120,2,1); //Uy fasadini chizamiz
//Треугольная часть крыши
int poly[8]; //3 вершины*2 = 6. Tugatish nuqtasi kerak 6+2 =8
poly[0]=x-155; poly[1]=y-120; //A(x,y)
poly[2]=x-100; poly[3]=y-200; //B(x,y)
poly[4]=x-45; poly[5]=y-120; //C(x,y)
poly[6]=poly[0];poly[7]=poly[1]; //Konturni tugatish
setfillstyle(5,1); //Rang berishni o’rnatish
fillpoly(3,poly); //Ichi quyilgan uchburchakni chizamiz
//Tomning parallelogram qismi
/*Parallelogramm uchun nuqtalarni qidirish
outtextxy(x-45,y-120,"A");
outtextxy(x+100,y-120,"B");
outtextxy(x-100,y-200,"C");
outtextxy(x+100-45,y-200,"D"); */
int poly1[10]; // parallelogrammning 4ta nuqtasi*2=8 + biriktirish nuqtasi =8+2=10
poly1[0]=x-45; poly1[1]=y-120; //A
poly1[2]=x+100; poly1[3]=y-120; //B
poly1[4]=x+100-45; poly1[5]=y-200; //D
poly1[6]=x-100; poly1[7]=y-200; //C
poly1[8]=poly1[0]; poly1[9]=poly1[1]; //Konturni biriktirish
setfillstyle(2,1);//УстанRang stilini o’rnatishовка стиля заливки
fillpoly(4,poly1); //Ichi bo’yalgan to’rtburchakni chizish
/*Uyning yon devori*/
/*Поиск точек
outtextxy(x-45,y,"A");
outtextxy(x+100,y,"B");
outtextxy(x+100,y-120,"C");
outtextxy(x-45,y-120,"D"); */
setfillstyle(10,2); //Rang stilini o’rnatish
bar3d(x-45,y,x+100,y-120,1,1); //Ichi bo’yalgan to’rtburchak
//Qidirish va oynalarni chizish
/*outtextxy(x-30,y-50,"A");
outtextxy(x-30,y-80,"B");
outtextxy(x,y-80,"C"); */
setfillstyle(1,7); //Rang stilini o’rnatish
bar3d(x-30,y-50,x,y-80,1,1); //Birinchi oynani chizish
/*outtextxy(x+15,y-50,"A");
outtextxy(x+45,y-80,"B");*/
bar3d(x+15,y-50,x+45,y-80,1,1); //Ikkinchi oynani chizish
/*outtextxy(x+60,y-50,"A");
outtextxy(x+90,y-80,"B"); */
setfillstyle(5,YELLOW); //Rang quyush stilini o’rnatish
bar3d(x+60,y-50,x+90,y-80,1,1); //Uchinchi oynani chizish
/*Koordinatalarni qidirish va eshiklarni chizish
outtextxy(x-70,y,"A");
outtextxy(x-100,y-70,"B");*/
setfillstyle(2,6); //Rang berish stilini o’rnatish
bar3d(x-70,y,x-100,y-70,1,1); //Eshikni chizish
}
int main()
{
int gm,gd=DETECT;
initgraph(&gd,&gm,"");
Fon Fon1; //KOnstruktor yordamida fonni chizish
Tree Derevo1(50,50); // Daraht tipli ob’ektni chizish
Derevo1.ShowTree(); //Darahtni chizish
Dom Dom1(400,300); //Uy tipli ob’ektni yaratish
Dom1.ShowHome(); //Uyni chizish
cin.get();
closegraph();
return 0;
}
|