Muhammad al-Xorazmiy nomidagi Toshkent Axborot Texnologiyalari Universiteti talabasi Qodirov Sanjarning Kompyuter Grafikasi fanidan tayyorlagan 3-amaliy ishi
Mavzu: Ixtiyoriy mеvali daraxt + bog‘ rasmini bеzе egri chizig‘idan foydalanib chizing va soxani bo‘yash algoritmlaridan foydalanib rasmni bo‘yang.
1-Bo’lib dasturimizga kerakli bo’ldan kodlarni yozib olamiz:
#include
#include
#include
#include
float t;
int i,s;
void floodfill(int x,int y,char BorderColor,char NewColor)
{
if(getpixel(x,y)!=BorderColor)
{
if(getpixel(x,y)!=NewColor)
{
putpixel(x,y,NewColor);
floodfill(x-1,y,BorderColor,NewColor);
floodfill(x+1,y,BorderColor,NewColor);
floodfill(x,y-1,BorderColor,NewColor);
floodfill(x,y+1,BorderColor,NewColor);
}}}
int beze(int x1,int y1,int x2, int y2,int x3,int y3,int x4,int y4,float &X,float &Y)
{
for(i=0;i<1000;i++)
{
//delay(0);
t=i/1000.;
X=pow((1-t),3)*x1+3*t*(1-t)*(1-t)*x2+3*t*t*(1-t)*x3+t*t*t*x4;
Y=pow((1-t),3)*y1+3*t*(1-t)*(1-t)*y2+3*t*t*(1-t)*y3+t*t*t*y4;
putpixel(X,Y,s);
}}
int main()
{
initwindow (1000,800);
setbkcolor(WHITE);
cleardevice();
float X,Y;
s=0;
Bog’imiz kodlarini kiritamiz:
//1-Daraxt bargi
beze(70,0,50,25,50,40,55,75,X,Y);
beze(55,75,36,86,30,109,40,124,X,Y);
beze(40,124,34,140,37,156,48,164,X,Y);
beze(48,164,50,191,55,199,66,204,X,Y);
beze(66,204,63,220,67,229,72,232,X,Y);
beze(72,232,71,258,80,266,88,267,X,Y);
beze(88,267,86,295,98,304,113,297,X,Y);
beze(113,297,119,321,130,325,140,321,X,Y);
beze(140,321,148,351,161,355,175,351,X,Y);
beze(175,351,184,365,196,367,206,359,X,Y);
beze(206,359,220,385,234,385,250,370,X,Y);
beze(250,370,264,402,276,401,286,376,X,Y);
beze(286,376,300,383,310,390,316,383,X,Y);
beze(316,383,330,390,339,385,343,372,X,Y);
beze(343,372,359,379,370,372,377,350,X,Y);
beze(377,350,403,347,412,332,413,315,X,Y);
beze(413,315,434,316,441,305,441,289,X,Y);
beze(441,289,457,285,459,278,457,267,X,Y);
beze(457,267,466,260,469,252,468,241,X,Y);
beze(468,241,479,229,480,219,480,208,X,Y);
beze(480,208,489,190,490,173,482,158,X,Y);
beze(482,158,485,140,484,126,482,116,X,Y);
beze(482,116,492,95,492,80,488,66,X,Y);
beze(488,66,492,45,487,29,479,17,X,Y);
beze(479,17,483,11,487,5,488,0,X,Y);
1-rasm. 1-Daraxtimiz barg qismi.
Endilikda bu daraxtimizni tana qismini kodini kiritamiz:
//1-Daraxt tanasi
beze(247,375,245,377,244,379,241,378,X,Y);
beze(241,378,247,430,255,469,277,519,X,Y);
beze(247,375,257,435,266,461,279,490,X,Y);
beze(278,390,282,503,278,547,244,675,X,Y);
beze(244,675,242,679,246,683,259,682,X,Y);
beze(259,682,265,680,278,677,291,676,X,Y);
beze(291,676,308,649,322,636,339,628,X,Y);
beze(339,628,355,631,370,654,375,685,X,Y);
beze(375,685,369,692,364,697,350,706,X,Y);
beze(350,706,309,706,290,697,291,676,X,Y);
beze(339,628,337,516,331,447,324,386,X,Y);
2-rasm.1-Daraxtimiz tana qismi natijasi.
2-Daraxtimizni chizish.
//2-Daraxt bargi
beze(470,240,480,243,488,242,497,237,X,Y);
beze(497,237,503,261,511,263,518,259,X,Y);
beze(518,259,527,269,535,265,540,255,X,Y);
beze(540,255,564,260,574,251,582,231,X,Y);
beze(582,231,606,233,616,225,623,214,X,Y);
beze(623,214,642,211,648,200,648,182,X,Y);
beze(648,182,664,171,669,162,670,146,X,Y);
beze(670,146,697,118,698,85,693,60,X,Y);
beze(693,60,698,27,697,11,690,0,X,Y);
3-rasm. 2-daraxtimiz barg qismi chizilgandagi holat.
Shu daraxtnin tana qismi kodi:
//2-Daraxt tanasi
beze(468,241,471,267,474,282,482,301,X,Y);
beze(468,241,471,242,473,242,475,242,X,Y);
beze(475,242,478,256,481,267,487,278,X,Y);
beze(493,239,474,354,469,394,455,505,X,Y);
beze(455,505,477,516,503,516,519,507,X,Y);
beze(525,263,518,353,519,443,519,507,X,Y);
beze(520,311,554,285,575,258,589,231,X,Y);
beze(470,240,480,243,488,242,497,237,X,Y);
beze(592,232,576,271,559,297,521,331,X,Y);
4-rasm. 2-daraxt tanasi chizilgandagi holat.
2-Daraxt yonidagi kustlar kodi:
//2-Daraxt tagidagi kust
beze(469,396,461,394,455,396,447,405,X,Y);
beze(447,405,437,389,428,388,419,399,X,Y);
beze(419,399,414,396,408,403,410,420,X,Y);
beze(410,420,400,421,394,435,401,450,X,Y);
beze(401,450,384,452,379,480,402,492,X,Y);
beze(402,492,405,507,416,510,430,500,X,Y);
beze(430,500,441,505,449,504,455,500,X,Y);
beze(519,416,539,423,542,434,538,454,X,Y);
beze(538,454,547,456,551,466,547,472,X,Y);
beze(547,472,554,481,549,497,536,498,X,Y);
beze(536,498,532,501,526,504,518,504,X,Y);
5-rasm. Kustlarning ko’rinishi.
3-Daraxt barg qismini kodini kiritishni boshlayman:
//3-Daraxt bargi
beze(999,53,984,53,971,59,961,69,X,Y);
beze(961,69,947,71,938,82,933,97,X,Y);
beze(933,97,906,91,888,101,867,140,X,Y);
beze(867,140,848,135,824,153,816,196,X,Y);
beze(816,196,806,195,796,216,805,257,X,Y);
beze(805,257,785,279,783,316,794,345,X,Y);
beze(794,345,772,362,774,406,801,436,X,Y);
beze(801,436,808,456,824,468,841,468,X,Y);
beze(841,468,866,493,878,494,891,480,X,Y);
beze(891,480,899,490,909,488,919,481,X,Y);
beze(919,481,942,499,958,495,967,480,X,Y);
beze(967,480,982,492,992,493,999,490,X,Y);
6-rasm. 3-Daraxt barg qismi ko’rinishi.
Endilikda shu daraxtga tana qismini kirataman:
//3-Daraxt tanasi
beze(909,485,928,608,930,644,924,714,X,Y);
beze(956,490,963,517,953,517,978,487,X,Y);
beze(989,490,970,551,970,551,979,598,X,Y);
beze(979,598,989,635,990,686,988,760,X,Y);
7-rasm. 3-Daraxtning tana qismi.
Quyosh kodlari:
//Quyosh
beze(802,48,765,55,770,106,805,103,X,Y);
beze(802,48,836,54,836,98,805,103,X,Y);
//Ko'zi
beze(785,65,787,60,790,60,792,65,X,Y);
beze(810,65,815,60,815,60,815,65,X,Y);
//Labi
beze(784,84,791,98,808,100,816,86,X,Y);
//Quyosh Nurlari
beze(754,41,778,37,778,37,785,8,X,Y);
beze(785,8,805,30,805,30,823,14,X,Y);
beze(823,14,831,49,831,49,849,48,X,Y);
beze(849,48,839,82,839,82,851,118,X,Y);
beze(851,118,826,114,826,114,815,144,X,Y);
beze(815,144,794,126,794,126,770,136,X,Y);
beze(770,136,772,103,772,103,753,92,X,Y);
beze(753,92,768,67,768,67,754,41,X,Y);
8-rasm. Quyosh chizmasini aylana qismi,ko’zi ,lablari va nurlarining umumiy ko’rinishi.
Past qismdagi kustlarning koordinatalarini kiritaman:
//Pastdagi chap kust
beze(0,574,16,561,29,561,47,580,X,Y);
beze(47,580,72,550,95,550,119,598,X,Y);
beze(119,598,131,589,141,595,148,609,X,Y);
beze(148,609,170,592,201,615,200,642,X,Y);
beze(200,642,229,647,240,672,233,698,X,Y);
beze(233,698,258,718,261,752,249,775,X,Y);
beze(249,775,255,784,259,793,261,800,X,Y);
9-rasm. Chap tomon past qismdagi kust ning ko’rinishi.
Endi shunday kustdan o’ng tarafga ham koordinatalar kiritaman.
//Pasdagi o'ng kust
beze(999,751,990,759,984,766,979,776,X,Y);
beze(979,776,972,763,962,757,954,759,X,Y);
beze(954,759,942,723,925,709,907,713,X,Y);
beze(907,713,894,678,871,667,848,682,X,Y);
beze(848,682,830,652,808,654,793,692,X,Y);
beze(793,692,781,677,767,678,754,695,X,Y);
beze(754,695,734,711,724,729,718,753,X,Y);
beze(718,753,698,764,688,777,679,799,X,Y);
10-rasm. Kustlarning ko’rinishi.
Daraxt chetlaridan o’tgan chiziq, ya’ni yerning va uni pastki qismida joylashgan toshchalarning koordinatalari.
//Yer
beze(0,492,98,455,180,425,245,403,X,Y);
beze(252,401,255,399,257,399,272,393,X,Y);
beze(369,364,411,354,434,348,476,339,X,Y);
beze(523,329,636,313,694,310,788,312,X,Y);
//Pastdagi toshchalar
beze(390,741,412,720,443,723,459,740,X,Y);
beze(459,740,458,757,451,767,425,766,X,Y);
beze(425,766,410,765,396,758,393,755,X,Y);
beze(390,741,392,746,393,750,393,755,X,Y);
beze(390,741,379,729,370,727,347,745,X,Y);
beze(347,745,343,756,348,766,371,768,X,Y);
beze(371,768,382,765,390,759,393,755,X,Y);
11-rasm. Yer va undagi toshchalar.
Pastda joylashgan toshchalarning o’tiga va tepa qismdagi bulutga berilgan koordinatalar:
//Toshchalarning o'ti
beze(357,736,355,724,353,716,349,709,X,Y);
beze(349,709,359,715,363,720,369,733,X,Y);
beze(369,733,367,709,366,697,366,693,X,Y);
beze(366,693,372,703,377,715,383,735,X,Y);
beze(382,727,412,680,412,680,408,730,X,Y);
//Bulut
beze(881,116,855,105,852,77,868,63,X,Y);
beze(868,63,869,52,874,48,882,47,X,Y);
beze(882,47,895,29,908,27,920,34,X,Y);
beze(920,34,949,17,976,24,993,54,X,Y);
12-rasm.Toshchalarning o’ti va bulut ko’rinishi.
Endi daraxtlarim yonida paydo bo’ladigan panjaralarning koordinatalari:
//Reshotka
beze(1,432,3,430,5,429,10,428,X,Y);
beze(10,428,9,422,8,418,8,413,X,Y);
beze(8,413,13,399,13,399,21,408,X,Y);
beze(21,408,22,414,23,419,24,426,X,Y);
beze(24,426,33,423,38,421,48,418,X,Y);
beze(48,418,47,413,47,411,46,408,X,Y);
beze(46,408,48,403,49,399,50,395,X,Y);
beze(50,395,53,398,56,400,59,403,X,Y);
beze(59,403,60,407,60,411,61,417,X,Y);
beze(61,417,71,414,78,411,91,406,X,Y);
beze(91,406,90,401,89,397,89,394,X,Y);
beze(89,394,90,390,92,385,94,379,X,Y);
beze(94,379,97,383,100,386,102,391,X,Y);
beze(102,391,103,395,104,401,105,407,X,Y);
beze(105,407,112,404,120,401,129,397,X,Y);
beze(129,397,129,394,128,391,128,387,X,Y);
beze(128,387,129,384,130,380,131,375,X,Y);
beze(131,375,134,378,137,380,141,383,X,Y);
beze(141,383,141,386,141,390,142,396,X,Y);
beze(142,396,151,392,159,389,172,384,X,Y);
beze(172,384,171,379,171,376,170,371,X,Y);
beze(170,371,172,367,173,363,175,357,X,Y);
beze(175,357,178,360,180,362,183,366,X,Y);
beze(183,366,184,370,185,376,185,381,X,Y);
beze(185,381,192,379,200,376,216,372,X,Y);
beze(1,440,3,439,6,437,11,435,X,Y);
beze(11,435,12,441,14,448,15,455,X,Y);
beze(15,455,9,457,4,460,1,462,X,Y);
beze(1,469,5,467,9,465,16,462,X,Y);
beze(16,462,18,468,19,475,20,486,X,Y);
beze(32,481,31,473,30,467,29,460,X,Y);
beze(29,460,36,458,43,456,54,453,X,Y);
beze(54,453,56,458,56,463,57,471,X,Y);
beze(26,435,26,440,27,445,28,453,X,Y);
beze(28,453,35,451,43,449,54,447,X,Y);
beze(26,435,32,432,38,430,49,425,X,Y);
beze(49,425,51,433,52,438,54,447,X,Y);
beze(63,426,72,422,80,419,92,414,X,Y);
beze(92,414,93,421,94,425,96,433,X,Y);
beze(96,433,86,438,77,442,67,447,X,Y);
beze(67,447,65,440,64,434,63,426,X,Y);
beze(68,466,68,462,68,458,67,455,X,Y);
beze(67,455,75,451,84,446,97,439,X,Y);
beze(97,439,98,444,99,448,100,454,X,Y);
beze(111,450,111,447,110,443,110,439,X,Y);
beze(110,439,118,437,126,434,136,431,X,Y);
beze(136,431,137,434,137,436,138,440,X,Y);
beze(109,432,107,426,107,421,106,415,X,Y);
beze(106,415,114,412,122,408,131,405,X,Y);
beze(131,405,132,411,133,417,135,425,X,Y);
beze(135,425,126,428,117,430,109,432,X,Y);
beze(149,436,149,433,169,421,179,416,X,Y);
beze(179,416,179,418,180,421,180,424,X,Y);
beze(148,426,147,419,146,412,144,405,X,Y);
beze(144,405,153,401,162,397,173,392,X,Y);
beze(173,392,175,399,176,404,177,410,X,Y);
beze(177,410,166,416,158,420,148,425,X,Y);
beze(192,420,192,418,191,416,191,414,X,Y);
beze(191,414,199,411,209,407,217,404,X,Y);
beze(217,404,218,407,218,408,219,411,X,Y);
beze(190,407,189,400,188,396,187,391,X,Y);
beze(187,391,194,387,201,384,212,379,X,Y);
beze(212,379,213,384,214,390,216,398,X,Y);
beze(216,398,207,401,198,404,190,406,X,Y);
beze(190,406,189,401,188,396,187,391,X,Y);
beze(227,380,227,391,228,394,228,398,X,Y);
beze(228,398,235,394,246,388,240,384,X,Y);
beze(230,407,233,403,237,401,244,398,X,Y);
beze(800,261,787,261,780,260,772,260,X,Y);
beze(772,260,772,254,772,250,772,245,X,Y);
beze(772,245,770,240,767,236,765,232,X,Y);
beze(765,232,763,236,761,239,758,244,X,Y);
beze(758,244,758,249,758,254,758,262,X,Y);
beze(758,262,750,262,741,262,733,261,X,Y);
beze(733,261,733,257,733,255,733,251,X,Y);
beze(733,251,732,248,730,244,728,239,X,Y);
beze(728,239,725,243,723,246,720,250,X,Y);
beze(720,250,720,254,720,258,720,265,X,Y);
beze(720,265,708,265,700,264,689,263,X,Y);
beze(689,263,689,259,689,255,689,250,X,Y);
beze(689,250,687,246,685,243,682,238,X,Y);
beze(682,238,681,242,679,245,676,249,X,Y);
beze(676,249,676,255,676,261,676,268,X,Y);
beze(676,268,667,268,660,268,651,267,X,Y);
beze(651,267,651,263,651,261,651,257,X,Y);
beze(651,257,649,253,647,250,645,246,X,Y);
beze(645,246,643,248,641,251,638,254,X,Y);
beze(638,254,638,258,638,262,637,315,X,Y);
beze(795,269,783,269,778,269,771,268,X,Y);
beze(771,268,771,274,771,280,771,287,X,Y);
beze(771,287,773,288,777,288,789,289,X,Y);
beze(770,311,770,306,770,301,770,295,X,Y);
beze(770,295,774,296,777,296,788,297,X,Y);
beze(733,269,741,270,747,270,757,271,X,Y);
beze(757,271,758,277,758,283,758,289,X,Y);
beze(758,289,748,290,741,291,733,291,X,Y);
beze(733,291,733,284,733,277,733,269,X,Y);
beze(731,310,731,306,731,303,731,298,X,Y);
beze(731,298,739,298,749,298,758,298,X,Y);
beze(758,298,758,302,758,306,758,311,X,Y);
beze(689,271,699,272,710,273,720,275,X,Y);
beze(720,275,720,282,720,288,720,296,X,Y);
beze(720,296,708,294,698,293,689,291,X,Y);
beze(689,291,689,284,689,279,689,271,X,Y);
beze(688,312,688,305,688,302,688,298,X,Y);
beze(688,300,699,300,708,302,720,304,X,Y);
beze(720,304,720,306,720,309,720,312,X,Y);
beze(648,314,648,309,648,305,648,302,X,Y);
beze(648,302,656,302,665,302,676,302,X,Y);
beze(676,302,676,306,676,308,676,312,X,Y);
beze(649,295,649,288,650,281,650,274,X,Y);
beze(650,274,658,275,668,277,676,278,X,Y);
beze(676,278,676,284,676,290,676,295,X,Y);
beze(676,295,668,295,659,295,649,295,X,Y);
beze(799,260,799,260,796,270,796,270,X,Y);
beze(788,288,788,288,788,297,785,297,X,Y);
13-rasm. Panjaralarning ko’rinishi.
1-Daraxtdagi olmchalarning koordinatalari:
//Olmachalar
beze(195,23,190,19,183,20,177,26,X,Y);
beze(177,26,175,43,180,60,189,62,X,Y);
beze(189,62,191,60,195,61,198,64,X,Y);
beze(198,64,205,65,214,56,216,33,X,Y);
beze(216,33,214,26,206,22,195,23,X,Y);
beze(199,10,196,18,196,24,196,31,X,Y);
beze(282,82,274,81,266,90,267,111,X,Y);
beze(267,111,275,122,282,121,286,118,X,Y);
beze(286,118,287,116,290,118,295,118,X,Y);
beze(295,118,303,111,306,97,298,80,X,Y);
beze(298,80,293,78,288,80,282,82,X,Y);
beze(282,69,282,75,282,83,285,88,X,Y);
14-rasm. Olmachalarning ko’rinishi.
Endi shu chizmalarimizga rang kiritaman va yakuniy natijani ko’ramiz:
//Osmonni bo'yash
floodfill(60,350,s,LIGHTCYAN);
floodfill(255,395,s,LIGHTCYAN);
floodfill(420,330,s,LIGHTCYAN);
floodfill(482,252,s,LIGHTCYAN);
floodfill(540,277,s,LIGHTCYAN);
s=LIGHTCYAN;
beze(732,1,732,1,682,238,682,238,X,Y);
floodfill(589,269,BLACK,LIGHTCYAN);
floodfill(859,14,BLACK,LIGHTCYAN);
floodfill(6,450,BLACK,LIGHTCYAN);
floodfill(7,475,BLACK,LIGHTCYAN);
floodfill(40,440,BLACK,LIGHTCYAN);
floodfill(44,464,BLACK,LIGHTCYAN);
floodfill(79,429,BLACK,LIGHTCYAN);
floodfill(85,455,BLACK,LIGHTCYAN);
floodfill(120,420,BLACK,LIGHTCYAN);
floodfill(123,441,BLACK,LIGHTCYAN);
floodfill(161,410,BLACK,LIGHTCYAN);
floodfill(171,424,BLACK,LIGHTCYAN);
floodfill(202,393,BLACK,LIGHTCYAN);
floodfill(205,413,BLACK,LIGHTCYAN);
floodfill(233,390,BLACK,LIGHTCYAN);
floodfill(238,403,BLACK,LIGHTCYAN);
floodfill(666,285,BLACK,LIGHTCYAN);
floodfill(660,306,BLACK,LIGHTCYAN);
floodfill(705,285,BLACK,LIGHTCYAN);
floodfill(700,305,BLACK,LIGHTCYAN);
floodfill(744,280,BLACK,LIGHTCYAN);
floodfill(744,304,BLACK,LIGHTCYAN);
floodfill(777,277,BLACK,LIGHTCYAN);
floodfill(775,305,BLACK,LIGHTCYAN);
//Quyosh
floodfill(805,50,BLACK,YELLOW);
floodfill(790,30,BLACK,BROWN);
//Bulut
floodfill(917,67,BLACK,WHITE);
//1-Daraxt
s=GREEN;
beze(34,141,34,141,485,141,485,141,X,Y);
beze(63,221,63,221,481,221,481,221,X,Y);
floodfill(140,30,BLACK,GREEN);
floodfill(60,171,BLACK,GREEN);
floodfill(272,323,BLACK,GREEN);
//Tanasi
floodfill(265,480,BLACK,BROWN);
floodfill(305,485,BLACK,BROWN);
//2-Daraxt
floodfill(566,144,BLACK,GREEN);
//Tanasi
floodfill(477,275,BLACK,BROWN);
floodfill(495,370,BLACK,BROWN);
floodfill(535,310,BLACK,BROWN);
//3-Draxt
s=GREEN;
beze(786,293,782,293,999,293,999,293,X,Y);
floodfill(850,180,BLACK,GREEN);
floodfill(865,469,BLACK,GREEN);
//Tanasi
floodfill(955,670,BLACK,BROWN);
//Yer
s=LIGHTGREEN;
beze(624,314,624,314,625,799,625,799,X,Y);
beze(412,354,335,491,435,654,494,799,X,Y);
beze(636,799,667,681,706,632,792,450,X,Y);
floodfill(225,580,BLACK,LIGHTGREEN);
floodfill(496,594,BLACK,LIGHTGREEN);
floodfill(820,555,BLACK,LIGHTGREEN);
floodfill(270,440,BLACK,LIGHTGREEN);
floodfill(997,712,BLACK,LIGHTGREEN);
floodfill(965,500,BLACK,LIGHTGREEN);
//Kust
floodfill(433,444,BLACK,GREEN);
floodfill(535,465,BLACK,GREEN);
floodfill(80,707,BLACK,GREEN);
floodfill(840,750,BLACK,GREEN);
//Reshotka
floodfill(17,430,BLACK,YELLOW);
floodfill(685,255,BLACK,YELLOW);
//Olmachalar
floodfill(195,45,BLACK,RED);
floodfill(280,100,BLACK,RED);
//Toshchalar
floodfill(336,666,BLACK,LIGHTGRAY);
floodfill(363,744,BLACK,LIGHTGRAY);
floodfill(425,744,BLACK,LIGHTGRAY);
floodfill(360,724,BLACK,GREEN);
floodfill(374,721,BLACK,GREEN);
floodfill(386,725,BLACK,GREEN);
getch();
closegraph();
return 0;
}
15-rasm.Chizmaning yakuniy ko’rinishi.
|