Random Colored Lines

DeFrog777 0 Tallied Votes 198 Views Share

This simple program will draw several randomly sized and colored lines on the screen. Makes a good screensaver!

Program RandColorLines;

Uses Crt, Graph;

Var GraphDriver, GraphMode: Integer;
      X, Y: Integer;

Begin
   GraphDriver := Detect; {This automatically detects the GraphicsDriver}
   InitGraph(GraphDriver, GraphMode, ' ');  
   {The ' ' is where the BGI file is stored on your Harddrive}
   {For me it is 'C:\TP\BGI'}
   X := GetMaxX;
   Y := GetMaxY;
   Randomize;  {This Enables the Random feature}

  While Not Keypressed Do
  Begin
      Delay(20);  {Delays drawing of a line to once every 20 milliseconds}
      SetColor(1 + Random(GetMaxColor));
      Line(Random(X), Random(Y), Random(X), Random(Y));
   End;

   Repeat Until Keypressed;
   Closegraph
End.
Dani 4,329 The Queen of DaniWeb Administrator Featured Poster Premium Member

Thank you for submitting DaniWeb's first pascal code snippet :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.