Saturday, October 17, 2015

Pascal: Отрисовываем елки



jgraph.pas:

  1. unit jgraph;
  2.  
  3. interface
  4.  
  5. uses Graph;
  6.  
  7. var
  8.   gd, gm, iJ, jJ: integer;
  9.   rJ, uJ, vJ, zJ: real;
  10.  
  11. procedure JInit;
  12. function Jx(x: real): integer;
  13. function Jy(y: real): integer;
  14. procedure JMoveTo(x,y: real);
  15. procedure JLineTo(x,y: real);
  16. procedure JLine(x1,y1,x2,y2: real);
  17. implementation
  18.  
  19. procedure JInit;
  20. begin
  21.   InitGraph(gd,gm,'');
  22.   rJ:= GetMaxY/GetMaxX;
  23.   uJ:= GetMaxX;
  24.   vJ:= GetMaxY/rJ;
  25.   zJ:= 0.5/GetMaxX
  26. end;
  27.  
  28. function Jx(x: real): integer;
  29. begin
  30.   Jx:= Round(x*uJ)
  31. end;
  32.  
  33. function Jy(y: real): integer;
  34. begin
  35.   Jy:= Round((rJ-y)*vJ)
  36. end;
  37.  
  38. procedure JMoveTo(x,y: real);
  39. begin
  40.   MoveTo(Jx(x),Jy(y))
  41. end;
  42.  
  43. procedure JLineTo(x,y: real);
  44. begin
  45.   LineTo(Jx(x),Jy(y))
  46. end;
  47.  
  48. procedure JLine(x1,y1,x2,y2: real);
  49. begin
  50.   Line(Jx(x1),Jy(y1),Jx(x2),Jy(y2))
  51. end;
  52.  
  53. begin
  54. end.

elka_z.pas:

  1. uses
  2.   Graph, WinCrt, jgraph;
  3.  
  4. procedure Elka(x,y,h,a,b,k: real);
  5. // x,y - coordinates of the base
  6. // h   - hight
  7. // a,b - external & internal top angles, rad
  8.  
  9.   procedure Zigzag(y,h,a: real);
  10.   var
  11.     ta,tb,ty,r: real;
  12.   begin
  13.     ta:= Sin(a)/Cos(a);
  14.     tb:= Sin(b)/Cos(b);
  15.     ty:= h+y;
  16.     JMoveTo(x,y);
  17.     while ty-y>zJ do begin
  18.       r:= h*ta;
  19.       JLineTo(x-r,y);
  20.       y:= y+Abs(r*tb*k);
  21.       h:= ty-y;
  22.       //for i:=1 to n do
  23.       JLineTo(x-r*(1-k),y)
  24.     end;
  25.   end;
  26.  
  27. begin
  28.   SetColor(DarkGray);
  29.   Zigzag(y,h,a);
  30.   Zigzag(y,h,-a);
  31.  
  32.   SetFillStyle(SolidFill,random(15)+1);
  33.   FloodFill(Jx(x),Jy(y)-1,DarkGray);
  34.   SetColor(White);
  35.   Zigzag(y,h,a);
  36.   Zigzag(y,h,-a);
  37.  
  38. end;
  39.  
  40. var
  41.   a: real;
  42.  
  43. begin
  44.  
  45.   randomize;
  46.   gd:=0;
  47.   JInit;
  48.   while  not KeyPressed do begin
  49.     a:= Pi/20+Pi/20*Random;
  50.     Elka(
  51.       Random,
  52.       Random*Random*0.5,
  53.       Random*rJ*0.6,
  54.       a,
  55.       (Pi/4-a)*(Random*0.25+0.7),
  56.       0.1+0.7*Random
  57.     );
  58.     Delay(300);
  59.   end;
  60.   readkey;
  61.   CloseGraph;
  62. end.



1 comment:

  1. Harrah's Cherokee Casino & Hotel - Mapyro
    Find 대구광역 출장안마 Harrah's Cherokee Casino & Hotel, Murphy, 안성 출장샵 NC, United States, price, 양주 출장마사지 history and map, 100 photos, 제천 출장샵 driving directions and online services. 충주 출장마사지

    ReplyDelete