Random Colored Pixels

DeFrog777 0 Tallied Votes 320 Views Share

This is Similar to the Previous Snippet, but it puts indivdual pixels of different colors randomly on the screen. Also makes a nice screensaver!

Progam RandColorPixel;

Uses Crt, Graph;

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

Begin
   GraphDriver := Detect;  {Automatically Detects Graphics Driver}
   InitGraph(GraphDriver, GraphMode, ' ');  {The ' ' is where the BGI Folder is on your HardDrive, for me it is 'C:\TP\BGI'}
   X := GetMaxX;
   Y := GetMaxY;
   Randomize;

   While Not Keypressed Do
   Begin
      Delay(20);  {Delays drawing to once every 20 milliseconds}
      SetColor(1 + Random(GetMaxColor));
      PutPixel(Random(X), Random(Y), 10); {For Some Reason, Pascal wants a third value, I'm not sure why...}
   End;
   
   Repeat Until Keypressed
   CloseGraph;
End.
Dani 4,329 The Queen of DaniWeb Administrator Featured Poster Premium Member

I thought I had De Ja Vu for a second with the same snippet posted twice ... but then I read and saw it's slightly different.

I've no experience with Pascal. Where could I pick myself up a Pascal compiler to test this out?

another guest -17 Junior Poster in Training

kewlness :D....needed a bit of modifying to get it working thou

yvesli 0 Newbie Poster

really basic.

Pascal's third value is the colour for the pixel...

btw, to change an exe to windows screensaver format, just change the .exe to .scr . Then put it into your [main hard drive, usually C]\WINDOWS directory to make it available in Properties (Personalization->Screensaver on Vista).

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.