Tuesday, November 24, 2009

17. Free Pascal Graphics

In the previous post we learned the fundamentals of graphics and were able to do basic painting on the screen. In this post we use the same instructions to create circles etc. and use delay and loops to create visual effects. Study the program17 and play with it.

There are two procedures in the program. First procedure createcircles creates circles etc. The second procedure destroycircle destroys the created circle and also creates more visuals while destroying the circle.

The main program is just initiating graphics, declaring variables, calling the procedures and closing the Graphical unit.

Study the two procedures and play with them and enjoy creating your own paintings. Use delay and variation of pixel coordinates for visual effects.

Always remember Graphics is just activation of pixels on the screen. Screen is your canvas and use your imagination and mathematical formulae for timing the activation and deactivation of pixels.

Program program17;
{Author: Rao S Lakkaraju}
{Graphics with Pascal}
Uses Crt,Graph;

Var GraphicsDriver, GraphicsMode,
x,y,radius,radius1,radius3 : Integer;

Procedure Createcircles;
Begin
setcolor(yellow);
rectangle(100,120,510,570);
radius1 := 0;
Outtextxy(20,40,' Creating Circles');

For radius := 1 to 200 do
Begin
while radius1 <> radius then begin SetColor(black); {Set text colour}
Circle(GetMaxX Div 2, GetMaxY Div 2, Radius3);
radius3 := radius - 5;
SetColor(Random(15) + 1);
Circle(100,200, Radius3 div 2);
{ellipse(x1,y1,degreesfrom,degrees to,hr,vr)}
ellipse(250,330 + radius3 ,0,360,80,40);
pieslice(370,570,20,80,radius3 div 2+40);
Delay(905 );
setfillstyle(1,red);
bar(240,570,260, radius3 + 300 );
{pieslice(x,y,p,q,radius)}
pieslice(430,200,20,80,radius3 div 2+40);
end; end;
End;


Begin
ClrScr;
Writeln('Graphics Initialization');
GraphicsDriver := Detect;
InitGraph(GraphicsDriver, GraphicsMode,'');
ClearViewPort;
Randomize;
SetColor(cyan);
settextstyle(triplexfont,horizdir,2);
OutTextXY(20,20,'Welcome to the Disappearing Circle');


createcircles;
destroycircle;

SetColor(cyan);
OutTextXY(20,80,' I am done');
Readln;
CloseGraph;

End.

SUMMARY: Graphics is just activating the pixels on the screen. We can use delay, color and timing in activating the pixels to give visual effects. Your paint brush is your program, control the paint brush movements and you get an excellent pictures on the screen.

No comments:

Post a Comment