PROGRAM chap4;
USES CRT, SDL;
VAR
screen:pSDL_SURFACE;
pixellocation:^LONGWORD;
pixelcolor,i:LONGWORD;
BEGIN
SDL_INIT(SDL_INIT_VIDEO);
screen:=SDL_SETVIDEOMODE(200,200,32,SDL_SWSURFACE);
IF screen=NIL THEN HALT;
NEW(pixellocation);
WRITE('Pitch value: ',screen^.pitch DIV screen^.format^.BytesPerPixel);
i:=0;
REPEAT
inc(i); IF i>39999 THEN i:=0;
pixellocation:=screen^.pixels+i; //delete old pixel
pixelcolor:=SDL_MAPRGB(screen^.format,0,0,0);
pixellocation^:=pixelcolor;
pixellocation:=screen^.pixels+i+1; //draw new pixel
pixelcolor:=SDL_MAPRGB(screen^.format,255,255,0);
pixellocation^:=pixelcolor;
SDL_FLIP(screen);
SDL_DELAY(5);
UNTIL keypressed;
DISPOSE(pixellocation);
SDL_FREESURFACE(screen);
SDL_QUIT;
END.
|
PROGRAM chap4; USES CRT, SDL; VAR screen:pSDL_SURFACE; pixellocation:^LONGWORD; pixelcolor,i:LONGWORD; BEGIN SDL_INIT(SDL_INIT_VIDEO); screen:=SDL_SETVIDEOMODE(200,200,32,SDL_SWSURFACE); IF screen=NIL THEN HALT; |
NEW(pixellocation);
WRITE('Pitch value: ',screen^.pitch DIV screen^.format^.BytesPerPixel);
i:=0;
REPEAT
inc(i); IF i>39999 THEN i:=0;
|
pixellocation:=screen^.pixels+i; //delete old pixel pixelcolor:=SDL_MAPRGB(screen^.format,0,0,0); pixellocation^:=pixelcolor; |

pixellocation:=screen^.pixels+i+1; //draw new pixel pixelcolor:=SDL_MAPRGB(screen^.format,255,255,0); pixellocation^:=pixelcolor; |
SDL_FLIP(screen); SDL_DELAY(5); UNTIL keypressed; DISPOSE(pixellocation); SDL_FREESURFACE(screen); SDL_QUIT; END. |
![]() |
The final result should look and behave like this: You have to look quite carefully to recognize a single yellow pixel moving from the left top corner, line by line down until it reaches the right bottom corner. |