ALGORITMA PEMBENTUK BINTANG

Posted: February 28, 2011 in Pascal

uses graph,crt;
procedure init();
var gd, gm : integer;
begin
gm:=detect; gd:=0;
InitGraph(gd,gm,”);
if GraphResult <> grOk then
begin
Writeln(‘Graph driver ‘,gd,’ graph mode ‘,gm,’ not supported’);
Halt(1);
end;
end;
procedure destroy();
begin
closegraph;
end;
procedure drawLine(xstart,ystart,xend,yend,c:integer);
var
step,k:integer;
dx,dy:real;
x_inc,y_inc,x,y:real;
begin
if(xstart <> xend) or (ystart <> yend) then
begin
dx:=xend-xstart;
dy:=yend-ystart;
x:=xstart;
y:=ystart;
if abs(dx) > abs(dy) then
step:=round(abs(dx))
else
step:=round(abs(dy));
x_inc:=dx/step;
y_inc:=dy/step;
putPixel(round(x),round(y),c);
for k:=1 to step do
begin
x:=x+x_inc;
y:=y+y_inc;
putPixel(round(x),round(y),c);
end;
end;
end;
begin
init;
drawLine(100,50,112,88,white);
drawLine(112,88,150,88,blue);
drawLine(150,88,119,112,yellow);
drawLine(119,112,131,150,red);
drawLine(131,150,100,126,green);
drawLine(100,126,69,150,green);
drawLine(69,150,81,112,red);
drawLine(81,112,50,88,yellow);
drawLine(50,88,88,88,blue);
drawLine(88,88,100,50,white);
readkey;
destroy;
end.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s