Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 13th, 2012  |  syntax: Pascal  |  size: 1.82 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. uses crt, graph, sysutils;
  2.  
  3. const N = 10;
  4.  
  5. var
  6. ster, tryb, k, i, j, p, x, q: integer;
  7. d : array[1..N] of integer;
  8. s, t: string;
  9.  
  10. procedure heart(x, y: integer);
  11.         begin
  12.                 line(x-50, y-20, x, y+35);
  13.                 line(x, y+35, x+50, y-20);
  14.                 arc(x-25, y-20, 0,180, 25);
  15.                 arc(x+25, y-20, 0,180, 25);
  16.             SetFillStyle ( SolidFill, 4 );
  17.                 floodfill( x, y, 4);
  18.         end;
  19.  
  20. begin
  21. detectgraph(ster,tryb);
  22. initgraph(ster,tryb, 'C:\tp\bgi');
  23.  
  24. randomize;
  25.   for i := 1 to N do d[i] := random(100);
  26.  
  27. setbkcolor(darkgray);
  28. SetTextStyle ( 1, HorizDir, 2 );
  29.  
  30. k:=0;  
  31.   for j := N - 1 downto 1 do
  32.   begin
  33.     p := 1;
  34.     for i := 1 to j do
  35.       if d[i] > d[i+1] then
  36.       begin
  37.         x := d[i]; d[i] := d[i+1]; d[i+1] := x;
  38.         p := 0;    
  39.                 k:= k+1;
  40.                 s:= 'krok ' + inttostr(k);
  41.                 t:= 'Sortowanie babelkowe!';
  42.                 cleardevice();
  43.                 outtextxy( (getmaxx-TextWidth(s)) div 2, 80, s);
  44.                 outtextxy( (getmaxx-TextWidth(t)) div 2, 120, t);
  45.                         for q:=1 to N do       
  46.                                 begin
  47.                                         outtextxy( ( (getmaxx - textwidth( inttostr(d[q]) ) ) div (N+1)) * q, ( 400 - textheight( inttostr(d[q]) ) ), inttostr(d[q]) );
  48.                                 end;
  49.                 setcolor(red);
  50.                 heart(( getmaxx div (n+1)) * i, 400);
  51.                 heart((getmaxx div (n+1)) * (i+1), 400);
  52.                
  53.                 {outtextxy( ( (getmaxx - textwidth( inttostr(d[q]) ) ) div (N+1)) * q, ( 400 - textheight( inttostr(d[q]) ) ), inttostr(d[q]) );}
  54.                 delay(500);
  55.       end;
  56.     if p = 1 then break;
  57.   end;
  58.  
  59. cleardevice();
  60. outtextxy( (getmaxx-TextWidth(s)) div 2, 80, s);
  61. outtextxy( (getmaxx-TextWidth(t)) div 2, 120, t);
  62.  
  63. for q:=1 to N do       
  64.                                 begin
  65.                                 outtextxy( ( (getmaxx - textwidth( inttostr(d[q]) ) ) div (N+1)) * q, ( 400 - textheight( inttostr(d[q]) ) ), inttostr(d[q]) );
  66.                                 end;
  67.                                
  68. setcolor(lightgreen);
  69. s:='Well done!';
  70. outtextxy( (getmaxx-textwidth(s)) div 2, 600, s );
  71.  
  72. delay(5000);
  73.  
  74. CloseGraph;
  75.  
  76. end.