{$N+} uses crt, graph; var x1, x2, y1, y2, r,x_, y_, x__, y__, bgC, speed1, speed2: integer; Gd, Gm : integer; choise : integer; h, t, i : integer; angle1, angle2 : single; c, q : char; s : string; procedure draw (x, y, r, c : integer); begin setfillstyle(solidfill, c); fillellipse(x, y, r, r); Setcolor (c); circle (x, y, r); end; procedure escape (x, y, r, bgC : integer); begin setfillstyle(solidfill, bgC); fillellipse(x, y, r, r); Setcolor (bgC); circle (x, y, r); end; procedure move (var x, y: integer; angle : single; speed : integer); begin x := round(x + speed*cos(angle)); y := round(y + speed*sin(angle)); end; function angleX (angle : single):single; begin angleX := (pi - angle); end; function angleY (angle : single): single; begin angleY := -angle; end; Procedure border1 (var x1, y1 : integer; r1: integer{; speed: integer{; angle : single}); begin if (x1 + r1 >= GetMaxX-1) or (x1 - r1 <= 1) then angle1 := angleX(angle1); if (y1 + r1 >= GetMaxY-1) or (y1 - r1 <= 1) then angle1 := angleY(angle1); end; Procedure border2 (var x2, y2 : integer; r2: integer{; speed: integer{; angle : single}); begin if (x2 + r2 >= GetMaxX-1) or (x2 - r2 <= 1) then angle2 := angleX(angle2); if (y2 + r2 >= GetMaxY-1) or (y2 - r2 <= 1) then angle2 := angleY(angle2); end; function value(const r: integer):real; begin value := 4/3*pi*r*r*r; end; procedure after_hit (var speed1, speed2 : integer; var angle1, angle2 : single); var m1, m2 : real; Vx1, Vy1, Vx2, Vy2 : real; t1, t2, t3, t4, t5, t6, t7, t8, t9, t10 : real; begin m1 := value(r); m2 := value(r); Vx1 := speed1*cos(angle1); Vy1 := speed1*sin(angle1); Vx2 := speed2*cos(angle2); Vy2 := speed2*sin(angle2); t1 := m2/(m1*(m2 + m1)); t2 := (Vx1 - Vx2); t3 := (m1*m1*m2 - m1); Vx1 := Vx1 + t1*t2*t3; t4 := (Vy1 - Vy2); Vy1 := Vy1 + t1*t4*t3; t5 := Vx1*m1 + m2*Vx2; t6 := m1*m1*Vx1; t7 := m1*m1*m2*Vx2; vx2 := (t5 - t6 + t7)/(m2 + m1); t8 := Vy1*m1 + m2*Vy2; t9 := m1*m1*Vy1; t10 := m1*m1*m2*Vy2; vy2 := (t8 - t9 + t10)/(m2 + m1); speed1 := round(sqrt(Vx1*Vx1 + Vy1*Vy1)); Angle1 := Arctan(Vy1/Vx1); if abs(Vx1) < 1e - 5 then begin Angle1 := pi/2; if Vy1 < 0 then Angle1 := - angle1 end else begin Angle1 := ArcTan(Vy1/Vx1); if Vx1 < 0 then Angle1 := - angle1 end; speed2 := round(sqrt(Vx2*Vx2 + Vy2*Vy2)); Angle2 := Arctan(Vy2/Vx2); if abs(Vx2) < 1e - 5 then begin Angle2 := pi/2; if Vy2 < 0 then Angle2 := - angle2 end else begin Angle2 := ArcTan(Vy2/Vx2); if Vx2 < 0 then Angle2 := - angle2 end; end; function balls_hit (const r1,r2 : integer; x1,y1,x2,y2 : integer) : boolean; var dist : real; t1, t2, t3, t4, t5: real; begin t1 := abs(x2-x1); t2 := sqr(t1); t3 := abs(y2-y1); t4 := sqr(t3); t5 := t2 + t4; dist := sqrt(t5); balls_hit := (dist < (r1 + r2)); end; procedure balls_hit_2; begin if balls_hit(r,r,x1,y1,x2,y2) then after_hit (speed1, speed2,angle1,angle2); end; function Menu(Params: string): integer; var Count: integer; Strings: array [0 .. 15] of string [127]; i: integer; Ch: char; X, Y, H: integer; begin Count := 1; Strings[0] := ''; for i := 1 to Length(Params) do begin if Params[i] = #13 then begin Inc(Count); Strings[Count - 1] := ''; end else begin Strings[Count - 1] := Strings[Count - 1] + Params[i]; end; end; SetTextJustify(CenterText, CenterText); H := TextHeight('A') + 10; ClearDevice; SetColor(7); for i := 0 to Count - 1 do OutTextXY( GetMaxX div 2, GetMaxY div 2 - (Count - 1) * H div 2 - H div 4 + i * H, Strings[i] ); i := 0; repeat SetColor(LightMagenta); X := TextWidth(Strings[i]) + 10; Y := TextHeight(Strings[i]) + 10; Rectangle(GetMaxX div 2 - X div 2, GetMaxY div 2 - (Count - 1) * H div 2 + i * H - Y div 2, GetMaxX div 2 + X div 2, GetMaxY div 2 - (Count - 1) * H div 2 + i * H + Y div 2); ch := readkey; SetColor(BLACK); X := TextWidth(Strings[i]) + 10; Y := TextHeight(Strings[i]) + 10; Rectangle(GetMaxX div 2 - X div 2, GetMaxY div 2 - (Count - 1) * H div 2 + i * H - Y div 2, GetMaxX div 2 + X div 2, GetMaxY div 2 - (Count - 1) * H div 2 + i * H + Y div 2); case ch of #0: case ReadKey of #72: begin Dec(i); if i < 0 then i := Count - 1; end; #80: begin Inc(i); if i >= Count then i := 0; end; end; end; until ch = #13; Menu := i; end; procedure MENU1(x_,y_,x__,y__:integer;s:string;c:word); begin SetColor(c); RecTangle(x_,y_,x__,y__); SetColor(White); OutTextXY(round(x_+(x__-x_-TextWidth(s))/2),round(y_+(y__-y_)/2),s); end; procedure _case_(var x_,y_,x__,y__:integer;var q:char;var r:integer); var s:string; begin case q of '1':begin {Menu1(x_,y_,x__,y__,s,white);} x_:=200; y_:=150; x__:=300; y__:=200; s:='R=15'; Menu1(x_,y_,x__,y__,s,13); r:=15; end; '2':begin { Menu1(x_,y_,x__,y__,s,white); } x_:=350; y_:=150; x__:=450; y__:=200; s:='R=25'; Menu1(x_,y_,x__,y__,s,13); r:=25; end; end; end; begin Gd := Detect; InitGraph (Gd, Gm, ''); If GraphResult <> grOk then halt(1); repeat settextStyle(4,0,6); Choise := Menu ('INFO'#13'Ypravlenie'#13'Moving Balls'#13'Exit'); case Choise of 0 : begin cleardevice; setcolor(7); settextstyle(4,0,3); settextjustify ( CenterText, CenterText); h := Textheight('A') + 10; outTextxY(getmaxx div 2, getmaxy div 4 - h, 'Kursovay rabota:'); SetColor(13); outTextxY ( getmaxx div 2, getmaxy div 4 + h, '"M O V I N G C I R C L E S"'); SetColor (7); outtextxy( getmaxx div 2, getmaxy div 4 + 2*h, 'Podgotovila:'); outtextxy ( getmaxx div 2, getmaxy div 4 + 3*h, 'Stydentka gr. ** - 11'); outtextxy(getmaxx div 2, getmaxy div 4 + h*4, '******** Marina'); outtextxy( getmaxx div 2, getmaxy div 4 + 6*h, 'Thanks for attention!'); end; 1: begin cleardevice; setcolor (7); settextstyle(4,0,3); h := textheight('A') + 10; setColor (13); outTextXY(getmaxx div 2, getmaxy div 4 + 6*h, 'Exit in main menu: Enter;' ); outTextXY(getmaxx div 2, getmaxy div 4 + 7*h, 'Exit iz MOVING CIRCLES: Esc -> Enter;' ); outTextxY(getmaxx div 2, getmaxy div 4 - h, 'Your moshete regylirovati skorosti shariv:'); SetColor(7); outtextxy(getmaxx div 2 - 150, getmaxy div 4 + h, 'Pink Circle:'); outTextXY(getmaxx div 2 - 150, getmaxy div 4 + 2*h, 'Yveli4enie skorosti : ->'); outTextXY(getmaxx div 2 - 150, getmaxy div 4 + 3*h, 'Ymenshenie skorosti : <-'); outtextxy(getmaxx div 2+ 170, getmaxy div 4 + h, 'White Circle:'); outtextxy(getmaxx div 2+ 170, getmaxy div 4 + 2*h, 'Yveli4enie skorosti: +'); outtextxy(getmaxx div 2+ 170, getmaxy div 4 + 3*h, 'Ymenshenie skorosti: -'); end; 2: begin cleardevice; randomize; x1 := 50; y1 := 200; x_ := 170; y_ := 200; x2 := 400; y2 := 300; x__ := 300; y__ := 250; {r1 := 40; r2 := 40;} SetTextStyle (4, 0, 3); h := textheight('A') + 10; settextjustify ( CenterText, CenterText); Menu1(x_,y_,x__,y__,'R=15',13); Menu1(x_+150,y_,x__+150,y__,'R=25',13); outtextxY(x_-10, y_-20, '1:'); outtextxY(x_+140, y_-20, '2:'); OutTextXy (getmaxx div 2, getmaxy div 4 - h, 'Zadaite radiys nashatiem nyshogo 4isla:' ); {if KeyPressed then begin } q:=readkey; _case_(x_,y_,x__,y__, q, r); if (q <> '1') and (q <>'2') then begin t := 5; ClearDevice; SeTTextStyle(4, 0, 6); settextjustify ( CenterText, CenterText); while (GetMaxY div 2 - t) > 0 do begin for i := 0 to 15 do begin SetColor (i mod 13); OutTextXY (getMaxX div 2, getMaxY div 2 - t, 'ERROR!'); Delay (40000); Cleardevice; t := t + 5; end; end; setColor(7); OutTextXY (getMaxX div 2, getMaxY div 2 + 30, 'Press any key for Exit!'); readkey; halt (1); end; {begin}cleardevice; speed1 := 6; speed2 := 4; angle1 := random(628)/100; angle2 := random(628)/200; bgC := 0; Setcolor(0); rectangle (1,1, getMaxX - 1, getMaxY - 1); repeat begin draw (x1, y1, r, 7); draw (x2, y2, r, 13 ); delay(15100); escape (x1, y1, r, bgC); escape (x2, y2, r, bgC); move (x1, y1, angle1, speed1); move (x2, y2, angle2, speed2); border1 (x1, y1, r); border2 (x2, y2, r); balls_hit_2; end; if keypressed then begin c := readkey; if c = '+' then begin inc(speed1); if speed1 >= 60 then speed1 := 60; end; if c = '-' then begin dec(speed1); if speed1 <= 1 then speed1 := 1; end; if c = #77 then begin inc(speed2); if speed2 >= 50 then speed2 := 50; end; if c = #75 then begin dec(speed2); if speed2 <= 5 then speed2 := 5; end; end; until c = #27; end; {end;} 3 : begin clearDevice; SetTExtStyle(4, 0, 7); SetColor(13); while (GetMaxY div 2 - t) > 0 do begin for i := 0 to 15 do begin SetColor (i mod 13); OutTextXY (getMaxX div 2, getMaxY div 2 - t, 'Bye, Bye!'); Delay (40000); Cleardevice; t := t + 5; end; end; readkey; halt (1); end; end; readkey; until Choise = 3; readkey; closegraph; end.