Ekranda chizmalarni xarakatlantirish

6. Ekranda chizmalarni xarakatlantirish
Ekranda chizmalarni xarakatlantirish uchun kerak buladigan protseduralar:
1.imagesize (x1, y1, x2, y2) – ekranning chap yuqori nuktasi va ung pastki nuktasi koordinatalaridan tugri turtburchakli soxani saklash uchun kerakbuladigan xotiraning ulchami (baytlarda olinadi);
2. getimage (x1, y1, x2, y2, p) – dinamik xotiraning berilganr maydonida to‘g‘ri to‘urtburchakli tasvirini saqlash. Bu erda – tasvirlanadigan joyning adresini saklaydigan uzgaruvchi, ya’ni kursatkich.
3. putimage (x, y, p, m) – ekranning berilgan joyiga tasvirni chikarish; bu yerda x va y – xotiraning p maydonidagi tasvirdan nusxa kuchiriladigan ekranmaydonining chap yukori nuktasi; m – tasvirni ekranga chikarish rejimi. Agar: m = 0 (NormalPut) - tasvirnikuchirish. Bunda eskisi uchib, yangisi paydo buladi (xuddiyuribketayotgandek)
m =1 (XorPut)
m = 2 (Orput) –
m = 3 (AndPut)
Masalan: quyidagi dasturda kvadrat ichidagi bo‘yalgan aylana ekran bo‘ylab xarakatlanadi.
1 # include < graphics.h >
2 # include
3 # include
4 void main ( )
5 { int gd = 0, gm, I, j, s; int *a;
6 initgraph(&gd,&gm,"");
7 setcolor ( 4 );
8 circle ( 30, 30, 20 ); putpixel ( 30, 30, 2);
9 rectangle ( 10, 10, 50, 50);
10 s = imagesize ( 9, 9, 51, 51);
11 *a ==new int; *a = s;
12 getimage (9, 9, 51, 51, a);
13 for ( i = 0; i <=585; i + +)
14 { putimage ( i, 10, a, 0); sound (20); delay (10); nosound ( ); }
15 for ( j = 10; j <= 420; j + +)
16 { putimage(585, j, a, 0 ); sound ( 30 ); delay (10); nosound( );}
17 for (i = 585; i >= 10; i - -)
18 { putimage(i, 420, a, 0); delay ( 10 ); }
19 for (j =420; j >10; j - -)
20 { putimage(10, j, a, 0); delay( 10 ); }
21 delete a;
22 getch(); //closegraph( );
23}
Quyida C++ dasturida Lacetti aftomobilini tuzish programmasi berilgan.
1 #include
2 #include
3 #include
4 using namespace std;
5 int main()
6 {
7 initwindow(754,460);
8 setcolor(WHITE);
9 circle(184, 314, 44); circle(184, 314, 31); circle(184, 314, 7);
10 circle(552, 311, 44); circle(552, 311, 31); circle(552, 311, 7);
11 setfillstyle(1, WHITE);
12 floodfill(170, 314, WHITE); ellipse(231, 247, 0, 360, 7, 3);
13 floodfill(540, 311, WHITE); setfillstyle(1, COLOR(255, 121, 0));
14 floodfill(231, 247, WHITE);
15 line(232, 321, 503, 318);
16 arc(184, 314, -10, 190, 49);
17 arc(552, 311, -10, 190, 49);
18 setcolor(BLACK);
19 circle(184+10, 314+10, 3);
20 circle(184+10, 314-10, 3);
21 circle(184-10, 314+10, 3);
22 circle(184-10, 314-10, 3);
23 circle(552+10, 311+10, 3);
24 circle(552+10, 311-10, 3);
25 circle(552-10, 311+10, 3);
26 circle(552-10, 311-10, 3);
27 setcolor(WHITE);
28 //orqasi
29 ellipse(600, 308, 270, 352, 10, 11);
30 line(609, 308, 664, 302);
31 Line(679, 262, 682, 286);
32 ellipse(664, 286, -90, 0, 18, 16);
33 ellipse(673, 262, 0, 90, 6, 8);
34 ellipse(673, 245, 180, 270, 5, 9);
35 ellipse(654, 245, 0, 90, 14, 42);
36 //fara
37 line(639, 218, 654, 238);
38 ellipse(668, 238, 180, 270, 14, 8);
39 ellipse(644, 218, 90, 180, 5, 16);
40 setfillstyle(1, RED);
41 floodfill(660, 238, WHITE);
42//putpixel(660, 238, GREEN);
43 line(602, 197, 654, 203);
44//putpixel(100, 252, GREEN);
45setfillstyle(1, COLOR(0, 0, 0));
46 floodfill(100, 252, WHITE);
47//setfillstyle(1, COLOR(255, 255, 255));
48//floodfill(10, 10, WHITE);
49//oldi
50 line(86, 314, 134, 320);
51 line(118, 237, 240, 212);
52 line(67, 280, 67, 292);
53 ellipse(86, 292, 180, 270, 19, 22);
54 ellipse(76, 280, 90, 180, 9, 8);
55 ellipse(76, 265, -90, 0, 7, 7);
56 ellipse(118, 265, 90, 180, 35, 28);
57 ellipse(83, 237, -90, 0, 40, 28);
58 //o'rtasi
59 moveto(417, 165);
60 lineto(479, 166);
61 lineto(512, 204);
62 lineto(418, 209);
63 lineto(417, 165);
64 moveto(500, 150);
65 lineto(515, 154);
66 lineto(533, 160);
67 lineto(540, 164);
68 lineto(544, 165);
69 moveto(527, 198);
70 lineto(500, 166);
71 lineto(522, 173);
72 lineto(539, 180);
73 lineto(552, 188);
74 lineto(558, 194);
75 line(536, 202, 552, 202);
76 ellipse(536, 198, 180, 270, 9, 4);
77 ellipse(552, 194, -90, 0, 6, 8);
78 moveto(491, 304);
79 lineto(256, 308);
80 lineto(256, 224);
81 lineto(256, 224);
82 lineto(530, 207);
83 lineto(533, 210);
84 lineto(534, 214);
85 lineto(536, 222);
86 lineto(536, 248);
87 ellipse(536, 304, 90, 180, 45, 56);
88 moveto(267, 219);
89 lineto(292, 202);
90 lineto(339, 177);
91 lineto(372, 168);
92 lineto(400, 165);
93 lineto(389, 210);
94 lineto(267, 219);
95 line(544, 165, 595, 194);
96 ellipse(602, 194, 180, 270, 7, 3);
97 moveto(240, 212);
98 lineto(336, 161);
99 lineto(347, 156);
100 lineto(366, 151);
101 lineto(500, 150);
102 moveto(396, 304);
103 lineto(397, 236);
104 lineto(398, 225);
105 lineto(402, 216);
106 ellipse(366, 233, 0, 360, 10, 4);
107 ellipse(504, 222, 0, 360, 10, 4);
108 getch();
109}
|