Previous: PutImage procedure To the Table of Content Next: PutSprite procedure

- 4.37.2.87 -
Standard Units
Graph Unit
Graph Unit Procedures and Functions

PutPixel procedure

Targets: MS-DOS, Win32


This procedure plots a pixel at (X,Y).

Declaration:
  procedure PutPixel(X, Y: Longint; Pixel: DWORD);
  procedure PutPixel(X, Y: Longint);
Return Value: None

Typical Usage:
  PutPixel(100, 200, 3);
  PutPixel(myX, myY);
Remarks:
Plots a point with the color defined by Pixel parameter at the point with (X, Y) coordinates.

Sample Code:
{ PutPixel Sample program                                  }
{ Written by Alligator especially for TMT Development Corp.}
Program Top_Art;
Uses Graph,Crt;
Const
  NumberOfPixels=1000; { Number of pixels to draw }
Type
  Pixels=record        { Coordinates and color for a pixel }
    x,y: Integer;
    Colours:Integer;
  end;
var
  { Here we will store colors and coordinates for our pixels}
  SomePixels: array [1..NumberOfPixels] of Pixels;
  {Pixel coordinates increments}
  dx,dy:Integer;
  {A loop variable}
  i:Integer;
begin
  { Initialize the random numbers generator }
  Randomize;
  { Set Hicolor graphics mode }
  SetSVGAMode(320,200,16,LfbOrBanked);
  { Clears the current active page using the background color}
  ClearPage;
  {Set random initial color and coordinates for each pixel }
  for i:=1 to NumberOfPixels do
    begin
      SomePixels[i].x:=Random(GetMaxX);           {Set the random X    }
      SomePixels[i].y:=Random(GetMaxY);           {Set the random Y    }
      SomePixels[i].Colours:=Random(GetMaxColor); {Set the random color}
    end;
  While not keypressed do
    begin
    for i:=1 to NumberOfPixels do
      begin
        { Increment the pixel coordinates }
        dy:=Random(2)*2-1; {Either 1, or-1}
        dx:=Random(2)*2-1;
        { Change the pixel coordinates with dx, dy }
        SomePixels[i].x:=SomePixels[i].x+dx;
        SomePixels[i].y:=SomePixels[i].y+dy;
        { Draw the pixel }
        PutPixel(SomePixels[i].x,SomePixels[i].y,SomePixels[i].Colours);
      end;
    end;
  CloseGraph; { Return to the text mode }
  ReadKey;    { Get the key pressed     }
end.



Previous: PutImage procedure To the Table of Content Next: PutSprite procedure
PutImage procedure Table of Content PutSprite procedure

- 4.37.2.87 -