Tuesday, December 8, 2009

18. More Graphics with Free Pascal

The following program generates circles and ellipses. By using random numbers for colors and delayed activation of pixels on the screen, I tried to paint a pleasing picture. The static(standard) graphics commands are in the main program and the variable calls for activating pixels(pictures) are in the createcircles procedure. The program follows:

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

Var GraphicsDriver, GraphicsMode,
n,radius,radius1,radius3 : Integer;
ax,ay,ar : integer;

Procedure Createcircles;
Begin
Outtextxy(120,30,'My Beautiful Painting');

setcolor(red);
setfillstyle(1,red);
rectangle(75,120,510,570);
radius1 := 0;
ax := getmaxx div 2;
ay := getmaxy div 2;


for radius := 50 to 100 do begin

SetColor(Random(14) + 1);
radius1 := radius ;
ar := radius div 2;
Outtextxy(120,30,'My Beautiful Painting');

{Left Side}
rectangle(10+ar,70+ar,200+ax-ar,290+ay-ar);
circle(ax-280, ay, radius1);
circle(ax-280, ay, radius1-49);
circle(ax-280, ay, radius1+55);
ellipse(ax-280, 420+radius1, 0,360,150,40);
ellipse(ax-280, 120+radius1, 0,360,150,40);

{ellipse(x1,y1,degreesfrom,degrees to,hr,vr)}
{ Right Side}

circle(ax, ay, radius1);
circle(ax , ay - radius1- ar, ar );
circle(ax , ay + radius1+ ar, ar );
ellipse(430, 220+radius1, 0,360,60,60);
ellipse(430+150, 220+radius1, 0,360,60,60);
ellipse(430, 220+2*radius1+30, 0,360,60,40);
ellipse(430+150, 220+2*radius1+30, 0,360,60,40);
delay(300 );

end;
End;

Begin
ClrScr;
Writeln('Graphics Initialization');
GraphicsDriver := Detect;
InitGraph(GraphicsDriver, GraphicsMode,'');
ClearViewPort;
Randomize;
SetColor(cyan);
settextstyle(triplexfont,horizdir,2);
for n:= 1 to 1 do begin

ClearViewPort;
createcircles; delay(300); end;

SetColor(cyan);
settextstyle(triplexfont,horizdir,1);
OutTextXY(135,70,'Is It not Wonderful ????');
OutTextXY(580,580,'lakkaraju');
Readln;
CloseGraph;

End.

Summary: Graphics is activation of pixels on the screen. Simply sketch it on paper . transform into rectangles, circles and ellipses with proper coordinates and colors. Now vary some of the coordinates and colors; A beautiful picture comes out in real time, as you imagined.