1 Chương trình tạo một chiếc đồng hồ Gimico trên màn hình máy tính dùng Pascal.
uses crt,graph,dos;
var x,y,x1,y1,x2,y2,goc: integer; goc1,goc2,goc3,old,gd,gm:integer;
gio,phut,giay,mili:word; so,gio1,phut1,giay1:string; rad:real;
procedure kim_giay(goc:integer);
begin rad:=goc*pi/180; x1:=round(x+150*sin(rad));
y1:=round(y-150*cos(rad)); setlinestyle(0,0,1); line(x,y,x1,y1);
if (goc mod 6=0) then
begin sound(3000);delay(10);nosound; end;
end;
procedure kim_phut(goc1:integer);
begin rad:=goc1*pi/180; x1:=round(x+150*sin(rad));
y1:=round(y-150*cos(rad)); setlinestyle(0,0,3); line(x,y,x1,y1);
end;
procedure kim_gio(goc2:integer);
begin rad:=goc2*pi/180;
x1:=round(x+100*sin(rad)); y1:=round(y-100*cos(rad));
setlinestyle(1,1,10); line(x,y,x1,y1);
end;
Begin gd:=detect; initgraph(gd,gm,”);
(* ——– Ve 3 vong tron ——- *)
setcolor(10); setbkcolor(white); x:=getmaxx div 2; y:=getmaxy div 2;
setfillstyle(1,10); setcolor(4);
circle(x,y,210); circle(x,y,170); circle(x,y,5); floodfill(x,y,4);
setfillstyle(2,14); floodfill(x+11,y+11,4);
setfillstyle(1,blue); floodfill(x+88,y+158,4);
(* ——- Ve so tren mat dong ho ——— *)
setcolor(12); settextstyle(0,0,2);
outtextxy(x-18,y-197,’12′); outtextxy(x+183,y-5,’3′);
outtextxy(x-196,y-5,’9′); outtextxy(x-10,y+183,’6′);
outtextxy(x+160,y-98,’2′); outtextxy(x-180,y-98,’10′);
outtextxy(x+89,y-170,’1′); outtextxy(x-114,y-170,’11′);
outtextxy(x+160,y+88,’4′); outtextxy(x-172,y+88,’8′);
outtextxy(x+88,y+158,’5′); outtextxy(x-110,y+154,’7′);
(* ——– Ke mac dong ho ——– *)
setcolor(12); settextstyle(0,0,1); outtextxy(x-20,y+120,’VIETNAM’);
(* —– Ve 3 kim dong ho ——- *)
setwritemode(xorput); goc:=0; goc1:=0; goc2:=0;
gettime(gio,phut,giay,mili); goc:=giay*6; old:=giay;
kim_giay(goc); goc1:=phut*6+ giay div 10; kim_phut(goc1);
goc2:=gio*30+phut div 2; kim_gio(goc2);
(* ——– Cho dong ho chay ———– *)
repeat gettime(gio,phut,giay,mili);
if giay<>old then
begin kim_giay(goc); goc:=giay*6; kim_giay(goc); old:=giay;
if phut*6+giay div 10 <>phut then
begin kim_phut(goc1); goc1:=phut*6+giay div 10;
kim_phut(goc1); kim_gio(goc2);
goc2:=gio*30+phut div 2; kim_gio(goc2);
end;
end;
until keypressed;
closegraph;
end
Trang 22 Chương trình viết bằng Pascal tạo các chùm pháo hoa nhân dịp năm mới.
uses crt,graph;
var gd,gm,i,j:integer;s,r,s1,r1,l:real;
h,t,x,y:array[1 40] of integer;
x0,y0,mau:array[1 8] of integer;
procedure sao(mau:word;x1,y1:integer;s:real);
var i:integer;d:real;
begin
d:=s*cos(2*pi/5)/cos(pi/5);
for i:=1 to 5 do
begin
x[i]:=x1+round(s*sin((i-1)*2*pi/5));
y[i]:=y1-round(s*cos((i-1)*2*pi/5));
end;
for i:=1 to 5 do
begin
x[i+5]:=x1+round(d*sin(pi/5+(i-1)*2*pi/5));
y[i+5]:=y1-round(d*cos(pi/5+(i-1)*2*pi/5));
end;
setcolor(mau);
for i:=1 to 5 do line(x[i],y[i],x[i+5],y[i+5]);
for i:=2 to 5 do line(x[i],y[i],x[i+4],y[i+4]);
line(x[10],y[10],x[1],y[1]);
setfillstyle(1,mau);
floodfill(x1,y1,mau);
end;
procedure phaohoa1(mau:word;x0,y0:integer);
var n:integer;
begin
r:=0;s:=2;l:=0;
repeat
for i:=1 to 40 do
begin
h[i]:=round(r*sin(i*pi/20));
t[i]:=round(r*cos(i*pi/20));
x[i]:=x0+h[i];
y[i]:=y0-t[i];
sao(mau,x[i],y[i],s);
end;
setcolor(red);
settextstyle(0,0,5);
outtextxy(50,460,’Happy New Year’);
settextjustify(0,0);
delay(5);
r:=r+4+l;
l:=l+0.1;
s:=s+0.05;
until r= 246;
delay(1000); n:=0;
repeat r1:=246-r;s1:=4-s;
for i:=1 to 40 do begin
h[i]:=round(r1*sin(i*pi/20));
t[i]:=round(r1*cos(i*pi/20));
x[i]:=x0+200+h[i];
y[i]:=y0+100-t[i];
sao(mau+1,x[i],y[i],s1);
h[i]:=round(r*sin(i*pi/20));
t[i]:=round(r*cos(i*pi/20));
x[i]:=x0+h[i];
y[i]:=y0-t[i];
sao(black,x[i],y[i],s);
end;
inc(n);
setcolor(red);
settextstyle(0,0,5);
outtextxy(50,460,’Happy New Year’); settextjustify(0,0);
delay(50);
l:=l-0.1;
r:=r-4-l;
s:=s-0.05;
until n=42;
end;
begin randomize;
gd:=detect;initgraph(gd,gm,”);
for j:=1 to 8 do begin
mau[j]:=random(15)+1;
x0[j]:=random(540);
y0[j]:=random(480);
phaohoa1(mau[j],x0[j],y0[j]);
end;
readln;
closegraph;
end