TX Library Help – Version: 00173a, Revision: 174
 ALL  Windows graphics in a sandbox

Movie.cpp

См. документацию.
00001 //{===========================================================================
00011 //          (C) Никита Уваров, 6 класс, 2009
00012 //}===========================================================================
00013 
00014 #include "TXLib.h"
00015 
00016 #if !defined (_TX_VER) || (_TX_VER < 0x172a0000)
00017 #error Must use TXLib.h version >= 1.72 to compile this. -- Ded
00018 #endif
00019 
00020 //============================================================================
00021 
00022 // Utilities
00023 
00024 COLORREF mixColor (COLORREF first, COLORREF second, int percentage);
00025 COLORREF getTransparentColor (COLORREF toSet, COLORREF back, int alpha);
00026 
00027 RECT convert (int cameraX, int cameraY, RECT object);
00028 bool in (RECT in, POINT toCheck);
00029 bool needToDraw (RECT what);
00030 
00031 int centerOutByLeftCorner (const char* toCenter);
00032 
00033 POINT getPoint (int x, int y);
00034 POINT getPointOnEllipse (int x, int y, int w, int h, double angle);
00035 
00036 int sqr (int a);
00037 int getRandom (int min, int max);
00038 int getMainLoopBasedValue (int mainLoop, int from, int to);
00039 
00040 double DELAY = -1;
00041 int    SPEED =  1;
00042 
00043 void doSleep (int time);
00044 
00045 // Loading and deleting
00046 
00047 void doHDCPreparations();
00048 void deleteDCs();
00049 
00050 FILE* sourceFile      = NULL;
00051 HDC*  sourceCodeParts = NULL;
00052 int   partsAmount     = 0;
00053 
00054 void initIO();
00055 HDC  readNextSourceCodePart();
00056 void readCodePro();
00057 void releaseScrollingSource();
00058 
00059 // Trigonometric pack
00060 
00061 int pointOfRest_x = 0, pointOfRest_y = 0;
00062 double sinTable[360] = {0}, cosTable[360] = {0};
00063 
00064 void calculateTables();
00065 
00066 int trigonometricGetNormalAngle (int angle);
00067 int trigonometricGetAngleOfLine (int x, int y, int x2, int y2);
00068 
00069 void trigonometricSetPointOfRest (int x, int y);
00070 void trigonometricMove (int angle, int lenght);
00071 void trigonometricDrawLine (int angle, int lenght);
00072 void trigonometricDrawLineAndReturn (int angle, int lenght);
00073 
00074 // Lightning engine
00075 
00076 struct Lightning;
00077 
00078 void lightningEngineLoop();
00079 void drawElectra (int x, int y, int angle, int nOfSteps, int stepLenght, int randomness, int thickness, COLORREF center, COLORREF border, int chance);
00080 
00081 // Matrix engine & Assembler randomizing system
00082 
00083 const char* oneRegisterCommands[] = { "push", "pop", "not", "inc", "dec" };
00084 const char* twoRegisterCommands[] = { "mov", "add", "sub", "mul", "div", "or", "and", "xor" };
00085 const char* functionNames[]       = { "hello", "f", "label", "forHelp", "Ded", "function", "main" };
00086 const char* registers[]           = { "AX", "BX", "CX", "DX", "SI", "DI" };
00087 
00088 const char* getRandomRegister();
00089 const char* getRandomCommand();
00090 
00091 int*   matrixElementsYPositions = NULL;
00092 char** matrixElementsNames      = NULL;
00093 int    matrixElementsNumber     = 0;
00094 
00095 void matrixFireball (int x, int y, const char* text, int len, int textHeight, COLORREF color);
00096 void matrixEngineInit (int count);
00097 void matrixEngineLoop (int spd, COLORREF col);
00098 void destroyBinaryStairsAndMatrix();
00099 
00100 // Binary stairs
00101 
00102 char** binaryStairsGrounds = NULL;
00103 int    binaryStairsHeight  = 0;
00104 
00105 const char* getStairsGround (int lenght);
00106 void generateBinaryStairs (int difference, int flats);
00107 void drawBinaryStairs (int x, int y, COLORREF color);
00108 
00109 // Graphics
00110 
00111 // Graphic utilities
00112 
00113 void drawGradientLine (int x, int y, int x2, int y2, int thickness, COLORREF border, COLORREF center);
00114 void drawGradientRectangle (int x, int y, int x2, int y2, COLORREF topColor, COLORREF downColor);
00115 void drawGradientCircle (int x, int y, int radius, COLORREF centerColor, COLORREF borderColor);
00116 void drawStripedCircle (int x, int y, int stripeRadius, int numberOfPairs, COLORREF fisrtStripe, COLORREF secondStripe);
00117 void drawPies (int x, int y, int xsize, int ysize, int pieAngle, int angleOffset, COLORREF color, COLORREF special, COLORREF border, int thickness);
00118 
00119 // Graphics
00120 
00121 void drawStickMan (int x, int y, int height, int hairIntensivity, int hairLenght, int walkingPosition,
00122                    int leftBase, int leftSpecial, int rightBase, int rightSpecial, int direction, int walkingAngle,
00123                    COLORREF bodyColor, COLORREF hairColor, COLORREF headColor, COLORREF eyeColor, int rotation, int bodyRot);
00124 
00125 void drawTurtle (int x, int y, int width, int height, COLORREF shellColor, COLORREF stripesColor);
00126 void drawTurtleBody (int x, int y, int width, int height, int walkingPos, COLORREF body, COLORREF border, COLORREF eye, COLORREF eyeBorder, HDC shell);
00127 void prepareTurtleShell (int width, int height, COLORREF baseColor, COLORREF specials, COLORREF border, int thickness);
00128 void drawStyledTurtleShell (int x, int y, int xStart, int yStart, int xFinal, int yFinal, int numberOfPies, int pieRadius, int offsetAngle, COLORREF color, COLORREF special, COLORREF border, int thickness);
00129 
00130 void drawPortalSystem (int x, int y, int radius, int everyRadius, int vertexCount, int bonus, COLORREF color, COLORREF alter, COLORREF back);
00131 void drawPortal (int x, int y, int radius, int each, int bonusRot, COLORREF color, COLORREF alter);
00132 
00133 void drawFlag (int x, int y, int stickHeight, const char* text, COLORREF fill, COLORREF border);
00134 
00135 void drawTree (int x, int y, int trunkWidth, int trunkHeight, int leafRowNumber, int leafsize, COLORREF borderColor, COLORREF fillColor, HDC fruit);
00136 void drawFruitRow (int x, int y, int leafNumber, int leafsize, HDC fruit);
00137 void drawLeafRow (int x, int y, int leafNumber, int leafsize);
00138 void drawLeafPart (int x, int y, int size);
00139 
00140 int rainLoop = 0;
00141 
00142 void drawRain (int columnsSpace, int tearsSpace, int tearsLenght, int animationFrame, int thickness, COLORREF color);
00143 void drawTearsRow (int x, int y, int tearsLenght, int space, int offset);
00144 void drawCloud (int x, int y, int width, int height, int everyAngle, int everyWidth, int everyHeight, COLORREF color);
00145 
00146 void drawBaloon (int x, int y, int radius, int sizeOfStripe, COLORREF centerStripe, COLORREF secondStripe, COLORREF base, COLORREF border);
00147 void drawMountain (int x, int y, int width, int height, int snowHeight, COLORREF ground, COLORREF snow, COLORREF border);
00148 void drawPrintingEffect (int x, int y, const char* whatToPrint, int howMany, COLORREF color);
00149 void printEffect (int x, int y, const char* text, int lenght, int delay);
00150 
00151 // Scenery graphics & animations
00152 
00153 int getTurtleWalkPosition (int rawPosition);
00154 
00155 void drawScene (int cameraX, int cameraY);
00156 
00157 void drawBaloonOnFirstScene (int baloonx, int baloony, int camx, int camy, int baloonsize);
00158 void drawTurtlesOnFirstScene (int x, int y, int slide);
00159 void drawEverythingWeather();
00160 void slideClouds (int space, int y);
00161 
00162 void prepareMountains (COLORREF skyUp, COLORREF skyDown, COLORREF grassUp, COLORREF grassDown);
00163 void walkMountains (POINT* mountains, int elems, int manHeight);
00164 void walkLine (int x, int y, int x2, int y2, int step, int size);
00165 void electraSplash();
00166 
00167 int logoPositionIdentifier = 0;
00168 void drawLogo();
00169 
00170 void drawASMFlag (int x, int y);
00171 
00172 void lastTextEngineLoop (COLORREF color);
00173 void setTextSpeed (int spd);
00174 void selectFont (const char* name, int size, int bold);
00175 
00176 // Scenery
00177 
00178 void fromLogoToCPP();
00179 void fromAssemblerAndUpToTheVeryEnd();
00180 
00181 // Other variables
00182 
00183 HDC sunnyBackground_1 = NULL,
00184     sunnyBackground_2 = NULL,
00185     sunnyBackground_3 = NULL,
00186     mountains_1       = NULL,
00187     mountains_2       = NULL,
00188     mountains_3       = NULL,
00189     trueSunny_up      = NULL;
00190 
00191 HDC orange = NULL,
00192     pear   = NULL,
00193     apple  = NULL;
00194 
00195 HDC shellForLeaderTurtle = NULL,
00196     shellForSecondTurtle = NULL,
00197     shellForKid          = NULL;
00198 
00199 HDC leftCloudlySlide  = NULL,
00200     rightCloudlySlide = NULL;
00201 
00202 int PASCAL_LOGO_WIDTH = 0;
00203 
00204 const COLORREF
00205     SUNNYSKY_UP          = RGB (67 , 101, 255),
00206     SUNNYSKY_DOWN        = RGB (213, 213, 255),
00207     SUN_CENTER           = RGB (255, 255, 142),
00208     SUN_BORDER           = RGB (255, 255, 0  ),
00209     SUNNYGROUND_UP       = RGB (54 , 255, 78 ),
00210     SUNNYGROUND_DOWN     = RGB (91 , 188, 0  ),
00211     GREEN_LIGHT          = RGB (168, 230, 29 ),
00212     GREEN_MEDIUM         = RGB (157, 187, 97 ),
00213     GREEN_DARK           = RGB (37 , 177, 76 ),
00214     LIGHT_ORANGE         = RGB (229, 170, 122),
00215     TRUNK_MINIMUM        = RGB (250, 180, 150),
00216     TRUNK_MAXIMUM        = RGB (255, 255, 255),
00217     NORMAL_BROWN         = RGB (156, 90 , 60 ),
00218     CLEAR_RED            = RGB (255, 0  , 0  );
00219 
00220 HDC scene[9][2] = {{0}};
00221 
00222 int main()
00223     {
00224     const char* title  = "Programmer's Way - Путь Программиста";
00225 
00226     txCreateWindow (800, 600);
00227     SetWindowText (txWindow(), title);
00228     txBegin();
00229 
00230     printf ("\nStarting: %s...\n", title);
00231     Sleep (500);
00232     doSleep (0);
00233 
00234     calculateTables();
00235     doHDCPreparations();
00236 
00237     txSetFillColor (TX_BLACK);
00238     txClear();
00239 
00240     for (int i = 0; i < 50; i++) printf ("\n");
00241     txTextCursor (false);
00242 
00243     fromLogoToCPP();
00244     fromAssemblerAndUpToTheVeryEnd();
00245 
00246     txEnd();
00247     return 0;
00248     }
00249 
00250 void doSleep (int time)
00251     {
00252     if (DELAY < 0)
00253         {
00254         double performance = txQueryPerformance();
00255 
00256         DELAY = performance * 2.5;
00257         SPEED = (int) (10/DELAY + 1.5);
00258         }
00259 
00260     double delay = (GetAsyncKeyState (VK_RIGHT)? 0 : DELAY);
00261 
00262     txSleep (time * delay);
00263 
00264     while (GetAsyncKeyState (VK_DOWN)) txSleep (10);
00265 
00266     if (GetAsyncKeyState (VK_LEFT)) MessageBox (txWindow(), "You need a time machine to do this    ", "Reality", MB_ICONEXCLAMATION);
00267     }
00268 
00269 COLORREF mixColor (COLORREF first, COLORREF second, int percentage)
00270     {
00271     return RGB (txExtractColor (first, TX_RED)   + (txExtractColor (second, TX_RED)   - txExtractColor (first, TX_RED))   / 100 * percentage,
00272                 txExtractColor (first, TX_GREEN) + (txExtractColor (second, TX_GREEN) - txExtractColor (first, TX_GREEN)) / 100 * percentage,
00273                 txExtractColor (first, TX_BLUE)  + (txExtractColor (second, TX_BLUE)  - txExtractColor (first, TX_BLUE))  / 100 * percentage);
00274     }
00275 
00276 int sqr (int a)
00277     {
00278     return a * a;
00279     }
00280 
00281 void drawGradientLine (int x, int y, int x2, int y2, int thickness, COLORREF border, COLORREF center)
00282     {
00283     for (int n = thickness; n > 0; n--)
00284         {
00285         txSetColor (getTransparentColor (border, center, 100 / n), n);
00286         txLine (x, y, x2, y2);
00287         }
00288     }
00289 
00290 void electraSplash()
00291     {
00292     txSetFillColor (TX_BLACK);
00293     txClear();
00294 
00295     drawElectra (0, 0, 126, 50, 20, 45, 5, TX_YELLOW, TX_WHITE, 50);
00296     doSleep (20);
00297     }
00298 
00299 void slideClouds (int space, int y)
00300     {
00301     txTransparentBlt (txDC(), - (space / 2 + 400), y, 800, 600, leftCloudlySlide,  0, 0, TX_BLACK);
00302     txTransparentBlt (txDC(),    space / 2 + 400,  y, 800, 600, rightCloudlySlide, 0, 0, TX_BLACK);
00303     }
00304 
00305 void drawStyledTurtleShell (int x, int y, int xStart, int yStart, int xFinal, int yFinal, int numberOfPies, int pieRadius, int offsetAngle, COLORREF color, COLORREF special, COLORREF border, int thickness)
00306     {
00307     int yChange = (xStart - xFinal) / numberOfPies;
00308     int xChange = (yStart - yFinal) / numberOfPies;
00309 
00310     for (int i = 0; i < numberOfPies; i++)
00311         drawPies (x, y, xStart-xChange*i, yStart-yChange*i, pieRadius, i*offsetAngle, color, special, border, thickness);
00312 
00313     txEllipse (x-xStart/xFinal, y-yStart/yFinal, x+xStart/xFinal, y+yStart/yFinal);
00314     }
00315 
00316 void drawPortalSystem (int x, int y, int radius, int everyRadius, int vertexCount, int bonus, COLORREF color, COLORREF alter, COLORREF back)
00317     {
00318     drawGradientCircle (x, y, radius, color, back);
00319 
00320     int numberSign = 1;
00321     for (int r = radius; r > 0; r -= everyRadius)
00322         {
00323         drawPortal (x, y, r, 360 / vertexCount, numberSign * bonus, color, alter);
00324         numberSign = -numberSign;
00325         }
00326     }
00327 
00328 void drawLogo()
00329     {
00330     logoPositionIdentifier += SPEED;
00331 
00332     int positionBonus = 0;
00333     if      (logoPositionIdentifier > 500) return;
00334     else if (logoPositionIdentifier > 300) positionBonus = 500 - logoPositionIdentifier;
00335     else if (logoPositionIdentifier > 200) positionBonus = 200;
00336     else                                   positionBonus = logoPositionIdentifier;
00337 
00338     positionBonus *= 4;
00339 
00340     txSetColor (TX_BLUE);
00341     txSelectFont ("Comic Sans MS", 80, 25, 1000);
00342     txTextOut (-100 - txGetTextExtentX ("Programmer's Way") + positionBonus, 100, "Programmer's Way");
00343     txTextOut (900 - positionBonus, 200, "Путь Программиста");
00344     }
00345 
00346 struct Lightning
00347     {
00348     int x, y;
00349     int angle;
00350     int state;
00351     COLORREF color;
00352     };
00353 
00354 Lightning lightnings[5] = {{0}};
00355 
00356 void lightningEngineLoop()
00357     {
00358     for (int i = 0; i < 5; i++)
00359         {
00360         if (lightnings[i].state > 0)
00361             {
00362             lightnings[i].state--;
00363             drawElectra (lightnings[i].x, lightnings[i].y, lightnings[i].angle, getRandom (7, 15), getRandom (10, 20), 60, 4, lightnings[i].color, TX_WHITE, 30);
00364             }
00365         else if (getRandom (1, 200) == 1)
00366             {
00367             Lightning random = { getRandom ( 50, 750),
00368                                  getRandom (  0, 150),
00369                                  getRandom (135, 225),
00370                                  getRandom (  2,  10),
00371                                  getRandom (  1,   2) == 1? TX_YELLOW : TX_CYAN };
00372 
00373             lightnings[i] = random;
00374             }
00375         }
00376     }
00377 
00378 int getRandom (int min, int max)
00379     {
00380     return min + rand() % (max - min + 1);
00381     }
00382 
00383 RECT convert (int cameraX, int cameraY, RECT object)
00384     {
00385     RECT result = { object.left   - cameraX,
00386                     object.top    - cameraY,
00387                     object.right  - cameraX,
00388                     object.bottom - cameraY };
00389 
00390     return result;
00391     }
00392 
00393 bool in (RECT in, POINT toCheck)
00394     {
00395     return toCheck.x >= in.left  &&
00396            toCheck.x <= in.right &&
00397            toCheck.y >= in.top   &&
00398            toCheck.y <= in.bottom;
00399     }
00400 
00401 bool needToDraw (RECT what)
00402     {
00403     RECT screen = {0, 0, 800, 600};
00404 
00405     POINT topLeft     = { what.left,  what.top    },
00406           topRight    = { what.right, what.top    },
00407           bottomRight = { what.right, what.bottom },
00408           bottomLeft  = { what.left,  what.bottom };
00409 
00410     return in (screen, topLeft)     |
00411            in (screen, bottomRight) |
00412            in (screen, topRight)    |
00413            in (screen, bottomLeft);
00414     }
00415 
00416 void drawScene (int cameraX, int cameraY)
00417     {
00418     txBitBlt (txDC(),     - (cameraX % 800),     - (cameraY % 600), 800, 600, scene[cameraX / 800]    [cameraY / 600],     0, 0);
00419     txBitBlt (txDC(), 800 - (cameraX % 800),     - (cameraY % 600), 800, 600, scene[cameraX / 800 + 1][cameraY / 600],     0, 0);
00420     txBitBlt (txDC(),     - (cameraX % 800), 600 - (cameraY % 600), 800, 600, scene[cameraX / 800]    [cameraY / 600 + 1], 0, 0);
00421     txBitBlt (txDC(), 800 - (cameraX % 800), 600 - (cameraY % 600), 800, 600, scene[cameraX / 800 + 1][cameraY / 600 + 1], 0, 0);
00422     }
00423 
00424 int getTurtleWalkPosition (int rawPosition)
00425     {
00426     if (rawPosition > 20) return 40 - rawPosition;
00427     else                  return      rawPosition;
00428     }
00429 
00430 void drawFlag (int x, int y, int stickHeight, const char* text, COLORREF fill, COLORREF border)
00431     {
00432     txSelectFont ("Comic Sans MS", 20);
00433 
00434     int width  = txGetTextExtentX (text) + 20,
00435         height = txGetTextExtentY (text) + 10;
00436 
00437     txSetColor (border);
00438     txSetFillColor (fill);
00439     txLine      (x, y, x, y-stickHeight);
00440     txRectangle (      x, y-stickHeight, x+width, y-stickHeight+height);
00441 
00442     txSetColor (TX_YELLOW);
00443     txTextOut (x+10, y-stickHeight+5, text);
00444     }
00445 
00446 void drawBaloonOnFirstScene (int baloonx, int baloony, int camx, int camy, int baloonSize)
00447     {
00448     RECT baloon = { baloonx - baloonSize,
00449                     baloony - baloonSize * 2,
00450                     baloonx + baloonSize,
00451                     baloony + baloonSize * 2 };
00452 
00453     baloon = convert (camx, camy, baloon);
00454 
00455     if (needToDraw (baloon))
00456         {
00457         drawBaloon (baloon.left + (baloon.right-baloon.left)/2,
00458                     baloon.top + (baloon.bottom-baloon.top)/2,
00459                     baloonSize, 20, CLEAR_RED, SUN_BORDER, TX_YELLOW, NORMAL_BROWN);
00460 
00461         txSetColor (TX_GREEN);
00462         txSelectFont ("Comic Sans MS", 60);
00463         txTextOut (baloonx - camx- PASCAL_LOGO_WIDTH / 2, baloony - camy - 25, "Pascal");
00464         }
00465     }
00466 
00467 void drawTurtlesOnFirstScene (int x, int y, int slide)
00468     {
00469     int walkPosition = getTurtleWalkPosition (slide % 40);
00470 
00471     drawTurtleBody (x,       y,      250, 125, walkPosition, TX_GREEN, GREEN_DARK, TX_YELLOW, TX_BROWN, shellForLeaderTurtle);
00472     drawTurtleBody (x - 200, y + 50, 160,  80, walkPosition, TX_GREEN, GREEN_DARK, TX_YELLOW, TX_BROWN, shellForSecondTurtle);
00473     drawTurtleBody (x - 300, y + 90,  80,  40, walkPosition, TX_GREEN, GREEN_DARK, TX_YELLOW, TX_BROWN, shellForKid);
00474 
00475     drawFlag (x + 158, y + 14 + walkPosition / 3, 175, "ЛогоМиры", CLEAR_RED, TX_GREEN);
00476 
00477     drawLogo();
00478     }
00479 
00480 void drawEverythingWeather()
00481     {
00482     drawRain (30, 20, 30, rainLoop % 10 * 5, 1, TX_BLUE);
00483     slideClouds (-167, -72);
00484     lightningEngineLoop();
00485 
00486     rainLoop++;
00487     }
00488 
00489 COLORREF getTransparentColor (COLORREF toSet, COLORREF back, int alpha)
00490     {
00491     // Red-back, green-back, blue-back
00492     int r  = txExtractColor (toSet, TX_RED  ), rb = txExtractColor (back, TX_RED  ),
00493         g  = txExtractColor (toSet, TX_GREEN), gb = txExtractColor (back, TX_GREEN),
00494         b  = txExtractColor (toSet, TX_BLUE ), bb = txExtractColor (back, TX_BLUE );
00495 
00496     return RGB (r + (rb - r) / 100 * alpha,
00497                 g + (gb - g) / 100 * alpha,
00498                 b + (bb - b) / 100 * alpha);
00499     }
00500 
00501 void drawElectra (int x, int y, int angle, int nOfSteps, int stepLenght, int randomness, int thickness, COLORREF center, COLORREF border, int chance)
00502     {
00503     txSetColor (center, thickness);
00504 
00505     int currentX = x,
00506         currentY = y;
00507 
00508     for (int a = 0; a < nOfSteps; a++)
00509         {
00510         int normalAngle = trigonometricGetNormalAngle (getRandom ((angle - randomness) / 5, (angle + randomness) / 5) * 5),
00511             lenght = getRandom (stepLenght * 4/5, stepLenght);
00512 
00513         int nextX = (int) (currentX + sinTable[normalAngle] * lenght),
00514             nextY = (int) (currentY + cosTable[normalAngle] * lenght);
00515 
00516         drawGradientLine (nextX, nextY, currentX, currentY, thickness, border, center);
00517 
00518         currentX = nextX;
00519         currentY = nextY;
00520 
00521         if (getRandom (1,100) < chance)
00522             drawElectra (currentX, currentY, angle + getRandom (0, 180) - 90, nOfSteps / 2, stepLenght / 2, randomness / 2, thickness * 2/3, center, border, chance / 3);
00523         }
00524     }
00525 
00526 void prepareMountains (COLORREF skyUp, COLORREF skyDown, COLORREF grassUp, COLORREF grassDown)
00527     {
00528     txSetFillColor (TX_BLACK);
00529     txClear();
00530 
00531     drawGradientRectangle (0,   0, 800, 200, skyUp,   skyDown);
00532     drawGradientRectangle (0, 200, 800, 600, grassUp, grassDown);
00533 
00534     drawMountain (300, 600, 700, 460, 200, TX_ORANGE, RGB (220,220,255), TX_GRAY);
00535     drawMountain (100, 600, 700, 460, 200, TX_ORANGE, RGB (220,220,255), TX_GRAY);
00536     drawMountain (700, 600, 500, 550, 200, TX_ORANGE, RGB (220,220,255), TX_GRAY);
00537     drawMountain (500, 600, 500, 570, 200, TX_ORANGE, RGB (220,220,255), TX_GRAY);
00538 
00539     txDeleteDC (mountains_1);
00540 
00541     mountains_1 = txCreateCompatibleDC (800, 600);
00542     txBitBlt (mountains_1, 0, 0, 800, 600, txDC(), 0, 0);
00543 
00544     scene[3][1] = mountains_1;
00545     scene[4][1] = mountains_1;
00546     scene[5][1] = mountains_1;
00547     }
00548 
00549 void walkLine (int x, int y, int x2, int y2, int step, int manSize)
00550     {
00551     int lineAngle  = trigonometricGetAngleOfLine (x, y, x2, y2),
00552         lineLenght = (int) (sqrt (1.0*sqr (x2-x) + 1.0*sqr (y2-y))),
00553         stepNumber = lineLenght/step;
00554 
00555     int cameraX, cameraY;
00556     int bodyRotNormal = 90 - (lineAngle > 90 ? 90 : lineAngle);
00557 
00558     for (int stepIndex = 0; stepIndex < stepNumber; stepIndex += SPEED)
00559         {
00560         trigonometricSetPointOfRest (x, y);
00561         trigonometricMove (lineAngle, stepIndex * step);
00562         trigonometricMove (lineAngle - 90, manSize * 7/20);
00563 
00564         cameraX = pointOfRest_x - 400;
00565         cameraY = pointOfRest_y - 300;
00566 
00567         int handsAngle = stepIndex * step % 40;
00568         if (handsAngle > 20) handsAngle = 40 - handsAngle;
00569 
00570         drawScene (cameraX, cameraY);
00571 
00572         drawStickMan (400, 300, manSize, 90, 10, stepIndex * step % 90, 180 - handsAngle, 180 - handsAngle, 180 + handsAngle, 180 + handsAngle, 90, 90, TX_BLACK, NORMAL_BROWN, TX_WHITE, TX_WHITE, lineAngle - 90, bodyRotNormal);
00573         drawBaloonOnFirstScene (3100, 400, cameraX, cameraY, 150);
00574         drawFlag (3700 - cameraX, 633 - cameraY, 150, "C++", RGB (111, 49, 152), TX_YELLOW);
00575         drawEverythingWeather();
00576 
00577         doSleep (4);
00578         }
00579     }
00580 
00581 void walkMountains (POINT* mountains, int elems, int manHeight)
00582     {
00583     for (int mountainIndex = 0; mountainIndex < elems-1; mountainIndex++)
00584         {
00585         walkLine (mountains[mountainIndex    ].x,
00586                   mountains[mountainIndex    ].y,
00587                   mountains[mountainIndex + 1].x,
00588                   mountains[mountainIndex + 1].y,
00589                   1, manHeight);
00590 
00591         electraSplash();
00592         }
00593     }
00594 
00595 void fromLogoToCPP()
00596     {
00597     int cameraX = 0,
00598         cameraY = 600,
00599         t       = 0;
00600 
00601     for (; cameraX < 1600; cameraX += SPEED, doSleep (2))
00602         {
00603         drawScene (cameraX, cameraY);
00604         drawTurtlesOnFirstScene (350 - cameraX / 5, 1050 - cameraY, cameraX);
00605         drawStickMan (480 - cameraX / 5, 375 + 48, 120, 90, 10, 0, 185, 185, 148, 45, 60, 45, TX_BLACK, NORMAL_BROWN, TX_WHITE, TX_WHITE, 0, 0);
00606         drawBaloonOnFirstScene (2000, 700, cameraX, cameraY, 150);
00607         }
00608 
00609     for (t = 0; t < 40; t += SPEED, doSleep (10))
00610         {
00611         drawScene (cameraX, cameraY);
00612         drawTurtlesOnFirstScene (350 - cameraX / 5, 1050 - cameraY, cameraX);
00613         drawStickMan (480 - cameraX / 5 + t*6, 375 - t*2 + 48, 120, 30, 10, t * 3 % 90, 185, 185, 90 + t * 2, 90 + t * 2, 60, 90, TX_BLACK, NORMAL_BROWN, TX_WHITE, TX_WHITE, 0, 0);
00614         drawBaloonOnFirstScene (2000, 700, cameraX, cameraY, 150);
00615         }
00616 
00617     for (t = 0; t < 200; t += SPEED, doSleep (5))
00618         {
00619         txBitBlt (txDC(), 0, t - 600, 800, 600, trueSunny_up, 0, 0);
00620         drawScene (cameraX + t / 2, cameraY-t);
00621         drawTurtlesOnFirstScene (350 - cameraX / 5, 1050 - cameraY, cameraX);
00622         drawStickMan (400, 285 + 48 + t/25, 120 + t/10, 30, 10, 0, 185, 185, 170, 170, 60, 90, TX_BLACK, NORMAL_BROWN, TX_WHITE, TX_WHITE, 0, 0);
00623         drawBaloonOnFirstScene (2000 + t, 700 - t*2, cameraX, cameraY, 150);
00624 
00625         cameraY -= 2 * SPEED;
00626         cameraX += SPEED;
00627         }
00628 
00629     cameraX += t/2;
00630     cameraY -= t;
00631 
00632     double vel = 0.1;
00633 
00634     for (t = 0; t < 430; t += SPEED, doSleep (5))
00635         {
00636         drawScene (cameraX, cameraY);
00637         drawStickMan (400, 285+56, 140, 30, 10, 0, 185, 185, 170, 170, 60, 90, TX_BLACK, NORMAL_BROWN, TX_WHITE, TX_WHITE, 0, 0);
00638         drawBaloonOnFirstScene (cameraX + 400, cameraY + 100, cameraX, cameraY, 150);
00639         slideClouds (800 - t * 9/4, -t / 6);
00640 
00641         cameraX = (int) (cameraX + vel * 2 * SPEED);
00642         cameraY = (int) (cameraY + vel     * SPEED);
00643         vel    += 0.005                    * SPEED;
00644         }
00645 
00646     cameraX = 2700;
00647     cameraY = 300;
00648 
00649     prepareMountains (TX_DARKGRAY, TX_LIGHTGRAY, TX_GREEN, TX_LIGHTGREEN);
00650 
00651     txClear();
00652     drawGradientRectangle (0, 0, 800, 600, TX_BLACK, TX_DARKGRAY);
00653 
00654     txDeleteDC (trueSunny_up);
00655     trueSunny_up = txCreateCompatibleDC (800, 600);
00656     txBitBlt (trueSunny_up, 0, 0, 800, 600, txDC(), 0, 0);
00657 
00658     txSleep (300);
00659 
00660     for (int x = 0; x < 8; x++) scene[x][0] = trueSunny_up;
00661 
00662     POINT path[10] = {{ 3100, 651 },
00663                       { 3181, 821 },
00664                       { 3233, 827 },
00665                       { 3301, 740 },
00666                       { 3377, 840 },
00667                       { 3427, 840 },
00668                       { 3500, 740 },
00669                       { 3568, 829 },
00670                       { 3619, 813 },
00671                       { 3700, 633 }};
00672 
00673     walkMountains (path, 10, 140);
00674 
00675     txSleep (200);
00676 
00677     cameraX = 3300;
00678     cameraY = 277;
00679 
00680     for (t = 0; t < 180; t += 5, doSleep (15))
00681         {
00682         drawScene (cameraX, cameraY);
00683         drawFlag (400, 356, 150, "C++", RGB (111, 49, 152), TX_YELLOW);
00684 
00685         drawPortalSystem (400, 286, ((t > 90)? 180 - t     : t), 9, 8, t * 5, TX_WHITE, TX_WHITE, TX_GRAY);
00686         drawStickMan     (400, 300, ((t > 90)? 230 - t*6/5 : 30), 30, 10 - t/18, 45, 185, 185, 165, 165, 60, 90, TX_BLACK, NORMAL_BROWN, TX_WHITE, TX_WHITE, 0, 0);
00687 
00688         drawEverythingWeather();
00689         }
00690 
00691     for (; t < 200; t += 1, doSleep (20))
00692         drawRain (15, 15, 30, t % 10, 1, getRandom (1, 2) == 1 ? TX_BLUE : TX_LIGHTBLUE);
00693 
00694     txSleep (200);
00695 
00696     txSetFillColor (TX_BLACK);
00697     txRectangle (0, 0, 800, 600);
00698 
00699     deleteDCs();
00700     }
00701 
00702 void drawPies (int x, int y, int xSize, int ySize, int pieAngle, int angleOffset, COLORREF color, COLORREF special, COLORREF border, int thickness)
00703     {
00704     txSetFillColor (color);
00705     txSetColor (border, thickness);
00706 
00707     for (int n = 0; n < (360 / pieAngle); n++)
00708         {
00709         txSetFillColor ((n % 2 == 0)? color : special);
00710         txPie (x - xSize/2, y - ySize/2, x + xSize/2, y + ySize/2, n * pieAngle + angleOffset, pieAngle);
00711         }
00712     }
00713 
00714 void deleteDCs()
00715     {
00716     txDeleteDC (sunnyBackground_1);
00717     txDeleteDC (sunnyBackground_2);
00718     txDeleteDC (sunnyBackground_3);
00719 
00720     txDeleteDC (pear);
00721     txDeleteDC (apple);
00722     txDeleteDC (orange);
00723 
00724     txDeleteDC (shellForLeaderTurtle);
00725     txDeleteDC (shellForSecondTurtle);
00726     txDeleteDC (shellForKid);
00727     }
00728 
00729 void doHDCPreparations()
00730     {
00731     // ==================================================
00732 
00733     drawGradientCircle (15,15,10, LIGHT_ORANGE, TX_ORANGE);
00734 
00735     orange = txCreateCompatibleDC (30,30);
00736     txBitBlt (orange, 0, 0, 30, 30, txDC(), 0, 0);
00737 
00738     txSetColor (TX_TRANSPARENT);
00739     txSetFillColor (TX_BLACK);
00740     txRectangle (0, 0, 100, 100);
00741 
00742     // ==================================================
00743 
00744     txSetFillColor (SUN_BORDER);
00745     txCircle (15, 15, 10);
00746     txCircle (15, 7, 6);
00747 
00748     pear = txCreateCompatibleDC (30,30);
00749     txBitBlt (pear, 0, 0, 30, 30, txDC(), 0, 0);
00750 
00751     // ==================================================
00752 
00753     txSetColor (TX_TRANSPARENT);
00754     txSetFillColor (TX_BLACK);
00755     txRectangle (0, 0, 100, 100);
00756 
00757     txSetFillColor (TX_GREEN);
00758     txCircle (15, 15, 10);
00759     drawGradientCircle (12, 12, 5, TX_LIGHTGREEN, TX_GREEN);
00760 
00761     apple = txCreateCompatibleDC (30, 30);
00762     txBitBlt (apple, 0, 0, 30, 30, txDC(), 0, 0);
00763 
00764     // ==================================================
00765 
00766     drawGradientRectangle (0,0,800,200, SUNNYSKY_UP, SUNNYSKY_DOWN);
00767     drawGradientRectangle (0,200,800,600, SUNNYGROUND_UP, SUNNYGROUND_DOWN);
00768     drawTree (400, 300, 35, 55, 3, 15, TX_RED, TX_ORANGE, apple);
00769     drawTree (200, 200, 50, 70, 4, 12, TX_ORANGE, LIGHT_ORANGE, orange);
00770     drawTree (250, 450, 50, 100, 4, 16, TX_ORANGE, LIGHT_ORANGE, pear);
00771     drawTree (700, 200, 60, 40, 1, 25, TX_BROWN, LIGHT_ORANGE, apple);
00772     drawTree (600, 440, 35, 40, 2, 20, TX_BROWN, LIGHT_ORANGE, pear);
00773 
00774     sunnyBackground_1 = txCreateCompatibleDC (800, 600);
00775     txBitBlt (sunnyBackground_1, 0, 0, 800, 600, txDC(), 0, 0);
00776 
00777     // ==================================================
00778 
00779     drawGradientRectangle (0, 0, 800, 200, SUNNYSKY_UP, SUNNYSKY_DOWN);
00780     drawGradientRectangle (0, 200, 800, 600, SUNNYGROUND_UP, SUNNYGROUND_DOWN);
00781     drawTree (150, 200, 30, 80, 3, 17, TX_RED, TX_ORANGE, apple);
00782     drawTree (350, 450, 30, 60, 4, 15, TX_BROWN, TX_ORANGE, pear);
00783     drawTree (450, 190, 20, 50, 4, 12, TX_RED, NORMAL_BROWN, apple);
00784     drawTree (650, 350, 20, 50, 3, 15, TX_RED, NORMAL_BROWN, orange);
00785 
00786     sunnyBackground_2 = txCreateCompatibleDC (800, 600);
00787     txBitBlt (sunnyBackground_2, 0, 0, 800, 600, txDC(), 0, 0);
00788 
00789     // ==================================================
00790 
00791     drawGradientRectangle (0, 0, 800, 200, SUNNYSKY_UP, SUNNYSKY_DOWN);
00792     drawGradientRectangle (0, 200, 800, 600, SUNNYGROUND_UP, SUNNYGROUND_DOWN);
00793     drawTree (150, 250, 30, 80, 4, 13, TX_RED, TX_ORANGE, orange);
00794     drawTree (350, 450, 30, 60, 3, 18, TX_BROWN, TX_ORANGE, apple);
00795     drawTree (450, 200, 20, 50, 3, 15, TX_RED, NORMAL_BROWN, pear);
00796 
00797     drawMountain (700, 600, 500, 550, 200, TX_ORANGE, RGB (220,220,255), TX_GRAY);
00798 
00799     sunnyBackground_3 = txCreateCompatibleDC (800, 600);
00800     txBitBlt (sunnyBackground_3, 0, 0, 800, 600, txDC(), 0, 0);
00801 
00802     // ==================================================
00803 
00804     prepareMountains (SUNNYSKY_UP, SUNNYSKY_DOWN, SUNNYGROUND_UP, SUNNYGROUND_DOWN);
00805 
00806     txClear();
00807 
00808     // ==================================================
00809 
00810     drawGradientRectangle (0,0,800,600, TX_BLUE, SUNNYSKY_UP);
00811 
00812     trueSunny_up = txCreateCompatibleDC (800, 600);
00813     txBitBlt (trueSunny_up, 0, 0, 800, 600, txDC(), 0, 0);
00814 
00815     shellForLeaderTurtle = txCreateCompatibleDC (250, 125);
00816     prepareTurtleShell (250, 125, LIGHT_ORANGE, NORMAL_BROWN, TX_YELLOW, 2);
00817     txTransparentBlt (shellForLeaderTurtle, 0, 0, 250, 125, txDC(), 0, 62);
00818 
00819     shellForSecondTurtle = txCreateCompatibleDC (160, 80);
00820     prepareTurtleShell (160, 80, GREEN_MEDIUM, TX_CYAN, TX_BLUE, 2);
00821     txTransparentBlt (shellForSecondTurtle, 0, 0, 160, 80, txDC(), 0, 40);
00822 
00823     shellForKid = txCreateCompatibleDC (80, 40);
00824     prepareTurtleShell (80, 40, TX_RED, TX_LIGHTRED, NORMAL_BROWN, 1);
00825     txTransparentBlt (shellForKid, 0, 0, 80, 40, txDC(), 0, 20);
00826 
00827     txSelectFont ("Comic Sans MS", 60);
00828     PASCAL_LOGO_WIDTH = txGetTextExtentX ("Pascal");
00829 
00830     // ==================================================
00831 
00832     txSetFillColor (TX_BLACK);
00833     txClear();
00834 
00835     leftCloudlySlide = txCreateCompatibleDC (800, 600);
00836     drawCloud (600, 100, 200, 100, 40, 80, 40, TX_GRAY);
00837     drawCloud (550, 50, 200, 100, 40, 80, 40, TX_LIGHTGRAY);
00838     drawCloud (650, 75, 200, 100, 40, 80, 40, TX_DARKGRAY);
00839     drawCloud (605, 200, 200, 100, 40, 80, 40, TX_LIGHTGRAY);
00840     drawCloud (450, 120, 200, 100, 40, 80, 40, TX_GRAY);
00841     drawCloud (380, 175, 200, 100, 40, 80, 40, TX_DARKGRAY);
00842     drawCloud (380, 25, 200, 100, 40, 80, 40, TX_DARKGRAY);
00843     drawCloud (300, 125, 200, 100, 40, 80, 40, TX_LIGHTGRAY);
00844     txBitBlt (leftCloudlySlide, 0, 0, 800, 600, txDC(), 0, 0);
00845 
00846     txSetFillColor (TX_BLACK);
00847     txClear();
00848 
00849     rightCloudlySlide = txCreateCompatibleDC (800, 600);
00850     drawCloud (370, 100, 200, 100, 40, 80, 40, TX_LIGHTGRAY);
00851     drawCloud (320, 50 , 200, 100, 40, 80, 40, TX_DARKGRAY);
00852     drawCloud (420, 75 , 200, 100, 40, 80, 40, TX_GRAY);
00853     drawCloud (375, 200, 200, 100, 40, 80, 40, TX_DARKGRAY);
00854     drawCloud (220, 120, 200, 100, 40, 80, 40, TX_LIGHTGRAY);
00855     drawCloud (150, 175, 200, 100, 40, 80, 40, TX_GRAY);
00856     drawCloud (150, 25 , 200, 100, 40, 80, 40, TX_GRAY);
00857     drawCloud (500, 25 , 200, 100, 40, 80, 40, TX_LIGHTGRAY);
00858     drawCloud (500, 175, 200, 100, 40, 80, 40, TX_LIGHTGRAY);
00859     txBitBlt (rightCloudlySlide, 0, 0, 800, 600, txDC(), 0, 0);
00860 
00861     // ==================================================
00862 
00863     for (int x = 0; x < 7; x++) scene[x][0] = trueSunny_up;
00864 
00865     scene[0][1] = sunnyBackground_1;
00866     scene[1][1] = sunnyBackground_2;
00867     scene[2][1] = sunnyBackground_3;
00868     scene[4][1] = mountains_1;
00869     scene[5][1] = sunnyBackground_3;
00870     scene[6][1] = sunnyBackground_3;
00871     }
00872 
00873 void drawGradientRectangle (int x, int y, int x2, int y2, COLORREF topColor, COLORREF downColor)
00874     {
00875     int height = y2 - y;
00876 
00877     double currentRed   = txExtractColor (topColor, TX_RED),
00878            currentGreen = txExtractColor (topColor, TX_GREEN),
00879            currentBlue  = txExtractColor (topColor, TX_BLUE);
00880 
00881     double redChange    = (txExtractColor (downColor, TX_RED  ) - currentRed  ) / height,
00882            greenChange  = (txExtractColor (downColor, TX_GREEN) - currentGreen) / height,
00883            blueChange   = (txExtractColor (downColor, TX_BLUE ) - currentBlue ) / height;
00884 
00885     for (int yPos = y; yPos < y2; yPos++)
00886         {
00887         txSetColor (RGB (currentRed, currentGreen, currentBlue));
00888         txLine (x, yPos, x2, yPos);
00889 
00890         currentRed   += redChange;
00891         currentGreen += greenChange;
00892         currentBlue  += blueChange;
00893         }
00894     }
00895 
00896 void drawGradientCircle (int x, int y, int radius, COLORREF centerColor, COLORREF borderColor)
00897     {
00898     if (radius == 0) radius = 1;
00899 
00900     double currentRed   = txExtractColor (borderColor, TX_RED),
00901            currentGreen = txExtractColor (borderColor, TX_GREEN),
00902            currentBlue  = txExtractColor (borderColor, TX_BLUE);
00903 
00904     double redChange    = (txExtractColor (centerColor, TX_RED  ) - currentRed  ) / radius,
00905            greenChange  = (txExtractColor (centerColor, TX_GREEN) - currentGreen) / radius,
00906            blueChange   = (txExtractColor (centerColor, TX_BLUE ) - currentBlue ) / radius;
00907 
00908     for (int r = 0; r <= radius; r++)
00909         {
00910         txSetFillColor (RGB (currentRed, currentGreen, currentBlue));
00911         txSetColor     (RGB (currentRed, currentGreen, currentBlue));
00912 
00913         txCircle (x, y, radius-r);
00914 
00915         currentRed   += redChange;
00916         currentGreen += greenChange;
00917         currentBlue  += blueChange;
00918         }
00919     }
00920 
00921 void drawStripedCircle (int x, int y, int stripeRadius, int numberOfPairs, COLORREF fisrtStripe, COLORREF secondStripe)
00922     {
00923     int maxRadius = stripeRadius * numberOfPairs * 2;
00924 
00925     for (int n = 0; n < numberOfPairs; n++)
00926         {
00927         txSetFillColor (secondStripe);
00928         txCircle (x,y,maxRadius-n*stripeRadius*2);
00929 
00930         txSetFillColor (fisrtStripe);
00931         txCircle (x,y,maxRadius-n*stripeRadius*2-stripeRadius);
00932         }
00933     }
00934 
00935 void drawLeafPart (int x, int y, int size)
00936     {
00937     txSetColor (TX_TRANSPARENT);
00938 
00939     txSetFillColor (GREEN_DARK);
00940     txCircle (x-0.3*size, y+0.7*size, size);
00941 
00942     txSetFillColor (GREEN_MEDIUM);
00943     txCircle (x-0.5*size, y-0.5*size, size);
00944 
00945     txSetFillColor (GREEN_LIGHT);
00946     txCircle (x+0.7*size, y-0.3*size, size);
00947     }
00948 
00949 void drawLeafRow (int x, int y, int leafNumber, int leafSize)
00950     {
00951     int space     =  leafSize * 2/3;
00952     int totalSize = (leafSize * 2) * leafNumber + space * leafNumber;
00953 
00954     for (int i = 0; i < leafNumber; i++)
00955         drawLeafPart (x - totalSize / 2 + i * (leafSize * 2 + space) + leafSize * 3/2, y, leafSize);
00956     }
00957 
00958 void drawFruitRow (int x, int y, int leafNumber, int leafsize, HDC fruit)
00959     {
00960     int space     =  leafsize * 2/3;
00961     int totalsize = (leafsize * 2) * leafNumber + space * leafNumber;
00962 
00963     for (int i = 0; i < leafNumber-1; i++)
00964         txTransparentBlt (txDC(), x - totalsize/2 + i * (leafsize*2 + space) + leafsize*1.8, y-15, 30, 30, fruit, 0, 0, TX_BLACK);
00965     }
00966 
00967 void drawTree (int x, int y, int trunkWidth, int trunkHeight, int leafRowNumber, int leafSize, COLORREF borderColor, COLORREF fillColor, HDC fruit)
00968     {
00969     int circleDiameter = (int) (sqrt (2.0 * trunkWidth * trunkWidth) + 1.5);
00970 
00971     txSetFillColor (fillColor);
00972 
00973     txSetColor (borderColor, 2);
00974     txArc (x - circleDiameter / 2, y + trunkHeight - (circleDiameter + trunkWidth) / 2,
00975            x + circleDiameter / 2, y + trunkHeight + (circleDiameter - trunkWidth) / 2, 225, 90);
00976 
00977     txSetColor (TX_TRANSPARENT);
00978     txPie (x - circleDiameter / 2, y + trunkHeight - (circleDiameter + trunkWidth) / 2,
00979            x + circleDiameter / 2, y + trunkHeight + (circleDiameter - trunkWidth) / 2, 225, 90);
00980 
00981     POINT treePolygon[5] = {{ x - trunkWidth / 4, y               },
00982                             { x + trunkWidth / 4, y               },
00983                             { x + trunkWidth / 2, y + trunkHeight },
00984                             { x - trunkWidth / 2, y + trunkHeight },
00985                             { x - trunkWidth / 4, y               }};
00986 
00987     txPolygon (treePolygon, 5);
00988 
00989     txSetColor (borderColor, 2);
00990     txLine (x - trunkWidth / 4, y, x - trunkWidth / 2, y + trunkHeight);
00991     txLine (x + trunkWidth / 4, y, x + trunkWidth / 2, y + trunkHeight);
00992 
00993     txSetFillColor (fillColor);
00994 
00995     drawLeafRow (x, y, leafRowNumber, leafSize);
00996 
00997     int i = 0;
00998     for (i = 0; i < leafRowNumber; i++)
00999         drawLeafRow (x, y - leafSize *7/4 * (i+1), leafRowNumber + 1, leafSize);
01000 
01001     for (i = leafRowNumber; i >= 0; i--)
01002         drawLeafRow (x, y - leafSize *7/4 * (leafRowNumber*2 - i), i+1, leafSize);
01003 
01004     drawFruitRow (x, y, leafRowNumber, leafSize, fruit);
01005 
01006     for (i = 0; i < leafRowNumber; i++)
01007         drawFruitRow (x, y - leafSize *7/4 * (i+1), leafRowNumber + 1, leafSize, fruit);
01008 
01009     for (i = leafRowNumber; i >= 0; i--)
01010         drawFruitRow (x, y - leafSize *7/4 * (leafRowNumber*2 - i), i+1, leafSize, fruit);
01011     }
01012 
01013 void prepareTurtleShell (int width, int height, COLORREF baseColor, COLORREF specials, COLORREF border, int thickness)
01014     {
01015     txSetColor (TX_TRANSPARENT);
01016     txSetFillColor (TX_BLACK);
01017     txRectangle (0, 0, width, height);
01018 
01019     txSetFillColor (TX_WHITE);
01020     txEllipse (0, 0, width, height * 2);
01021 
01022     HDC mask = txCreateCompatibleDC (width, height);
01023     txBitBlt (mask, 0, 0, width, height, txDC(), 0, 0);
01024 
01025     txSetFillColor (TX_BLACK);
01026     txRectangle (0, 0, width, height * 2);
01027     txSetFillColor (TX_WHITE);
01028     txEllipse (0, 0, width, height);
01029 
01030     HDC mask_down = txCreateCompatibleDC (width, height);
01031     txBitBlt (mask_down, 0, 0, width, height, txDC(), 0, 0);
01032 
01033     txSetFillColor (TX_BLACK);
01034     txRectangle (0, 0, width, height*2);
01035 
01036     drawStyledTurtleShell (width/2, height/2, height *5/2, width, height/5, width/10,
01037                            7, 20, width/25, baseColor, specials, border, thickness);
01038 
01039     txTransparentBlt (txDC(), 0, height/2, width, height, mask,      0, 0, TX_WHITE);
01040     txTransparentBlt (txDC(), 0, height/2, width, height, mask_down, 0, 0, TX_WHITE);
01041 
01042     txDeleteDC (mask);
01043     txDeleteDC (mask_down);
01044     }
01045 
01046 
01047 void drawTurtleBody (int x, int y, int width, int height, int walkingPos, COLORREF body, COLORREF border, COLORREF eye, COLORREF eyeBorder, HDC shell)
01048     {
01049     txSetFillColor (body);
01050     txSetColor (border, 2);
01051 
01052     POINT polygon[5] = {{ x + width *7/8, y + height *7/8                },
01053                         { x + width,      y + height *7/8                },
01054                         { x + width *6/5, y + height *1/5 + walkingPos/2 },
01055                         { x + width,      y + height *1/5 + walkingPos/2 },
01056                         { x + width *7/8, y + height *7/8                }};
01057 
01058     txPolygon (polygon, 5);
01059 
01060     txEllipse (x - walkingPos/3, y + height *3/4, x + width, y + height);
01061     txEllipse (x + width, y + walkingPos/2, x + width*1.3, y + height*0.4 + walkingPos/2);
01062 
01063     txSetColor (TX_TRANSPARENT);
01064     txPolygon (polygon, 5);
01065 
01066     txSetFillColor (eye);
01067     txSetColor (eyeBorder);
01068     txEllipse (x + width * 1.1, y + height * 0.05 + walkingPos/2 + walkingPos/5,
01069                x + width * 1.2, y + height * 0.3  + walkingPos/2 - walkingPos/3);
01070 
01071     txSetFillColor (eyeBorder);
01072     txCircle (x + width * 1.15, y + height * 0.15 + walkingPos / 2, 2);
01073 
01074     txSetFillColor (body);
01075     txSetColor (border, 2);
01076     txCircle (x + width * 0.9 - walkingPos, y + height, width / 16);
01077     txCircle (x + width * 0.8 + walkingPos, y + height, width / 16);
01078     txCircle (x + width * 0.3 - walkingPos, y + height, width / 16);
01079     txCircle (x + width * 0.2 + walkingPos, y + height, width / 16);
01080 
01081     txTransparentBlt (txDC(), x + width/20, y + height/10 + walkingPos/3, width-1, height,
01082                       shell, 0, 0, TX_BLACK);
01083     }
01084 
01085 
01086 void drawTurtle (int x, int y, int width, int height, COLORREF shellColor, COLORREF stripesColor)
01087     {
01088     txSetColor (stripesColor, 1);
01089     txSetFillColor (shellColor);
01090     txPie (x - width / 2, y - height, x + width / 2, y + height, 0, 180);
01091 
01092     txSetColor (TX_TRANSPARENT);
01093     txSetFillColor (stripesColor);
01094 
01095     txEllipse (x - width * 4 / 22, y - height * 17/22, x + width * 4/22, y - height*5/22);
01096     txEllipse (x - width * 2 / 22, y - height * 4/22, x + width * 2/22, y);
01097     txEllipse (x - width * 2 / 22, y - height, x + width * 2/22, y - height*18/22);
01098     txEllipse (x - width * 4 / 22, y - height * 17/22, x + width*4/22, y - height * 5/22);
01099     }
01100 
01101 void drawBaloon (int x, int y, int radius, int sizeOfStripe, COLORREF centerStripe, COLORREF secondStripe, COLORREF base, COLORREF border)
01102     {
01103     txSetColor (border, 1);
01104     txSetFillColor (base);
01105 
01106     POINT baseFigure[5] = {{ x - radius / 2  , y + radius * 3/2 },
01107                            { x + radius / 2  , y + radius * 3/2 },
01108                            { x + radius * 2/5, y + radius * 2   },
01109                            { x - radius * 2/5, y + radius * 2   },
01110                            { x - radius / 2  , y + radius * 3/2 }};
01111 
01112     txPolygon (baseFigure, 5);
01113 
01114     int number = 0;
01115     for (number = 0; number < radius / sizeOfStripe; number++)
01116         {
01117         txSetColor (border, 1);
01118         txLine (x - radius + number * sizeOfStripe,     y, x - radius/2 + number * sizeOfStripe / 2, y + radius * 1.5);
01119         txLine (x + radius - number * sizeOfStripe - 1, y, x + radius/2 - number * sizeOfStripe / 2, y + radius * 1.5);
01120 
01121         txSetColor (TX_BLACK, 1);
01122         txSetFillColor ((number % 2 == 0)? centerStripe : secondStripe);
01123 
01124         txEllipse (x - radius + number * sizeOfStripe, y - radius, x + radius - number * sizeOfStripe, y + radius);
01125         }
01126 
01127     txSetFillColor ((number % 2 == 0)? centerStripe : secondStripe);
01128     txEllipse (x - sizeOfStripe / 2, y - radius, x + sizeOfStripe / 2, y + radius);
01129 
01130     txSetColor (border);
01131     txLine (x, y + radius, x, y + radius * 1.5);
01132     }
01133 
01134 void calculateTables()
01135     {
01136     for (int x = 0; x < 360; x++)
01137         {
01138         sinTable[x] = sin (x * txPI / 180);
01139         cosTable[x] = cos (x * txPI / 180);
01140         }
01141     }
01142 
01143 void trigonometricSetPointOfRest (int x, int y)
01144     {
01145     pointOfRest_x = x;
01146     pointOfRest_y = y;
01147     }
01148 
01149 int trigonometricGetNormalAngle (int ang)
01150     {
01151     int angle = ang;
01152 
01153     while (angle <   0) angle += 360;
01154     while (angle > 360) angle -= 360;
01155 
01156     return (angle <= 180)? 180 - angle : 540 - angle;
01157     }
01158 
01159 void trigonometricDrawLine (int angle, int lenght)
01160     {
01161     int ang = trigonometricGetNormalAngle (angle);
01162     int endx = (int) (pointOfRest_x + sinTable[ang] * lenght);
01163     int endy = (int) (pointOfRest_y + cosTable[ang] * lenght);
01164 
01165     txLine (pointOfRest_x, pointOfRest_y, endx, endy);
01166 
01167     pointOfRest_x = endx;
01168     pointOfRest_y = endy;
01169     }
01170 
01171 void trigonometricDrawLineAndReturn (int angle, int lenght)
01172     {
01173     int ang = trigonometricGetNormalAngle (angle);
01174     int endx = (int) (pointOfRest_x + sinTable[ang] * lenght);
01175     int endy = (int) (pointOfRest_y + cosTable[ang] * lenght);
01176 
01177     txLine (pointOfRest_x, pointOfRest_y, endx, endy);
01178     }
01179 
01180 void trigonometricMove (int angle, int lenght)
01181     {
01182     int ang = trigonometricGetNormalAngle (angle);
01183 
01184     pointOfRest_x = (int) (pointOfRest_x + sinTable[ang] * lenght);
01185     pointOfRest_y = (int) (pointOfRest_y + cosTable[ang] * lenght);
01186     }
01187 
01188 int trigonometricGetAngleOfLine (int x, int y, int x2, int y2)
01189     {
01190     return (int) (180 - (atan2 (1.0 * (x2 - x), 1.0 * (y2 - y)) * 180 / txPI));
01191     }
01192 
01193 void drawStickMan (int x, int y, int height, int hairIntensivity, int hairLenght, int walkingPosition,
01194                    int leftBase, int leftSpecial, int rightBase, int rightSpecial, int direction, int walkingAngle,
01195                    COLORREF bodyColor, COLORREF hairColor, COLORREF headColor, COLORREF eyeColor, int rotation, int bodyRot)
01196     {
01197     txSetColor     (bodyColor);
01198     txSetFillColor (headColor);
01199 
01200     trigonometricSetPointOfRest (x, y);
01201     trigonometricDrawLine (180 - walkingAngle / 2 + walkingPosition + rotation, height *2/5);
01202     trigonometricDrawLine ( 90 - walkingAngle / 2 + walkingPosition + rotation, height /20);
01203 
01204     int angleBetweenLegs = walkingPosition;
01205     if (angleBetweenLegs > walkingAngle / 2) angleBetweenLegs = walkingAngle - angleBetweenLegs;
01206 
01207     trigonometricSetPointOfRest (x, y);
01208     trigonometricDrawLine (180 + walkingAngle / 2 - walkingPosition + rotation, height / 5);
01209     trigonometricDrawLine (180 + walkingAngle / 2 - walkingPosition + angleBetweenLegs + rotation, height/5);
01210     trigonometricDrawLine ( 90 + walkingAngle / 2 - walkingPosition + angleBetweenLegs + rotation, height/20);
01211 
01212     trigonometricSetPointOfRest (x, y);
01213     trigonometricDrawLine (bodyRot + rotation, height * 2/5);
01214 
01215     int neckX = pointOfRest_x,
01216         neckY = pointOfRest_y;
01217 
01218     txSetColor (hairColor);
01219 
01220     trigonometricSetPointOfRest (neckX, neckY);
01221     trigonometricMove (bodyRot + rotation, height / 10);
01222 
01223     int headx = pointOfRest_x,
01224         heady = pointOfRest_y;
01225 
01226     int space      = 90 / hairIntensivity;
01227         hairLenght = hairLenght + height / 10;
01228 
01229     for (int number = 0; number < hairIntensivity + 1; number++)
01230         trigonometricDrawLineAndReturn (direction - 135 + space * number + rotation, hairLenght);
01231 
01232     txSetColor (bodyColor);
01233     txSetFillColor (headColor);
01234     txCircle (headx, heady, height / 10);
01235 
01236     trigonometricSetPointOfRest (headx, heady);
01237     trigonometricMove (direction      + rotation, height / 20);
01238     trigonometricMove (direction - 90 + rotation, height / 50);
01239 
01240     txSetFillColor (eyeColor);
01241     txCircle (pointOfRest_x,     pointOfRest_y, height / 50);
01242     txCircle (pointOfRest_x + 1, pointOfRest_y, height / 125);
01243 
01244     trigonometricSetPointOfRest (headx, heady);
01245     trigonometricMove     (direction + 15 + rotation, height / 20);
01246     trigonometricDrawLine (direction + 15 + rotation, height / 20);
01247 
01248     trigonometricSetPointOfRest (neckX, neckY);
01249     trigonometricDrawLine (leftBase    + rotation, height / 5);
01250     trigonometricDrawLine (leftSpecial + rotation, height / 5);
01251 
01252     trigonometricSetPointOfRest (neckX, neckY);
01253     trigonometricDrawLine (rightBase    + rotation, height / 5);
01254     trigonometricDrawLine (rightSpecial + rotation, height / 5);
01255     }
01256 
01257 POINT getPoint (int x, int y)
01258     {
01259     POINT p = {x, y};
01260     return p;
01261     }
01262 
01263 void drawMountain (int x, int y, int width, int height, int snowHeight, COLORREF ground, COLORREF snow, COLORREF border)
01264     {
01265     POINT mountain[3] = {{ x - width/2, y          },
01266                          { x + width/2, y          },
01267                          { x,           y - height }};
01268 
01269     txSetFillColor (ground);
01270     txSetColor (border, 2);
01271     txPolygon (mountain, 3);
01272 
01273     trigonometricSetPointOfRest (x, y - height);
01274     trigonometricMove (trigonometricGetAngleOfLine (x, y - height, x - width / 2, y), snowHeight);
01275 
01276     int pointX = pointOfRest_x,
01277         pointY = pointOfRest_y;
01278 
01279     int snowWidth = (x - pointOfRest_x) * 2;
01280     int snowSpace = height / 40;
01281     int snowPointsNumber = snowWidth/snowSpace;
01282 
01283     POINT* snowPolygon = new POINT [snowPointsNumber + 4];
01284 
01285     snowPolygon [0] =
01286     snowPolygon [snowPointsNumber + 3] = getPoint (x, y - height);
01287     snowPolygon [1]                    = getPoint (pointX, pointY);
01288 
01289     for (int snowVertexNumber = 0; snowVertexNumber < snowPointsNumber; snowVertexNumber++)
01290         snowPolygon[snowVertexNumber + 2] = getPoint (pointX + (snowVertexNumber + 1) * snowSpace,
01291                                             getRandom (pointY - height / 15, pointY + height / 15));
01292 
01293     snowPolygon[snowPointsNumber + 2] =
01294     snowPolygon[snowPointsNumber + 1] = getPoint (pointX+snowWidth, pointY);
01295 
01296     txSetFillColor (snow);
01297     txPolygon (snowPolygon, snowPointsNumber + 4);
01298 
01299     delete[] snowPolygon;
01300     }
01301 
01302 void drawTearsRow (int x, int y, int tearsLenght, int space, int offset)
01303     {
01304     int numberOfTears = (x + offset) / (tearsLenght + space) + 1;
01305 
01306     for (int n = 0; n < numberOfTears; n++)
01307         txLine (x + offset - n * (tearsLenght + space),
01308                 y - offset + n * (tearsLenght + space),
01309                 x + offset - n * (tearsLenght + space) - tearsLenght,
01310                 y - offset + n * (tearsLenght + space) + tearsLenght);
01311     }
01312 
01313 POINT getPointOnEllipse (int x, int y, int w, int h, double angle)
01314     {
01315     double trueAngle = 360- (angle-90) * txPI / 180;
01316 
01317     POINT p = { (int) (x + w / 2 * cos (trueAngle)),
01318                 (int) (y + h / 2 * sin (trueAngle)) };
01319     return p;
01320     }
01321 
01322 void drawRain (int columnsSpace, int tearsSpace, int tearsLenght, int animationFrame, int thickness, COLORREF color)
01323     {
01324     txSetColor (color, thickness);
01325 
01326     int number = 1400 / columnsSpace;
01327     int space = 0;
01328 
01329     for (int n = 0; n < number; n++)
01330         {
01331         drawTearsRow (space, 0, getRandom (tearsLenght - 4, tearsLenght), tearsSpace, tearsLenght + tearsSpace - animationFrame + n % 25);
01332         space += getRandom (columnsSpace - 1, columnsSpace + 4);
01333         }
01334     }
01335 
01336 void drawCloud (int x, int y, int width, int height, int everyAngle, int everyWidth, int everyHeight, COLORREF color)
01337     {
01338     txSetColor (TX_TRANSPARENT);
01339     txSetFillColor (color);
01340     txEllipse (x - width / 2, y - height / 2, x + width / 2, y + height / 2);
01341 
01342     for (int n = 0; n < 360 / everyAngle; n++)
01343         {
01344         POINT p = getPointOnEllipse (x, y, width, height, n * everyAngle);
01345         txEllipse (p.x - everyWidth / 2, p.y - everyHeight / 2, p.x + everyWidth / 2, p.y + everyHeight / 2);
01346         }
01347     }
01348 
01349 void drawPortal (int x, int y, int radius, int each, int bonusRot, COLORREF color, COLORREF alter)
01350     {
01351     txSetColor (color);
01352 
01353     trigonometricSetPointOfRest (x, y);
01354     trigonometricMove (bonusRot, radius);
01355 
01356     int lastx = pointOfRest_x,
01357         lasty = pointOfRest_y;
01358 
01359     int n = 360 / each;
01360 
01361     for (int a = 1; a <= n; a++)
01362         {
01363         trigonometricSetPointOfRest (x, y);
01364         trigonometricMove (a * each + bonusRot, radius);
01365 
01366         drawElectra (pointOfRest_x, pointOfRest_y,
01367                      trigonometricGetAngleOfLine (pointOfRest_x, pointOfRest_y, lastx, lasty),
01368                      5, 10, 45, 2,
01369                      color, alter, 0);
01370 
01371         txLine (pointOfRest_x, pointOfRest_y, lastx, lasty);
01372 
01373         lastx = pointOfRest_x;
01374         lasty = pointOfRest_y;
01375         }
01376     }
01377 
01378 // Assembler randomizing system
01379 
01380 const char* getRandomRegister()
01381     {
01382     return registers [rand() % sizearr (registers)];
01383     }
01384 
01385 const char* getRandomCommand()
01386     {
01387     char* buf = new char[20];
01388 
01389     if (rand() % 20 == 0)
01390         switch (rand() % 2)
01391             {
01392             case 0:  sprintf (buf, "call %s", functionNames [rand() % sizearr (functionNames)]);
01393                      return buf;
01394 
01395             case 1:  sprintf (buf, "jump %s", functionNames [rand() % sizearr (functionNames)]);
01396                      return buf;
01397 
01398             default: break;
01399             }
01400     else
01401         switch (rand() % 2)
01402             {
01403             case 0:  sprintf (buf, "%s %s, %s", twoRegisterCommands [rand() % sizearr (twoRegisterCommands)],
01404                                                 getRandomRegister(), getRandomRegister());
01405                      return buf;
01406 
01407             case 1:  sprintf (buf, "%s %s",     oneRegisterCommands [rand() % sizearr (oneRegisterCommands)],
01408                                                 getRandomRegister());
01409                      return buf;
01410 
01411             default: break;
01412             }
01413 
01414     return strcpy (buf, "nop");
01415     }
01416 
01417 // ============================
01418 
01419 void matrixFireball (int x, int y, const char* text, int len, int textHeight, COLORREF color)
01420     {
01421     txSetTextAlign  (TA_CENTER);
01422 
01423     int yBonus = 0;
01424     for (int a = 0; a < len; a++)
01425         {
01426         txSelectFont ("Comic Sans MS", textHeight + a, false, false, false);
01427         txSetTextAlign (TA_CENTER);
01428         txSetColor (color);
01429 
01430         const char str[2] = { text[a], 0 };
01431         txTextOut (x, y + yBonus, str);
01432 
01433         yBonus += (textHeight + a) * 4/5;
01434         }
01435     }
01436 
01437 void matrixEngineInit (int count)
01438     {
01439     matrixElementsNumber     = count;
01440     matrixElementsYPositions = new int   [count];
01441     matrixElementsNames      = new char* [count];
01442 
01443     for (int x = 0; x < count; x++)
01444         {
01445         matrixElementsYPositions[x] = getRandom (-200, 500);
01446         matrixElementsNames[x]      = new char [20];
01447 
01448         const char* command = getRandomCommand();
01449         strcpy (matrixElementsNames[x], command);
01450         delete[] (const char*) command;
01451         }
01452     }
01453 
01454 void matrixEngineLoop (int spd, COLORREF col)
01455     {
01456     txSetTextAlign (TA_BASELINE | TA_LEFT);
01457     txSelectFont ("Comic Sans MS", 100, false, false, false);
01458 
01459     for (int a = 0; a < matrixElementsNumber; a++)
01460         {
01461         matrixElementsYPositions[a] += spd;
01462 
01463         if (matrixElementsYPositions[a] >  600 ||
01464             matrixElementsYPositions[a] < -600)
01465             {
01466             delete matrixElementsNames[a];
01467             matrixElementsNames[a] = new char[20];
01468 
01469             matrixElementsYPositions[a] = -getRandom (400, 800);
01470 
01471             const char* randomCommand = getRandomCommand();
01472             strcpy (matrixElementsNames[a], randomCommand);
01473             delete[] (const char*) randomCommand;
01474             }
01475 
01476         matrixFireball (a * 40, matrixElementsYPositions[a],       matrixElementsNames[a],                                      10, 20, col);
01477         matrixFireball (a * 40, matrixElementsYPositions[a] + 300, matrixElementsNames[a < matrixElementsNumber-1 ? a+1 : a-1], 10, 20, col);
01478         }
01479     }
01480 
01481 const char* getStairsGround (int lenght)
01482     {
01483     char* ret = new char[lenght + 1];
01484     ret[lenght] = 0;
01485 
01486     for (int i = 0; i < lenght; i++) ret[i] = (char) getRandom (48, 49);
01487 
01488     return ret;
01489     }
01490 
01491 void generateBinaryStairs (int difference, int flats)
01492     {
01493     binaryStairsGrounds = new char* [flats];
01494     binaryStairsHeight  = flats;
01495 
01496     for (int i = 0; i < flats; i++)
01497         {
01498         binaryStairsGrounds[i]   = new char        [(i + 1 ) * difference + 1];
01499 
01500         const char* stairsGround = getStairsGround ((i + 1 ) * difference);
01501         strcpy (binaryStairsGrounds[i], stairsGround);
01502         delete[] (const char*) stairsGround;
01503         }
01504     }
01505 
01506 void destroyBinaryStairsAndMatrix()
01507     {
01508     int i = 0;
01509 
01510     for (i = 0; i < binaryStairsHeight; i++) delete binaryStairsGrounds[i];
01511     delete binaryStairsGrounds;
01512 
01513     delete matrixElementsYPositions;
01514 
01515     for (i = 0; i < matrixElementsNumber; i++) delete matrixElementsNames[i];
01516     delete matrixElementsNames;
01517     }
01518 
01519 void drawBinaryStairs (int x, int y, COLORREF color)
01520     {
01521     txSetTextAlign (TA_RIGHT);
01522     txSelectFont ("Comic Sans MS", 20, false, false, false);
01523     txSetColor (color);
01524 
01525     for (int i = 0; i < binaryStairsHeight; i++)
01526         txTextOut (x, y + i * 20, binaryStairsGrounds[i]);
01527     }
01528 
01529 void drawASMFlag (int x, int y)
01530     {
01531     txSetTextAlign (TA_BASELINE | TA_LEFT);
01532 
01533     txTextOut (x, y,       "111111111");
01534     txTextOut (x, y + 20,  "11ASM11");
01535     txTextOut (x, y + 40,  "111111111");
01536     txTextOut (x, y + 60,  "1");
01537     txTextOut (x, y + 80,  "1");
01538     txTextOut (x, y + 100, "1");
01539     }
01540 
01541 void initIO()
01542     {
01543     sourceFile = fopen (__FILE__, "r");
01544     if (sourceFile == 0) TX_THROW ("Cannot open source file");
01545     }
01546 
01547 void readCodePro()
01548     {
01549     txSetDefaults();
01550     txSetFillColor (TX_BLACK);
01551     txSetColor (RGB (0, 150, 0));
01552     txClear();
01553 
01554     initIO();
01555 
01556     fseek (sourceFile, 0, SEEK_END);
01557     unsigned fileSize = MIN (ftell (sourceFile), 10000);
01558     fseek (sourceFile, 0, SEEK_SET);
01559 
01560     char* allData = new char [fileSize + 100];
01561     int numberOfStrings = 0;
01562 
01563     try {
01564         unsigned i = 0;
01565 
01566         for (i = 0; i < fileSize; i++)
01567             {
01568             allData[i] = (char) fgetc (sourceFile);
01569             if (allData[i] == '\n') numberOfStrings++;
01570             }
01571 
01572         fileSize += (unsigned) strlen (strcpy (&allData[i-1], "\n    ...\n"));
01573         numberOfStrings += 2;
01574 
01575         partsAmount = numberOfStrings / 30 + 1;
01576 
01577         sourceCodeParts = new HDC [partsAmount + 1];
01578         for (i = 0; i < partsAmount + 1u; i++) sourceCodeParts[i] = NULL;
01579 
01580         int lastStringYID    = 0;
01581         int lastStringLength = 0;
01582         int lastSourcePart   = 0;
01583 
01584         for (i = 0; i < fileSize; i++)
01585             {
01586             if ((allData[i] == '\n') || (i == fileSize-1))
01587                 {
01588                 allData[i] = 0;
01589                 if (i != fileSize-1) txTextOut (0, lastStringYID * 20, allData + (i - lastStringLength));
01590 
01591                 lastStringYID++;
01592                 lastStringLength = 0;
01593 
01594                 if (lastStringYID == 30 || i >= fileSize-1)
01595                     {
01596                     HDC nHDC = txCreateCompatibleDC (800, 600);
01597                     txBitBlt (nHDC, 0, 0, 800, 600, txDC(), 0, 0);
01598                     sourceCodeParts[lastSourcePart] = nHDC;
01599  
01600                     lastSourcePart++;
01601                     lastStringYID = 0;
01602 
01603                     txClear();
01604                     }
01605                 }
01606             else
01607                 lastStringLength++;
01608             }
01609 
01610         fclose (sourceFile);
01611         
01612         sourceCodeParts[lastSourcePart] = txCreateCompatibleDC (800, 600);
01613         }
01614 
01615     catch (...)
01616         {}
01617 
01618     delete[] allData;
01619     }
01620 
01621 void printEffect (int x, int y, const char* text, int lenght, int delay)
01622     {
01623     doSleep (delay);
01624 
01625     for (int i = 0; i < lenght; i++)
01626         {
01627         char buf[2] = { text[i] };
01628         txTextOut (x + txGetTextExtentX (text) * i / lenght * 1.2, y, buf);
01629 
01630         doSleep (delay);
01631         }
01632     }
01633 
01634 void releaseScrollingSource()
01635     {
01636     for (int i = 0; i < partsAmount; i++) txDeleteDC (sourceCodeParts[i]);
01637 
01638     delete[] sourceCodeParts;
01639     sourceCodeParts = NULL;
01640     }
01641 
01642 void fromAssemblerAndUpToTheVeryEnd()
01643     {
01644     matrixEngineInit (20);
01645     generateBinaryStairs (10, 10);
01646     readCodePro();
01647 
01648     // Smooth matrix color change
01649     int period = 20;
01650     int change = 1;
01651     int greenCooficient = 150;
01652 
01653     COLORREF stickColor = RGB (200, 255, 200);
01654 
01655     for (int t = 0; t < 210; t += SPEED)
01656         {
01657         int tMan = (t < 200)? t : 200;
01658 
01659         trigonometricSetPointOfRest (50, 520);
01660         trigonometricMove (77, tMan * 7/2);
01661 
01662         txSetFillColor (TX_BLACK);
01663         txClear();
01664 
01665         matrixEngineLoop (100, RGB (0, greenCooficient, 0));
01666         drawBinaryStairs (800, 400, TX_GREEN);
01667         drawASMFlag (720, 300);
01668         drawStickMan (pointOfRest_x, pointOfRest_y, 120, 30, 10, (tMan * 6 % 90), 185, 185, 90, 90, 60, 90,
01669                      TX_GREEN, NORMAL_BROWN, stickColor, TX_WHITE, -20 + tMan / 10, 0);
01670 
01671         doSleep (15);
01672 
01673         greenCooficient += change;
01674         period--;
01675 
01676         if (period == 0)
01677             {
01678             period = getRandom (5, 40);
01679             change = getRandom (1, 2) == 1 ? 1 : -1;
01680 
01681             if      (greenCooficient + period * change <  10) change = -change;
01682             else if (greenCooficient + period * change > 240) change = -change;
01683             }
01684         }
01685 
01686     destroyBinaryStairsAndMatrix();
01687 
01688     txSetFillColor (TX_BLACK);
01689     txClear();
01690     printEffect (20, 20,  "Critical Error!", 15, 10/SPEED);
01691     printEffect (20, 60,  "Critical Error!", 15, 10/SPEED);
01692     printEffect (20, 100, "Rebooting...",    12, 10);
01693     txSleep (3000);
01694 
01695     setTextSpeed (10 - SPEED);
01696     double sourceCodeYScrolled = 0;
01697 
01698     for (; sourceCodeYScrolled < partsAmount * 600; sourceCodeYScrolled += SPEED)
01699         {
01700         txSetFillColor (TX_BLACK);
01701         txClear();
01702 
01703         int roundY = (int) sourceCodeYScrolled;
01704 
01705         HDC hDC = txDC();
01706         txBitBlt (hDC, 0,     - (roundY % 600), 800, 600, sourceCodeParts[roundY / 600    ], 0, 0);
01707         txBitBlt (hDC, 0, 600 - (roundY % 600), 800, 600, sourceCodeParts[roundY / 600 + 1], 0, 0);
01708 
01709         lastTextEngineLoop (mixColor (TX_BLACK, RGB (0, 200, 0), roundY < 100 ? roundY : 100));
01710 
01711         doSleep (4);
01712         }
01713 
01714     releaseScrollingSource();
01715     }
01716 
01717 void drawPrintingEffect (int x, int y, const char* whatToPrint, int howMany, COLORREF color)
01718     {
01719     txSetColor (color);
01720 
01721     int charWidthTotal = 0;
01722 
01723     for (int i = 0; i < howMany; i++)
01724         {
01725         const char toPrintNow[2] = { whatToPrint[i], 0 };
01726         txTextOut (x + charWidthTotal, y, toPrintNow);
01727 
01728         charWidthTotal += txGetTextExtentX (toPrintNow);
01729         }
01730     }
01731 
01732 int centerOutByLeftCorner (const char* toCenter)
01733     {
01734     int ts = txGetTextExtentX (toCenter);
01735     return 400 - ts / 2;
01736     }
01737 
01738 int getMainLoopBasedValue (int mainLoop, int from, int to)
01739     {
01740     return mainLoop + from > to ? to : from + mainLoop;
01741     }
01742 
01743 int textEngineIndex = 0;
01744 
01745 const char* theEnd    = "The end...";
01746 const char* createdBy = "Created by Nikita Uvarov";
01747 
01748 int lenghtOfTheEnd    = (int) strlen (theEnd),
01749     lenghtOfCreatedBy = (int) strlen (createdBy);
01750 
01751 int textEngineSpeed = 1;
01752 
01753 void setTextSpeed (int spd)
01754     {
01755     textEngineSpeed = spd;
01756     }
01757 
01758 void lastTextEngineLoop (COLORREF color)
01759     {
01760     txSelectFont ("Comic Sans MS", 50, 25, 1000);
01761 
01762     drawPrintingEffect (centerOutByLeftCorner (theEnd),    200, theEnd,    getMainLoopBasedValue (textEngineIndex / textEngineSpeed, 0, lenghtOfTheEnd + 1), color);
01763     drawPrintingEffect (centerOutByLeftCorner (createdBy), 320, createdBy, getMainLoopBasedValue (textEngineIndex / textEngineSpeed, -lenghtOfTheEnd * 3 / 2, lenghtOfCreatedBy + 1), color);
01764 
01765     textEngineIndex += SPEED;
01766     }