![]() |
TX Library Help – Version: 00173a, Revision: 174
|
00001 //{=========================================================================== 00011 // $Copyright: (C) Ded (Ilya Dedinsky, http://txlib.ru) <mail@txlib.ru> $ 00012 //}=========================================================================== 00013 00014 #include <conio.h> 00015 #include "TXLib.h" 00016 00017 //---------------------------------------------------------------------------- 00018 00019 void JumpMan (int x, int y, int sizeX, int sizeY, double jump, 00020 COLORREF color, COLORREF bkColor, int jumps, int delay); 00021 00022 void MoveMan (int fromX, int fromY, int toX, int toY, 00023 int sizeX, int sizeY, COLORREF color, COLORREF bkColor, 00024 int time, int steps); 00025 00026 void DrawMan (int x, int y, int sizeX, int sizeY, COLORREF color, 00027 double hand = 0, double legs = 0, double head = 0, double twist = 0); 00028 00029 void AppearEarth (int x, int y, int sizeX, int sizeY, COLORREF from, COLORREF to, 00030 int time, int steps); 00031 00032 void DrawEarth (int x, int y, int sizeX, int sizeY, COLORREF color); 00033 00034 void AppearText (int x, int y, const char* text, COLORREF from, COLORREF to, 00035 int time, int steps); 00036 00037 void DrawHello (int x, int y, const char* text, int size, COLORREF color); 00038 00039 void UnwindFlag (int x, int y, int fromSizeX, int toSizeX, int sizeY, 00040 COLORREF color, COLORREF bkColor, int time, int steps); 00041 00042 void DrawFlag (int x, int y, int sizeX, int sizeY, COLORREF color, COLORREF bkColor); 00043 00044 void DrawFrame (int sizeX, int sizeY, int size, COLORREF color); 00045 00046 //---------------------------------------------------------------------------- 00047 00048 int main() 00049 { 00050 txCreateWindow (800, 600); 00051 txTextCursor (false); 00052 00053 DrawFrame (800, 600, 10, TX_WHITE); 00054 00055 txSelectFont ("Times New Roman", 60); 00056 txSetTextAlign (TA_CENTER); 00057 00058 AppearText (400, 480, "Hello, world!", TX_BLACK, TX_LIGHTGREEN, 5000, 100); 00059 AppearEarth (400, 300, 400, 300, TX_BLACK, TX_LIGHTCYAN, 5000, 100); 00060 00061 MoveMan (20, 150, 385, 150, 20, 40, TX_YELLOW, TX_BLACK, 3000, 100); 00062 JumpMan (385, 150, 20, 40, 0.25, TX_YELLOW, TX_BLACK, 10, 100); 00063 UnwindFlag (400, 150, 0, 40, 60, TX_YELLOW, TX_BLACK, 500, 100); 00064 00065 return 0; 00066 } 00067 00068 //---------------------------------------------------------------------------- 00069 00070 void JumpMan (int x, int y, int sizeX, int sizeY, double jump, 00071 COLORREF color, COLORREF bkColor, int jumps, int delay) 00072 { 00073 DrawMan (x, y, sizeX, sizeY, TX_BLACK, 0, 0, 0, 0); 00074 00075 txBegin(); 00076 00077 int i = 0; 00078 while (i < jumps) 00079 { 00080 DrawMan (x, y - (int)(i%2 * jump*10), sizeX, sizeY, color, 00081 (i%2-0.5) * jump/3, 0, (i%2-0.5) * -jump/3, 0); 00082 00083 txSleep (delay); 00084 00085 DrawMan (x, y - (int)(i%2 * jump*10), sizeX, sizeY, bkColor, 00086 (i%2-0.5) * jump/3, 0, (i%2-0.5) * -jump/3, 0); 00087 i++; 00088 } 00089 00090 DrawMan (x, y - (int)(jumps%2 * jump*10), sizeX, sizeY, color, 00091 (jumps%2-0.5) * jump/3, 0, (jumps%2-0.5) * -jump/3, 0); 00092 00093 txEnd(); 00094 } 00095 00096 //---------------------------------------------------------------------------- 00097 00098 void MoveMan (int fromX, int fromY, int toX, int toY, 00099 int sizeX, int sizeY, COLORREF color, COLORREF bkColor, 00100 int time, int steps) 00101 { 00102 txBegin(); 00103 00104 int i = 0; 00105 while (i <= steps) 00106 { 00107 int x = fromX + (toX - fromX) * i/steps, 00108 y = fromY + (toY - fromY) * i/steps; 00109 00110 DrawMan (x, y - i%6, sizeX, sizeY, color, i%3*0.02, i%3*-0.1, i%3*0.1, 0); 00111 00112 txSleep (time / steps); 00113 00114 DrawMan (x, y - i%6, sizeX, sizeY, bkColor, i%3*0.02, i%3*-0.1, i%3*0.1, 0); 00115 i++; 00116 } 00117 00118 DrawMan (toX, toY, sizeX, sizeY, color, 0, 0, 0); 00119 00120 txEnd(); 00121 } 00122 00123 //---------------------------------------------------------------------------- 00124 00125 void UnwindFlag (int x, int y, int fromSizeX, int toSizeX, int sizeY, 00126 COLORREF color, COLORREF bkColor, int time, int steps) 00127 { 00128 txBegin(); 00129 00130 int i = 0; 00131 while (i <= steps) 00132 { 00133 int sizeX = fromSizeX + (toSizeX - fromSizeX) * i/steps; 00134 00135 DrawFlag (x, y, sizeX, sizeY, color, bkColor); 00136 00137 txSleep (time / steps); 00138 00139 DrawFlag (x, y, sizeX, sizeY, bkColor, bkColor); 00140 i++; 00141 } 00142 00143 DrawFlag (x, y, toSizeX, sizeY, color, bkColor); 00144 00145 txEnd(); 00146 } 00147 00148 //---------------------------------------------------------------------------- 00149 00150 void DrawMan (int x, int y, int sizeX, int sizeY, COLORREF color, 00151 double hand, double legs, double head, double twist) 00152 { 00153 txSetColor (color); 00154 txSetFillColor (color); 00155 00156 txLine (x + twist*sizeX, y - 0.35*sizeY, x, y - 0.7*sizeY); 00157 00158 txLine (x + twist*sizeX, y - 0.35*sizeY, x - (0.5 + legs) * sizeX, y); 00159 txLine (x + twist*sizeX, y - 0.35*sizeY, x + (0.5 + legs) * sizeX, y); 00160 00161 txLine (x, y - 0.65*sizeY, x - sizeX/2, y - 0.4*sizeY); 00162 txLine (x, y - 0.65*sizeY, x + sizeX/1.2, y - (0.7 + hand) * sizeY); 00163 00164 txCircle (x, y - sizeY + (0.3 + head) * sizeX, 0.3*sizeX); 00165 } 00166 00167 //---------------------------------------------------------------------------- 00168 00169 void DrawEarth (int x, int y, int sizeX, int sizeY, COLORREF color) 00170 { 00171 txSetColor (color); 00172 00173 int r = sizeX/2; 00174 while (r >= 0) 00175 { 00176 txEllipse (x-r, y-sizeY/2, x+r, y+sizeY/2); 00177 r -= sizeX/9; 00178 } 00179 00180 r = sizeY/2; 00181 while (r >= 0) 00182 { 00183 txEllipse (x-sizeX/2, y-r, x+sizeX/2, y+r); 00184 r -= sizeY/6; 00185 } 00186 00187 txLine (x - sizeX/2, y, x + sizeX/2, y); 00188 } 00189 00190 //---------------------------------------------------------------------------- 00191 00192 void AppearEarth (int x, int y, int sizeX, int sizeY, COLORREF from, COLORREF to, 00193 int time, int steps) 00194 { 00195 int r0 = txExtractColor (from, TX_RED), r1 = txExtractColor (to, TX_RED), 00196 g0 = txExtractColor (from, TX_GREEN), g1 = txExtractColor (to, TX_GREEN), 00197 b0 = txExtractColor (from, TX_BLUE), b1 = txExtractColor (to, TX_BLUE); 00198 00199 int i = 0; 00200 while (i <= steps) 00201 { 00202 int r = r0 + (r1 - r0) * i/steps, 00203 g = g0 + (g1 - g0) * i/steps, 00204 b = b0 + (b1 - b0) * i/steps; 00205 00206 DrawEarth (x, y, sizeX, sizeY, RGB (r, g, b)); 00207 00208 Sleep (time / steps); 00209 i++; 00210 } 00211 } 00212 00213 //---------------------------------------------------------------------------- 00214 00215 void AppearText (int x, int y, const char* text, COLORREF from, COLORREF to, 00216 int time, int steps) 00217 { 00218 int r0 = txExtractColor (from, TX_RED), r1 = txExtractColor (to, TX_RED), 00219 g0 = txExtractColor (from, TX_GREEN), g1 = txExtractColor (to, TX_GREEN), 00220 b0 = txExtractColor (from, TX_BLUE), b1 = txExtractColor (to, TX_BLUE); 00221 00222 for (int i = 0; i <= steps; i++) 00223 { 00224 int r = r0 + (r1 - r0) * i/steps, 00225 g = g0 + (g1 - g0) * i/steps, 00226 b = b0 + (b1 - b0) * i/steps; 00227 00228 txSetColor (RGB (r, g, b)); 00229 txTextOut (x, y, text); 00230 00231 Sleep (time / steps); 00232 } 00233 } 00234 00235 //---------------------------------------------------------------------------- 00236 00237 void DrawFlag (int x, int y, int sizeX, int sizeY, COLORREF color, COLORREF bkColor) 00238 { 00239 txSetColor (color); 00240 txSetFillColor (bkColor); 00241 00242 txLine (x, y, x, y - sizeY); 00243 txRectangle (x, y - sizeY/2, x + sizeX, y - sizeY); 00244 00245 txSelectFont ("Times New Roman", sizeX/2 + 1); 00246 txTextOut (x + sizeX/2, y - sizeY*7/8, "C++"); 00247 } 00248 00249 //---------------------------------------------------------------------------- 00250 00251 void DrawHello (int x, int y, const char* text, int size, COLORREF color) 00252 { 00253 txSetColor (color); 00254 00255 txSelectFont ("Times New Roman", size); 00256 txSetTextAlign (TA_CENTER); 00257 00258 txTextOut (x, y, text); 00259 } 00260 00261 //---------------------------------------------------------------------------- 00262 00263 void DrawFrame (int sizeX, int sizeY, int size, COLORREF color) 00264 { 00265 txSetColor (color); 00266 txSetFillColor (TX_TRANSPARENT); 00267 00268 txRectangle (size, size, sizeX-size, sizeY-size); 00269 } 00270 00271 00272 00273