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.
Showing posts with label Free Pascal Tutorial Graphics Lakkaraju. Show all posts
Showing posts with label Free Pascal Tutorial Graphics Lakkaraju. Show all posts
Tuesday, December 8, 2009
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.
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.
Saturday, November 21, 2009
16. Basic Graphics in Free Pascal
Graphics is just painting on the screen, the screen has pixels in it and we put light on individual pixels. Each pixel on the screen has a position (x,y), where x and y are the x,y coordinates of the pixel. Top left corner is the lowest pixel coordinate (0,0) and the bottom right corner is the highest pixel coordinate (1023,711). We can activate any pixel in the screen with any color we want. If we light the pixels on the circle, we get a circle on the screen. Basically Graphics is lighting the right pixels on the screen.
In order to write a Graphics program in Pascal, we have to do three special steps.
First, we have to use graphical unit.
uses crt,graph;
Second, we have to initialize the graphical unit.
grdriver := DETECT;
initgraph(grdriver,grmode, ' ' );
Third, we have to give instructions to the graph unit to paint on the screen.
settextstyle(triplexfont,horizdir,2);
OutTextXY(50,30,'Graphics With Pascal');
In the following program I wrote, I experimented with basic shapes and colors. All the instructions for graphical pictures are in the procedure graphicpics. Study the program and do your own experiments.
Program program16;
{Author: Rao S Lakkaraju}
{* Basic Graphics Program *}
uses crt,graph;
var grmode, grdriver :integer;
x,y : integer;
Procedure graphicpics;
Begin
{Now give instructions to do graphics}
randomize;
settextstyle(triplexfont,horizdir,1);
for x := 1 to 200 do begin putpixel(49+x,500,(random(15))); end;
setcolor(Lightgreen);
settextstyle(triplexfont,horizdir,2);
OutTextXY(50,30,'Graphics With Pascal');
settextstyle(triplexfont,horizdir,1);
OutTextXY(50,300,'Screen Coordinates');
OutTextXY(50,350,'Top left corner (x,y): 0,0');
OutTextXY(50,400,'Bottom right corner (x,y): 1023,711 Pixels');
writeln('max x = ', getmaxx,' max y = ', getmaxy);
setfillstyle(1,red);
bar(100,100,250,250);
setfillstyle(2,green);
bar(0,0,23,19);
bar(1000,690,1023,711);
setcolor(red);
{line(x1,y1,x2,y2)}
line(0,0,0,23);
line(0,0,23,0);
for x := 1000 to 1023 do putpixel(x,711,red);
for y := 690 to 711 do putpixel(1023,y,red);
for x := 800 to 850 do putpixel(x,500,red);
for y := 450 to 500 do putpixel(850,y,red);
setcolor(cyan);
{rectangle(x1,y1,x2,y2);}
Rectangle(50,150,80,250);
{circle(x1,y1,radius); x1,y1 center of the circle}
circle(80,180,50);
{ellipse(x1,y1,degreesfrom,degrees to,hr,vr)}
ellipse(150,200,0,360,30,40);
{arc(x,y,p,q,radius)}
arc(180,250,0,90,60);
{pieslice(x,y,p,q,radius)}
pieslice(150,150,20,95,100);
End;
begin
{First we have to initialize the graphics mode}
clrscr;
grdriver := DETECT;
initgraph(grdriver,grmode, ' ' );
graphicpics;
Writeln('**** My Sixteenth Pascal Program ****');
readln;
CloseGraph;
end.
Summary: Graphics is simple painting on the screen. Pascal has all the basics of drawing geometric shapes(Line, Rectangle, Circle, Ellipse, Arc etc) using basic colors (red, white etc). Pleasing graphics is a combination of these basic shapes and a little imagination of placing them on the screen.
In order to write a Graphics program in Pascal, we have to do three special steps.
First, we have to use graphical unit.
uses crt,graph;
Second, we have to initialize the graphical unit.
grdriver := DETECT;
initgraph(grdriver,grmode, ' ' );
Third, we have to give instructions to the graph unit to paint on the screen.
settextstyle(triplexfont,horizdir,2);
OutTextXY(50,30,'Graphics With Pascal');
In the following program I wrote, I experimented with basic shapes and colors. All the instructions for graphical pictures are in the procedure graphicpics. Study the program and do your own experiments.
Program program16;
{Author: Rao S Lakkaraju}
{* Basic Graphics Program *}
uses crt,graph;
var grmode, grdriver :integer;
x,y : integer;
Procedure graphicpics;
Begin
{Now give instructions to do graphics}
randomize;
settextstyle(triplexfont,horizdir,1);
for x := 1 to 200 do begin putpixel(49+x,500,(random(15))); end;
setcolor(Lightgreen);
settextstyle(triplexfont,horizdir,2);
OutTextXY(50,30,'Graphics With Pascal');
settextstyle(triplexfont,horizdir,1);
OutTextXY(50,300,'Screen Coordinates');
OutTextXY(50,350,'Top left corner (x,y): 0,0');
OutTextXY(50,400,'Bottom right corner (x,y): 1023,711 Pixels');
writeln('max x = ', getmaxx,' max y = ', getmaxy);
setfillstyle(1,red);
bar(100,100,250,250);
setfillstyle(2,green);
bar(0,0,23,19);
bar(1000,690,1023,711);
setcolor(red);
{line(x1,y1,x2,y2)}
line(0,0,0,23);
line(0,0,23,0);
for x := 1000 to 1023 do putpixel(x,711,red);
for y := 690 to 711 do putpixel(1023,y,red);
for x := 800 to 850 do putpixel(x,500,red);
for y := 450 to 500 do putpixel(850,y,red);
setcolor(cyan);
{rectangle(x1,y1,x2,y2);}
Rectangle(50,150,80,250);
{circle(x1,y1,radius); x1,y1 center of the circle}
circle(80,180,50);
{ellipse(x1,y1,degreesfrom,degrees to,hr,vr)}
ellipse(150,200,0,360,30,40);
{arc(x,y,p,q,radius)}
arc(180,250,0,90,60);
{pieslice(x,y,p,q,radius)}
pieslice(150,150,20,95,100);
End;
begin
{First we have to initialize the graphics mode}
clrscr;
grdriver := DETECT;
initgraph(grdriver,grmode, ' ' );
graphicpics;
Writeln('**** My Sixteenth Pascal Program ****');
readln;
CloseGraph;
end.
Summary: Graphics is simple painting on the screen. Pascal has all the basics of drawing geometric shapes(Line, Rectangle, Circle, Ellipse, Arc etc) using basic colors (red, white etc). Pleasing graphics is a combination of these basic shapes and a little imagination of placing them on the screen.
Subscribe to:
Posts (Atom)