//------------------------------- Experiments in Moving Text along the Screen // // Produces interesting effects if the render and erase operations are out // of sync or if the render and erase texts are different. // //--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit1.h" #include #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; // initial variables for each move type int down=0; // counter for the down timer int diag=0; // counter for the diagonal timer int freefall=0; // counter for the freefall timer int dis=0; // counter for the disintegration timer int alpha[14]; // the vertical position of each character int delay[14]; // random delay for each letter int start=30; // time before disintegration begins int last[14]; // the vertical position of the last render // gravitational variabiles int s=0; // distance int a=2; // acceleration int t=0; // time int lasts=0; // last value of s //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { // Sets the background of the text to transparent. Form1->Canvas->Brush->Style = bsClear; randomize(); } //---------------------------------------------------------------- Down Timer //----------------------------------------- Moves Down at a Constant Velocity void __fastcall TForm1::TimerDownTimer(TObject *Sender) { down++; down++; // backs up to erase previous text if (down>1) { Form1->Canvas->Font->Color=clBtnFace; Form1->Canvas->TextOut(150, down-2, "Lower me down."); } // moves forward to render new text Form1->Canvas->Font->Color=clBlack; Form1->Canvas->TextOut(150, down, "Lower me down."); // quit if (down==300) Form1->TimerDown->Enabled=false; } //------------------------------------------------------------ Diagonal Timer //------------------------ Moves Down and to the Right at a Constant Velocity void __fastcall TForm1::TimerDiagonallyTimer(TObject *Sender) { diag++; diag++; // backs up to erase previous text if (diag>1) { Form1->Canvas->Font->Color=clBtnFace; Form1->Canvas->TextOut(diag-2, diag-2, "I move diagonally."); } // moves forward to render new text Form1->Canvas->Font->Color=clBlack; Form1->Canvas->TextOut(diag, diag, "I move diagonally."); // quit if (diag==300) Form1->TimerDiagonally->Enabled=false; } //----------------------------------------------------------- Free Fall Timer //------------------------------------------ Simulates Gravitational FreeFall void __fastcall TForm1::TimerFreeFallTimer(TObject *Sender) { freefall++; // backs up to erase previous text if (freefall>1) { Form1->Canvas->Font->Color=clBtnFace; Form1->Canvas->TextOut(200, lasts, "Watch me fall."); } s = (a * freefall * freefall) / 2; // s=1/2(at^2) // moves forward to render new text Form1->Canvas->Font->Color=clBlack; Form1->Canvas->TextOut(200, s, "Watch me fall."); // quit if (s>=300) Form1->TimerFreeFall->Enabled=false; lasts=s; } //------------------------------------------------------ Disintegration Timer //--------------------------------------------- Simulates Disintegrating Text void __fastcall TForm1::TimerDisintegrationTimer(TObject *Sender) { dis++; Form1->Canvas->Font->Color=clBlack; if (dis>delay[0]) { if (dis>delay[0]) { Form1->Canvas->Font->Color=clBtnFace; Form1->Canvas->TextOut(10, last[0], "D"); } Form1->Canvas->Font->Color=clBlack; alpha[0] = (a * pow(dis-delay[0], 2)) / 2; Form1->Canvas->TextOut(10, alpha[0], "D"); last[0]=alpha[0]; } if (dis>delay[1]) { if (dis>delay[1]) { Form1->Canvas->Font->Color=clBtnFace; Form1->Canvas->TextOut(25, last[1], "i"); } Form1->Canvas->Font->Color=clBlack; alpha[1] = (a * pow(dis-delay[1], 2)) / 2; Form1->Canvas->TextOut(25, alpha[1], "i"); last[1]=alpha[1]; } if (dis>delay[2]) { if (dis>delay[2]) { Form1->Canvas->Font->Color=clBtnFace; Form1->Canvas->TextOut(32, last[2], "s"); } Form1->Canvas->Font->Color=clBlack; alpha[2] = (a * pow(dis-delay[2], 2)) / 2; Form1->Canvas->TextOut(32, alpha[2], "s"); last[2]=alpha[2]; } if (dis>delay[3]) { if (dis>delay[3]) { Form1->Canvas->Font->Color=clBtnFace; Form1->Canvas->TextOut(40, last[3], "i"); } Form1->Canvas->Font->Color=clBlack; alpha[3] = (a * pow(dis-delay[3], 2)) / 2; Form1->Canvas->TextOut(40, alpha[3], "i"); last[3]=alpha[3]; } if (dis>delay[4]) { if (dis>delay[4]) { Form1->Canvas->Font->Color=clBtnFace; Form1->Canvas->TextOut(47, last[4], "n"); } Form1->Canvas->Font->Color=clBlack; alpha[4] = (a * pow(dis-delay[4], 2)) / 2; Form1->Canvas->TextOut(47, alpha[4], "n"); last[4]=alpha[4]; } if (dis>delay[5]) { if (dis>delay[5]) { Form1->Canvas->Font->Color=clBtnFace; Form1->Canvas->TextOut(60, last[5], "t"); } Form1->Canvas->Font->Color=clBlack; alpha[5] = (a * pow(dis-delay[5], 2)) / 2; Form1->Canvas->TextOut(60, alpha[5], "t"); last[5]=alpha[5]; } if (dis>delay[6]) { if (dis>delay[6]) { Form1->Canvas->Font->Color=clBtnFace; Form1->Canvas->TextOut(68, last[6], "e"); } Form1->Canvas->Font->Color=clBlack; alpha[6] = (a * pow(dis-delay[6], 2)) / 2; Form1->Canvas->TextOut(68, alpha[6], "e"); last[6]=alpha[6]; } if (dis>delay[7]) { if (dis>delay[7]) { Form1->Canvas->Font->Color=clBtnFace; Form1->Canvas->TextOut(78, last[7], "g"); } Form1->Canvas->Font->Color=clBlack; alpha[7] = (a * pow(dis-delay[7], 2)) / 2; Form1->Canvas->TextOut(78, alpha[7], "g"); last[7]=alpha[7]; } if (dis>delay[8]) { if (dis>delay[8]) { Form1->Canvas->Font->Color=clBtnFace; Form1->Canvas->TextOut(90, last[8], "r"); } Form1->Canvas->Font->Color=clBlack; alpha[8] = (a * pow(dis-delay[8], 2)) / 2; Form1->Canvas->TextOut(90, alpha[8], "r"); last[8]=alpha[8]; } if (dis>delay[9]) { if (dis>delay[9]) { Form1->Canvas->Font->Color=clBtnFace; Form1->Canvas->TextOut(100, last[9], "ax"); } Form1->Canvas->Font->Color=clBlack; alpha[9] = (a * pow(dis-delay[9], 2)) / 2; Form1->Canvas->TextOut(100, alpha[9], "a"); last[9]=alpha[9]; } if (dis>delay[10]) { if (dis>delay[10]) { Form1->Canvas->Font->Color=clBtnFace; Form1->Canvas->TextOut(110, last[10], "t"); } Form1->Canvas->Font->Color=clBlack; alpha[10] = (a * pow(dis-delay[10], 2)) / 2; Form1->Canvas->TextOut(110, alpha[10], "t"); last[10]=alpha[10]; } if (dis>delay[11]) { if (dis>delay[11]) { Form1->Canvas->Font->Color=clBtnFace; Form1->Canvas->TextOut(118, last[11], "i"); } Form1->Canvas->Font->Color=clBlack; alpha[11] = (a * pow(dis-delay[11], 2)) / 2; Form1->Canvas->TextOut(118, alpha[11], "i"); last[11]=alpha[11]; } if (dis>delay[12]) { if (dis>delay[12]) { Form1->Canvas->Font->Color=clBtnFace; Form1->Canvas->TextOut(125, last[12], "o"); } Form1->Canvas->Font->Color=clBlack; alpha[12] = (a * pow(dis-delay[12], 2)) / 2; Form1->Canvas->TextOut(125, alpha[12], "o"); last[12]=alpha[12]; } if (dis>delay[13]) { if (dis>delay[13]) { Form1->Canvas->Font->Color=clBtnFace; Form1->Canvas->TextOut(136, last[13], "n"); } Form1->Canvas->Font->Color=clBlack; alpha[13] = (a * pow(dis-delay[13], 2)) / 2; Form1->Canvas->TextOut(136, alpha[13], "n"); last[13]=alpha[13]; } if (dis>=300) Form1->TimerDisintegration->Enabled=false; } //-------------------------------------------------------------- Clear Button //------------------------------------------------------------- Clears Screen void __fastcall TForm1::ButtonClearClick(TObject *Sender) { Refresh(); } //--------------------------------------------------------------- Down Button //--------------------------------------------------------- Starts Down Timer void __fastcall TForm1::ButtonDownClick(TObject *Sender) { Form1->TimerDown->Enabled=true; down=0; } //----------------------------------------------------------- Diagonal Button //----------------------------------------------------- Starts Diagonal Timer void __fastcall TForm1::ButtonDiagonallyClick(TObject *Sender) { diag=0; Form1->TimerDiagonally->Enabled=true; } //--------------------------------------------------------------- Both Button //-------------------------------------- Starts Both Diagonal and Down Timers void __fastcall TForm1::ButtonBothClick(TObject *Sender) { diag=0; Form1->TimerDiagonally->Enabled=true; down=0; Form1->TimerDown->Enabled=true; } //--------------------------------------------------------------- Drop Button //----------------------------------------------------- Starts FreeFall Timer void __fastcall TForm1::ButtonFreeFallClick(TObject *Sender) { freefall=0; Form1->TimerFreeFall->Enabled=true; } //----------------------------------------------------- Disintegration Button //----------------------------------------------- Starts Disintegration Timer void __fastcall TForm1::ButtonDisintegrationClick(TObject *Sender) { dis=0; // Sets the time before falling for each letter for (int i=0; i<14; i++) { alpha[i]=0; last[i]=0; delay[i]=start+random(50); } // Renders each letter of the text in its top position Form1->Canvas->Font->Color=clBlack; Form1->Canvas->TextOut(10, 0, "D"); Form1->Canvas->TextOut(25, 0, "i"); Form1->Canvas->TextOut(32, 0, "s"); Form1->Canvas->TextOut(40, 0, "i"); Form1->Canvas->TextOut(47, 0, "n"); Form1->Canvas->TextOut(60, 0, "t"); Form1->Canvas->TextOut(68, 0, "e"); Form1->Canvas->TextOut(78, 0, "g"); Form1->Canvas->TextOut(90, 0, "r"); Form1->Canvas->TextOut(100, 0, "a"); Form1->Canvas->TextOut(110, 0, "t"); Form1->Canvas->TextOut(118, 0, "i"); Form1->Canvas->TextOut(125, 0, "o"); Form1->Canvas->TextOut(136, 0, "n"); Form1->TimerDisintegration->Enabled=true; } //--------------------------------------------------------------------------- void __fastcall TForm1::ButtonStopClick(TObject *Sender) { TimerDown->Enabled=false; TimerDiagonally->Enabled=false; TimerFreeFall->Enabled=false; TimerDisintegration->Enabled=false; } //---------------------------------------------------------------------------