CELLS.PAS 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. Uses Graph,CRT;
  2. Const
  3. XCen = 320;
  4. YCen = 240;
  5. Var
  6. size,Maincolor : byte;
  7. j,h,gd,gm : integer;
  8. Procedure WriteCell(x,y,color:integer);
  9. Var
  10. a2,x2,y2 : real;
  11. i : integer;
  12. Begin
  13. setcolor(color);
  14. a2:=0;x2:=x-size/2;y2:=y-sqrt(3*sqr(size)/4);Moveto(round(x2),round(y2));
  15. for i := 1 to 6 do
  16. begin
  17. x2 := x2+cos(a2)*size;
  18. y2 := y2+sin(a2)*size;
  19. Lineto(round(x2),round(y2));
  20. a2 := a2+60*3.14/180;
  21. end;
  22. End;
  23. Procedure ShowOne(k,color:integer);
  24. Var
  25. x0,y0,a,dx,dy : real;
  26. v : array [1..6] of pointtype;
  27. h,i,num : integer;
  28. snum : string;
  29. Begin
  30. a := 30*3.14/180;
  31. x0 := XCen+(k-1)*(size+round(size*cos(60*3.14/180)));
  32. y0 := 2*sqrt(3*size*size/4)+YCen+(k-1)*sqrt(3*sqr(size)/4);
  33. v[1].x := 0;
  34. v[1].y := round(k*2*sqrt(3*size*size/4)-4*k*sqrt(3*sqr(size)/4));
  35. num := ((12+(k-2)*6) div 2*(k-1))+2;
  36. for h := 2 to 6 do
  37. begin
  38. v[h].x := round(v[h-1].x+((2*sqrt(3*size*size/4))*k)*cos(a));
  39. v[h].y := round(v[h-1].y+((2*sqrt(3*size*size/4))*k)*sin(a));
  40. a:=a+60*3.14/180;
  41. end;
  42. v[2].x := -v[2].x;v[3].x := -v[3].x;v[5].x := -v[5].x;v[6].x := -v[6].x;
  43. for h := 1 to 6 do
  44. begin
  45. str(num+(h-1)*k+k-1,snum);
  46. if (MainColor<>0) then WriteCell(v[h].x+XCen,-v[h].y+Ycen,color)
  47. else WriteCell(v[h].x+XCen,-v[h].y+Ycen,Random(14)+1);
  48. IF TextWidth(snum) < 2*sqrt(3*size*size/4) then
  49. OutTextXY(v[h].x+XCen,-v[h].y+Ycen,snum);
  50. end;
  51. if (k<>1) then
  52. begin
  53. for h := 1 to 6 do
  54. begin
  55. if h = 1 then
  56. begin
  57. dx := v[6].x-v[1].x;
  58. dy := -(v[6].y-v[1].y);
  59. end
  60. else
  61. begin
  62. dx := v[h-1].x-v[h].x;
  63. dy := -(v[h-1].y-v[h].y);
  64. end;
  65. for i := k-1 downto 1 do
  66. begin
  67. Str(num,snum);
  68. if (MainColor<>0) then
  69. WriteCell(round(v[h].x+(dx/k*i)+XCen),round(-v[h].y+(dy/k*i))+Ycen,color)
  70. else WriteCell(round(v[h].x+(dx/k*i)+XCen),round(-v[h].y+(dy/k*i))+Ycen,Random(14)+1);
  71. IF TextWidth(snum) < 2*sqrt(3*size*size/4) then
  72. OutTextXY(round(v[h].x+(dx/k*i)+XCen),round(-v[h].y+(dy/k*i))+Ycen,snum);
  73. inc(num);
  74. end;
  75. INc(num);
  76. end;
  77. end;
  78. End;{ShowOne}
  79. {----------------------------}
  80. Procedure Start;
  81. Begin
  82. Gd := Detect;
  83. InitGraph(Gd, Gm, ' ');
  84. if GraphResult <> grOk then
  85. Halt(1);
  86. SetTextJustify(1,1);
  87. OutTextXY(XCen,Ycen,'1');
  88. End;
  89. Begin
  90. Write('Введите размер ячейки: ');
  91. ReadLn(size);
  92. { Write('Цвет? (0-нету) ');
  93. ReadLn(MainColor);}
  94. MainColor :=0;
  95. Start;
  96. for j := 1 to round(GetMaxY/(4*sqrt(3*size*size/4)))-1 do ShowOne(j,j mod 15 + 1);
  97. ReadKey;
  98. CloseGraph;
  99. End.