home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l217 / 2.ddi / PROGRAMS / BGIDEMO.PRO next >
Encoding:
Text File  |  1990-05-16  |  37.8 KB  |  1,227 lines

  1. /************************************************************************
  2. *************************************************************************
  3. *                                    *
  4. *        Demo program using the BGI standard predicates        *
  5. *                                                                       *
  6. *             Copyright (c) 1986, 90 by Prolog Development Center       *
  7. *                                                                       *
  8. *                                    *
  9. *************************************************************************
  10. *************************************************************************/
  11.  
  12. /* 
  13.    If you want to link device drivers and character fonts into
  14.    the .EXE file you should include the following directives.
  15.    Depending upon your hardware choose one of the 5 bgidrivers by 
  16.    removing the % at the begining of the line. The Drivers are in
  17.    BGI.LIB. In the Options/Link Options/Libraries add +bgi.
  18.  
  19. %bgidriver "_EGAVGA_driver_far"
  20. %bgidriver "_CGA_driver_far"
  21. %bgidriver "_HERC_driver_far"
  22. %bgidriver "_PC3270_driver_far"
  23. %bgidriver "_ATT_driver_far"
  24. bgifont   "_gothic_font_far"
  25. bgifont   "_small_font_far"
  26. bgifont   "_sansserif_font_far"
  27. bgifont   "_triplex_font_far"
  28. */
  29.  
  30.  
  31. code = 3000
  32. include    "BGI.PRE"
  33.  
  34. CONSTANTS    % define a better name for BGI_ilist
  35.   intlist = BGI_ilist
  36.   bgi_Path = "..\\bgi"
  37.            % Hard disk users might need to set BGI_PATH="..\\bgi"
  38.                  % 2 Floppy users, set BGI_PATH = "a:"
  39.  
  40.  
  41. Domains
  42.   PointList = intlist*
  43.  
  44. Constants
  45.   PaletteList    = intlist
  46.  
  47. /************************************************************************
  48.         Local data base
  49. *************************************************************************/
  50.  
  51. Database - graphics
  52.   Determ driver(Integer,Integer,String)
  53.   Determ maxcolors(Integer)
  54.   Determ maxX(Integer)
  55.   Determ maxY(Integer)
  56.   Determ aspectCorr(Real)
  57.   Determ graphCoord(Integer,Integer)
  58.   Determ lineStyleDBA(Integer,Integer,Integer)
  59.   Determ textHeightDBA(Integer)
  60.  
  61. /************************************************************************
  62.         Return name of driver
  63. *************************************************************************/
  64.  
  65. PREDICATES
  66.   GetDriverName2(Integer,String)
  67.  
  68. CLAUSES
  69.   GetDriverName2(0,"Detect").    GetDriverName2(1,"CGA").
  70.   GetDriverName2(2,"MCGA").    GetDriverName2(3,"EGA").
  71.   GetDriverName2(4,"EGA64").    GetDriverName2(5,"EGAMono").
  72.   GetDriverName2(6,"Reserved").    GetDriverName2(7,"HercMono").
  73.   GetDriverName2(8,"ATT400").    GetDriverName2(9,"VGA").
  74.   GetDriverName2(10,"PC3270").
  75.  
  76. /************************************************************************
  77.     Convert the current device mode into a string
  78. *************************************************************************/
  79.  
  80. PREDICATES
  81.   GetMode(Integer,Integer,String)
  82.  
  83. CLAUSES
  84.   GetMode(cga,cgaHi,"CGAHi"):-!.
  85.   GetMode(cga,GraphMode,S):- !,format(S,"CGA%",GraphMode).
  86.   GetMode(mcga,mcgaMed,"MCGAMed"):- !.
  87.   GetMode(mcga,mcgahi,"MCGAHi"):- !.
  88.   GetMode(mcga,GraphMode,S):- !,format(S,"MCGA%",GraphMode).
  89.   GetMode(ega,egaLo,"EGALo"):- !.
  90.   GetMode(ega,egaHi,"EGAHi"):- !.
  91.   GetMode(ega64,ega64Lo,"EGA64Lo"):- !.
  92.   GetMode(ega64,ega64Hi,"EGA64Hi"):- !.
  93.   GetMode(hercMono,_,"HercMonoHi"):- !.
  94.   GetMode(egaMono,_,"EGAMonoHi"):- !.
  95.   GetMode(pc3270,_,"PC3270Hi"):- !.
  96.   GetMode(att400,att400Med,"ATT400Med"):- !.
  97.   GetMode(att400,att400Hi,"ATT400Hi"):- !.
  98.   GetMode(att400,GraphMode,S):- !,format(S,"ATT400%",GraphMode).
  99.   GetMode(vga,vgaLo,"VGALo"):- !.
  100.   GetMode(vga,vgaMed,"VGAMedo"):- !.
  101.   GetMode(vga,vgaHi,"VGAHi"):- !.
  102.   GetMode(_,_,"UnKnown"):- !.
  103.  
  104. /************************************************************************
  105.         Return name of font
  106. *************************************************************************/
  107.  
  108. PREDICATES
  109.   GetFontName(Integer,String)
  110.  
  111. CLAUSES
  112.   GetFontName(0,"Default").    GetFontName(1,"TrixplexFont").
  113.   GetFontName(2,"SmallFont").    GetFontName(3,"SansSerifFont").
  114.   GetFontName(4,"GothicFont").
  115.  
  116. /************************************************************************
  117.         BlackToWhite
  118. *************************************************************************/
  119.  
  120. PREDICATES
  121.   BlackToWhite(Integer,Integer)
  122.  
  123. CLAUSES
  124.   BlackToWhite(black,white):-GetMaxColor(X),X>4,!.
  125.   BlackToWhite(Color,Color).
  126.     
  127.  
  128. /************************************************************************
  129.         Repeat forever
  130. *************************************************************************/
  131.  
  132. PREDICATES
  133.   nondeterm repeat
  134.  
  135. CLAUSES
  136.   repeat.
  137.   repeat:- repeat.
  138.  
  139. /************************************************************************
  140.     Implementation of the C loop:  for(I=Cur, i<Max, I++)
  141. *************************************************************************/
  142.  
  143. PREDICATES
  144.   nondeterm for(Integer,Integer,Integer)
  145.  
  146. CLAUSES
  147.   for(Cur,_,Cur).
  148.   for(Cur,Max,I):- Cur2=Cur+1, Cur2<Max, for(Cur2,Max,I).
  149.  
  150. /************************************************************************
  151.     Graphics write a string
  152. *************************************************************************/
  153.  
  154. PREDICATES
  155.   gwrite(String)
  156.  
  157. CLAUSES
  158.   gwrite(S):-
  159.     retract(graphCoord(X,Y)),
  160.     OutTextXY(X,Y,S), TextHeight("H",DY), Y2=Y+DY+2,
  161.     assert(graphCoord(X,Y2)),!.
  162.  
  163. /************************************************************************
  164.         Mode switching
  165. *************************************************************************/
  166.  
  167. PREDICATES
  168.   ToGraphic
  169.   ToText
  170.   KeepColor(integer,integer,integer)
  171.  
  172. CLAUSES
  173.   ToGrapHic:-
  174.     /* Detect graphic equipment */
  175.     DetectGraph(G_Driver, G_Mode1),
  176.     KeepColor(G_Driver,G_Mode1,G_Mode),
  177.     GetDriverName2(G_Driver,G_Name),
  178.     assert(driver(G_Driver,G_Mode,G_Name)),
  179.     InitGraph(G_Driver,G_Mode, _, _, bgi_Path),!.
  180.  
  181.   ToText:-
  182.     closegraph().
  183.     
  184. KeepColor(1,_,0):- !.
  185. KeepColor(_,Mode,Mode).
  186.     
  187.  
  188. /************************************************************************
  189.     Display a status line at the bottom of the screen
  190. *************************************************************************/
  191.  
  192. PREDICATES
  193.   StatusLine(String)
  194.  
  195. CLAUSES
  196.   StatusLine(Msg):-
  197.     maxX(MaxX), maxY(MaxY), SetViewPort(0,0,MaxX,MaxY, 1),
  198.     maxColors(MaxColors), MaxCol2=MaxColors,
  199.     SetColor(MaxCol2),
  200.     SetBkColor(0),
  201.     SetTextStyle(default_Font, horiz_Dir, 1),
  202.     SetTextJustify(center_Text, top_Text),
  203.     SetLineStyle(solid_Line,0,norm_Width),
  204.     SetFillStyle(empty_Fill,0),
  205.     TextHeight("H",Height), MaxYH = MaxY-(Height+4),
  206.     Bar(0, MaxYH,MaxX,MaxY),
  207.     Rectangle(0,MaxYH,MaxX,MaxY),
  208.     MaxX2 = MaxX div 2, MaxY2 = MaxY-(Height+2),
  209.     OutTextXY(MaxX2,MaxY2, Msg),
  210.     Height5 = Height+5, MaxX1=MaxX-1, MaxY5 = MaxY-(Height+5),
  211.     SetViewPort(1,Height5,MaxX1,MaxY5,1).
  212.  
  213. /************************************************************************
  214.     Pause until the user enter a keystroke
  215. *************************************************************************/
  216.  
  217. PREDICATES
  218.   Pause
  219.   ChkEsc(Char)
  220.  
  221. CLAUSES
  222.   Pause:-
  223.     StatusLine("Esc aborts or press a key ..."),
  224.     readChar(Ch), ChkEsc(Ch).
  225.  
  226.   ChkEsc('\027'):- !,CloseGraph, exit(1).
  227.   ChkEsc(_).
  228.  
  229. /************************************************************************
  230.     Draw a solid line around the current viewport
  231. *************************************************************************/
  232.  
  233. PREDICATES
  234.   DrawBorder
  235.  
  236. CLAUSES
  237.   DrawBorder:-
  238.     maxColors(MaxColors), MaxCol2 = MaxColors, SetColor(MaxCol2),
  239.     SetBkColor(0),
  240.     SetLineStyle(solid_Line,0,norm_Width),
  241.     GetViewSettings(Left,Top,Right,Bottom,_),
  242.     RL=Right-Left, BT=Bottom-Top,
  243.     Rectangle(0,0,RL,BT).
  244.  
  245. /************************************************************************
  246.     Establish the main window and set a viewport
  247. *************************************************************************/
  248.  
  249. PREDICATES
  250.   MainWindow(String)
  251.  
  252. CLAUSES
  253.   MainWindow(Header):-
  254.     ClearDevice,
  255.     maxColors(MaxColors),
  256.     MaxCol1=MaxColors,
  257.     SetColor(MaxCol1),           % Set current color to white
  258.     SetBkColor(0),               % Set background to black
  259.     TextHeight("H",Height),           % Get basic text height
  260.     Height5=Height+5, Height4=Height+4,
  261.     maxX(MaxX), MaxX1=MaxX-1,MaxX2=MaxX div 2,
  262.     maxY(MaxY), MaxY4=MaxY-(Height+4),MaxY5=MaxY-(Height+5),
  263.     SetViewPort(0,0,MaxX,MaxY,1),       % Open port to full screen
  264.     SettextStyle(default_font,horiz_dir,1),
  265.     SetTextJustify(center_text, top_text),
  266.     OutTextXY(MaxX2,2,Header),
  267.     SetViewPort( 0, Height4, MaxX, MaxY4, 1),
  268.     DrawBorder,
  269.     SetViewPort(1, Height5, MaxX1,MaxY5, 1).
  270.  
  271. /************************************************************************
  272.         Initialize video and Global flags
  273. *************************************************************************/
  274.  
  275. PREDICATES
  276.   Initialize
  277.  
  278. CLAUSES
  279.   Initialize:-
  280.       retractall(_, graphics),
  281.       ToGraphic,
  282.       GetMaxColor(MaxColors),   assert(maxcolors(MaxColors)),
  283.       GetMaxX(MaxX),      assert(maxX(MaxX)),
  284.       GetMaxY(MaxY),      assert(maxY(MaxY)),
  285.       GetAspectRatio(Xasp,Yasp),
  286.       AspectRatio = Xasp/Yasp,  assert(aspectCorr(AspectRatio)).
  287.  
  288. /************************************************************************
  289.         Report the current configuration
  290. *************************************************************************/
  291.  
  292. PREDICATES
  293.   ReportStatus
  294.  
  295. CLAUSES
  296.   ReportStatus:-
  297.     GetViewSettings(Left,Top,Right,Bottom,Clip),
  298.     GetLineSettings(LineStyle,_,ThickNess),
  299.     GetFillSettings(FillPattern,FillColor),
  300.     GetTextSettings(Font,Direction,CharSize,Horiz,Vert),
  301.     X = 10, Y = 4, assert(graphCoord(X,Y)),
  302.     MainWindow("Status report after InitGraph "),
  303.     SetTextJustify(left_Text,top_Text),
  304.     maxColors(MaxC), MaxC2 = MaxC, SetColor(MaxC2),
  305.     driver(DriverNo,DriverMode,Driver),
  306.     GetMode(DriverNo,DriverMode,Mode),
  307.     format(Buf1,"Graphics device   : %-20 (%)",Driver,DriverNo), gwrite(Buf1),
  308.     format(Buf2,"Graphics mode     : %-20 (%)",Mode,DriverMode), gwrite(Buf2),
  309.     maxX(MaxX), maxY(MaxY),
  310.     format(Buf3,"Screen resolution : ( 0, 0, %, % )",MaxX,MaxY), gwrite(Buf3),
  311.     format(Buf4,"Current view port : ( %, %, %, % )",Left,Top, Right, Bottom), gwrite(Buf4),
  312.     format(Buf5,"Clipping          : %",Clip), gwrite(Buf5),
  313.     GetX(XX), GetY(YY),
  314.     format(Buf6,"Current position  : ( %, % )",XX,YY), gwrite(Buf6),
  315.     maxColors(MaxColors),
  316.     format(Buf7,"Colors available  : %",MaxColors), gwrite(Buf7),
  317.     GetColor(Color),
  318.     format(Buf8,"Current color     : %",Color), gwrite(Buf8),
  319.     format(Buf9 ,"Line style        : %",LineStyle), gwrite(Buf9),
  320.     format(Buf10,"Line thickness    : %",Thickness), gwrite(Buf10),
  321.         format(Buf11,"Current fill style: %",FillPattern), gwrite(Buf11),
  322.         format(Buf12,"Current fill color: %",FillColor), gwrite(Buf12),
  323.         format(Buf13,"Current font      : %",Font), gwrite(Buf13),
  324.         format(Buf14,"Text direction    : %",Direction), gwrite(Buf14),
  325.         format(Buf15,"Character size    : %",CharSize), gwrite(Buf15),
  326.         format(Buf16,"Horizontal justify: %",Horiz), gwrite(Buf16),
  327.         format(Buf17,"Vertical justify  : %",Vert), gwrite(Buf17),
  328.         Pause.
  329.  
  330. /************************************************************************
  331.     Display a 3-D bar chart on the screen
  332. *************************************************************************/
  333.  
  334. PREDICATES
  335.   Bar3DDemo
  336.   Bar3DDemo2(Integer,Integer,Integer)
  337.   Bar3DDemo3(Integer,Integer,Integer,Integer,Integer)
  338.   BarHeight(Integer,Integer)
  339.  
  340. CLAUSES
  341.   Bar3DDemo:-
  342.       MainWindow("Bar 3-D / Rectangle Demonstration"),
  343.       TextHeight("H",Height), H = 3*Height,
  344.     GetViewSettings(Left1,Top1,Right1,Bottom1,_),
  345.     SetTextJustify(center_Text,top_Text),
  346.     SetTextStyle(triplex_Font,horiz_Dir,4),
  347.     maxX(MaxX), MaxX2 = MaxX div 2,
  348.     OutTextXY(MaxX2,6,"These are 3-D Bars"),
  349.     SetTextStyle(default_Font, horiz_Dir, 1),
  350.     Left50 = Left1+50, Top40 = Top1+40, Right50=Right1-50, Bottom10=Bottom1-10,
  351.     SetViewPort(Left50,Top40,Right50,Bottom10,1),
  352.     GetViewSettings(Left,Top,Right,Bottom,_),
  353.     BTH = Bottom-Top-H,
  354.     Line(H,H,H, BTH),
  355.     RLH = Right-Left-H,
  356.     Line(H, BTH, RLH, BTH),
  357.     XStep = (Right-Left-2*H) div 10,
  358.     YStep = (Bottom-Top-2*H) div 5,
  359.     J     = Bottom-Top-H,
  360.     SetTextJustify(center_Text,center_Text),
  361.     Bar3DDemo2(H,J,Ystep),
  362.     SetTextJustify(center_Text,top_Text),
  363.     Bar3DDemo3(H,Bottom,Top,YStep,XStep),
  364.     Pause.
  365.  
  366.   Bar3DDemo2(H,InitJ,YStep):-
  367.       for (0,6,I),
  368.         H2 = H div 2, J = InitJ - YStep*I,
  369.         Line(H2,J,H,J),
  370.         str_int(Buf,I),
  371.         OutTextXY(0,J,Buf),
  372.       fail.
  373.   Bar3DDemo2(_,_,_).
  374.  
  375.   Bar3DDemo3(H,Bottom,Top,YStep,XStep):-
  376.       maxColors(MaxColors),
  377.       for (0,11,I),
  378.         J  = H + XStep*I,
  379.         random(MaxColors,Color),
  380.         I1 = I + 1,
  381.         SetFillStyle(I1,Color),
  382.         BTH = Bottom-Top-H, BT3H2 = Bottom-Top-3-H div 2,
  383.         Line(J,BTH,J,BT3H2),
  384.         Str_Int(Buf,I),
  385.         BTH2 = Bottom-Top-H div 2,
  386.         OutTextXY(J,BTH2,Buf),
  387.         I<>10,
  388.         BHeight = Bottom-Top-H-1,
  389.         BarHeight(I,BH),
  390.         BTHBY      = Bottom-Top-H-BH*YStep, JX = J+XStep,
  391.         Bar3D(J,BTHBY, JX, BHeight,15,1),
  392.       fail.
  393.   Bar3DDemo3(_,_,_,_,_).
  394.  
  395.   BarHeight(0,1).  BarHeight(1,3).  BarHeight(2,5).  BarHeight(3,4).
  396.   BarHeight(4,3).  BarHeight(5,2).  BarHeight(6,1).  BarHeight(7,5).
  397.   BarHeight(8,4).  BarHeight(9,2).  BarHeight(10,3).
  398.  
  399. /************************************************************************
  400.     Display a 2-D bar chart using Bar and Rectangle
  401. *************************************************************************/
  402.  
  403. PREDICATES
  404.   BarDemo
  405.   BarDemo_2(Integer,Integer,Integer)
  406.   BarDemo_3(Integer,Integer,Integer,Integer)
  407.   BarDemo_Style(Integer,Integer)
  408.   BarDemo_BarHeight(Integer,Integer)
  409.  
  410. CLAUSES
  411.   BarDemo:-
  412.       MainWindow("Bar / Rectangle demonstration"),
  413.       TextHeight("H",Height), H = 3*Height,
  414.       GetViewSettings(Left1,Top1,Right1,Bottom1,_),
  415.     SetTextJustify(center_Text,top_Text),
  416.     SetTextStyle(triplex_Font,horiz_Dir,4),
  417.     maxX(MaxX), MaxX2 = MaxX div 2,
  418.     OutTextXY(MaxX2,6,"These are 2-D Bars"),
  419.     SetTextStyle(default_Font, horiz_Dir, 1),
  420.     Left50 = Left1+50, Top30 = Top1+30, Right50=Right1-50, Bottom10=Bottom1-10,
  421.     SetViewPort(Left50,Top30,Right50,Bottom10,1),
  422.     GetViewSettings(Left,Top,Right,Bottom,_),
  423.     SHeight    = Bottom-Top,
  424.     SWidth    = Right-Left,
  425.     SHeightH= SHeight-H,
  426.     Line(H,H,H,SHeightH),
  427.     Line(H,SHeightH,SHeightH,SHeightH),
  428.     YStep    = (SHeight - 2*H) div 5,
  429.     XStep    = (SWidth  - 2*H) div 5,
  430.     SetTextJustify(center_Text,center_Text),
  431.     BarDemo_2(H,SHeightH,YStep),
  432.     SetTextJustify(center_Text,top_Text),
  433.     BarDemo_3(H,SHeight,YStep,XStep),
  434.     Pause.
  435.  
  436.   BarDemo_2(H,SHeightH,YStep):-
  437.       H2 = H div 2,
  438.       for (0,5,I),
  439.         J = SHeightH - I*YStep,
  440.         Line(H2,J,H,J),
  441.         Str_Int(Buf,I),
  442.         OutTextXY(0,J,Buf),
  443.       fail.
  444.   BarDemo_2(_,_,_).
  445.  
  446.   BarDemo_3(H,SHeight,YStep,XStep):-
  447.       maxColors(MaxColors),
  448.       for (0,5,I),
  449.         J       = H + I*XStep,
  450.         BarDemo_Style(I,Style),
  451.         BarDemo_BarHeight(I,BHeight),
  452.         Random(MaxColors,RM),
  453.         SetFillStyle(Style,RM),
  454.         SHeightH = SHeight-H, SHeight3H = Sheight-3-H div 2,
  455.         Line(J,SHeightH,J,Sheight3H),
  456.         Str_Int(Buf,I),
  457.         SHeightH2 = SHeight-H div 2,
  458.         OutTextXY(J,SHeightH2,Buf),
  459.         I<>5,
  460.         SheightHBY = SHeight-H-BHeight*YStep, JX = J+XStep, SHeightH1=SHeight-H-1,
  461.         Bar(J,SHeightHBY,JX,SHeightH1),
  462.         Rectangle(J,SHeightHBY, JX,SHeightH),
  463.         fail.
  464.   BarDemo_3(_,_,_,_).
  465.  
  466.   BarDemo_Style(0,1).  BarDemo_Style(1,3).  BarDemo_Style(2,10).
  467.   BarDemo_Style(3,5).  BarDemo_Style(4,9).  BarDemo_Style(5,1).
  468.  
  469.   BarDemo_BarHeight(0,1).  BarDemo_BarHeight(1,3).  BarDemo_BarHeight(2,5).
  470.   BarDemo_BarHeight(3,2).  BarDemo_BarHeight(4,4).
  471.  
  472. /************************************************************************
  473.     Display a random pattern of ARC's on the screen
  474. *************************************************************************/
  475.  
  476. PREDICATES
  477.   ArcDemo
  478.  
  479. CLAUSES
  480.   ArcDemo:-
  481.       MainWindow("Arc Demonstration"),
  482.       StatusLine("Esc Aborts - Press a Key to stop"),
  483.       maxY(MaxY), Mradius = MaxY div 10, maxX(MaxX),
  484.       maxColors(MaxColors),
  485.       Repeat,
  486.         Random(MaxColors,RM), SetColor(RM),
  487.         Random(358,R2), Eangle = 1 + R2,
  488.         Random(MaxX,RX),
  489.         Random(MaxY,RY),
  490.         Random(Eangle,RE),
  491.         Arc(RX,RY,RE,Eangle,Mradius),
  492.         GetArcCoords(X,Y,XStart,YStart,XEnd,YEnd),
  493.         Line(X,Y,XStart,YStart),
  494.         Line(X,Y,XEnd,YEnd),
  495.       KeyPressed,!,
  496.       Pause.
  497.  
  498. /************************************************************************
  499.     Display a random pattern of Circles on the screen
  500. *************************************************************************/
  501.  
  502. PREDICATES
  503.   CircleDemo
  504.  
  505. CLAUSES
  506.   CircleDemo:-
  507.     MainWIndow("Circle Demonstration"),
  508.     StatusLine("Esc Aborts - Press a key to stop"),
  509.       maxY(MaxY), Mradius = MaxY div 10, maxX(MaxX),
  510.       maxColors(MaxColors),
  511.       Repeat,
  512.         Random(MaxColors,RM), SetColor(RM),
  513.         Random(MaxX,RX),
  514.         Random(MaxY,RY),
  515.         Random(Mradius,RR),
  516.         Circle(Rx,Ry,RR),
  517.       KeyPressed,!,
  518.       Pause.
  519.  
  520. /************************************************************************
  521.         Display a pie chart on the screen
  522. *************************************************************************/
  523.  
  524. PREDICATES
  525.   PieDemo
  526.   ToRad(Real,Real)
  527.   AdjAsp(Integer,Real)
  528.   colorPie(integer,integer,integer,integer)
  529.  
  530. CLAUSES
  531.   PieDemo:-
  532.       MainWindow("Pie Chart Demonstration"),
  533.       GetViewSettings(Left,Top,Right,Bottom,_),
  534.       XCenter    = (Right-Left) div 2,
  535.       YCenter = (Bottom-Top) div 2+20,
  536.       Radius  = (Bottom-Top) div 3,
  537.       LRadius = Radius + Radius div 5,
  538.       SetTextStyle(triplex_Font,horiz_Dir,4),
  539.       SetTextJustify(center_Text,top_Text),
  540.       maxX(MaxX), MaxX2 = MaxX div 2,
  541.       OutTextXY(MaxX2,6,"This is a Pie Chart"),
  542.       SetTextStyle(triplex_Font,horiz_Dir,3),
  543.       SetTextJustify(center_Text,top_Text),
  544.         ColorPie(ColorP1,ColorP2,ColorP3,ColorP4),      
  545.       SetFillStyle(solid_Fill,ColorP1),
  546.       XCenter10 = XCenter+4, AdjAsp(5,Asp), YCenterAdj10 = YCenter-Asp,
  547.       PieSlice(XCenter10,YCenterAdj10,0,90,Radius),
  548.     aspectCorr(AspectRatio),
  549.     ToRad(45,Radians),
  550.       X = XCenter + cos(Radians)*LRadius,
  551.       Y = YCenter - sin(Radians)*LRadius*AspectRatio,
  552.       SetTextJustify(left_Text,bottom_Text),
  553.       OutTextXY(X,Y,"25 %"),
  554.       SetFillStyle(wide_Dot_Fill,ColorP2),
  555.       PieSlice(XCenter,YCenter,90,135,Radius),
  556.       ToRad(113,Rad2),
  557.       X2 = XCenter + cos(Rad2)*LRadius+20,
  558.       Y2 = YCenter - sin(Rad2)*LRadius*AspectRatio+2,
  559.       SetTextJustify(right_Text,bottom_Text),
  560.       OutTextXY(X2,Y2,"12.5 %"),
  561.       SetFillStyle(interleave_Fill,ColorP3),
  562.       SetTextJustify(right_Text,center_Text),
  563.       XCenterM10 = XCenter - 7,
  564.       PieSlice(XCenterM10,YCenter,135,225,Radius),
  565.       ToRad(180,Rad3),
  566.       X3 = XCenter + cos(Rad3)*LRadius,
  567.       Y3 = YCenter - sin(Rad3)*LRadius*AspectRatio,
  568.       SetTextJustify(right_Text,center_Text),
  569.       OutTextXY(X3,Y3,"25 %"),
  570.       SetFillStyle(hatch_Fill,ColorP4),
  571.       PieSlice(XCenter,YCenter,225,360,Radius),
  572.       ToRad(293,Rad4),
  573.       X4 = XCenter + cos(Rad4)*LRadius+20,
  574.       Y4 = YCenter - sin(Rad4)*LRadius*AspectRatio-20,
  575.       SetTextJustify(left_Text,top_Text),
  576.       OutTextXY(X4,Y4,"37.5 %"),
  577.       Pause.
  578.  
  579.   ToRad(D,Rad):- Rad = D*pi/180.0.
  580.  
  581.   AdjAsp(Y,Asp):- aspectCorr(AspectRatio), Asp = AspectRatio*Y.
  582.  
  583. colorPie(red, green, yellow, blue):- getmaxColor(C),C>3,!.
  584. ColorPie(blue,green,cyan,green).
  585.  
  586.  
  587. /************************************************************************
  588.     Display pattern using MoveRel and LineRel commands
  589. *************************************************************************/
  590.  
  591. PREDICATES
  592.   LineRelDemo
  593.  
  594. CLAUSES
  595.   LineRelDemo:-
  596.       MainWindow("MoveRel / LineRel Demonstration"),
  597.     StatusLine("Press any key to continue, Esc to Abort"),
  598.       GetViewSettings(Left,Top,Right,Bottom,_),
  599.       CX = (Right-Left) div 2, CY = (Bottom-Top) div 2,
  600.       H = (Bottom-Top) div 8, W = (Right-Left) div 9,
  601.       DX = 2*W, DY = 2*H,
  602.       colorpie(C1,C2,C3,_),
  603.       SetColor(black),
  604.       SetFillStyle(solid_Fill,C1),
  605.       RL = Right-Left, BT = Bottom-Top,
  606.       Bar(0,0,RL,BT),
  607.     CXMDX = CX-DX, CYMDY = CY-DY,
  608.     CXMDXPW = CX-DX+W, CYMDYMH = CY-DY-H,
  609.     CXPDX = CX+DX, CYPDY = CY+DY,
  610.     CXPDXMW = CX+DX-W, CYPDYPH = CY+DY+H,
  611.     OutS    = [CXMDX,CYMDY,CXMDXPW,CYMDYMH,CXPDX,CYMDYMH,
  612.            CXPDX,CYPDY,CXPDXMW,CYPDYPH,CXMDX,CYPDYPH,CXMDX,CYMDY],
  613.     SetFillStyle(solid_Fill,C2),
  614.     FillPoly(Outs),
  615.     CXMW2 = CX-W div 2, CYPH = CY+H,
  616.     CXPW2 = CX+W div 2, CYMH = CY-H,
  617.     OutS2 = [CXMW2,CYPH,CXPW2,CYPH,CXPW2,CYMH,CXMW2,CYMH,CXMW2,CYPH],
  618.     SetFillStyle(solid_Fill,C3),
  619.     FillPoly(OutS2),
  620.     MH = -H, WT3 = 3*W, HT5 = 5*H, M3TW = -3*W, M5TH = -5*H, MW = -W,
  621.     MoveTo(CXMDX,CYMDY),
  622.     LineRel(W,MH), LineRel(WT3,0), LineRel(0,HT5), LineRel(MW,H),
  623.     LineRel(M3TW,0), LineRel(0,M5TH),
  624.     WPWD2 = W+W div 2, M3TH = -3*H, WD2 = W div 2,
  625.     MoveRel(W,MH),
  626.     LineRel(0,HT5), LineRel(WPWD2,0), LineRel(0,M3TH),
  627.     LineRel(WD2,MH), LineRel(0,HT5),
  628.     MWMWD2 = -W-W div 2, HT3 = 3*H, MWD2 = - W div 2,
  629.     MoveRel(0,M5TH), LineRel(MWMWD2,0), LineRel(0,HT3), LineRel(MWD2,H),
  630.     MoveRel(WD2,MH), LineRel(W,0),
  631.     M2TH = -2*H,
  632.     MoveRel(0,M2TH), LineRel(MW,0),
  633.       Pause.
  634.  
  635. /************************************************************************
  636.     Display a pattern using MoveTo and LineTo commands
  637. *************************************************************************/
  638.  
  639. CONSTANTS
  640.   maxpts    = 15
  641.  
  642. PREDICATES
  643.   LineToDemo
  644.   LineToDemo2(PointList,Integer,Integer,Integer,Integer,Real,Real)
  645.   LineToDemo3(PointList)
  646.   LineToDemo4(Integer,Integer,PointList)
  647.  
  648. CLAUSES
  649.   LineToDemo:-
  650.       MainWindow("MoveTo / LineTo Demonstration"),
  651.       GetViewSettings(Left,Top,Right,Bottom,_),
  652.       H    = Bottom - Top,
  653.       W    = Right - Left,
  654.       XCenter    = W div 2,
  655.       YCenter    = H div 2,
  656.     aspectCorr(AspectRatio),
  657.       Radius    = (H-30)/(AspectRatio*2),
  658.       Step    = 360/maxpts,
  659.       LineToDemo2(Points,0,XCenter,YCenter,Radius,AspectRatio,Step),
  660.       Circle(XCenter,YCenter,Radius),
  661.       LineToDemo3(Points),
  662.       Pause.
  663.  
  664.   LineToDemo2([[X,Y]|Points],I,XCenter,YCenter,Radius,AspectRatio,Step):-
  665.     I<maxpts,!,
  666.     Angle    = I*Step,
  667.     Rads    = Angle*pi/180.0,
  668.     X    = XCenter + cos(Rads)*Radius,
  669.     Y    = YCenter - sin(Rads)*Radius*AspectRatio,
  670.     I2    = I+1,
  671.     LineToDemo2(Points,I2,XCenter,YCenter,Radius,AspectRatio,Step).
  672.   LineToDemo2([],_,_,_,_,_,_).
  673.  
  674.   LineToDemo3([]):- !.
  675.   LineToDemo3([[X,Y]|Points]):-
  676.       X2=X, Y2=Y,
  677.       LineToDemo4(X2,Y2,[[X,Y]|Points]),
  678.       LineToDemo3(Points).
  679.  
  680.   LineToDemo4(X,Y,[[X2,Y2]|Points]):-!,
  681.       MoveTo(X,Y),
  682.       LineTo(X2,Y2),
  683.       LineToDemo4(X,Y,Points).
  684.   LineToDemo4(_,_,_).
  685.  
  686. /************************************************************************
  687.     Display a pattern using all of the standard line styles that
  688.     are available
  689. *************************************************************************/
  690.  
  691. PREDICATES
  692.   LineStyleDemo
  693.   LineStyleDemo2(Integer,Integer,Integer,Integer,Integer)
  694.  
  695. CLAUSES
  696.   LineStyleDemo:-
  697.     MainWIndow("Pre-defined line styles"),
  698.       GetViewSettings(Left,_,Right,Bottom,_),
  699.       W = Right - Left, Step = W div 11,
  700.       X = 35, Y = 10,
  701.       GetTextSettings(Font,Direction,CharSize,_,_),
  702.       SetTextStyle(sANS_SERIF_FONT,horiz_Dir,2),
  703.       SetTextJustify(left_Text,top_Text),
  704.       Y10 = Y - 10,
  705.       X1 = X -20,
  706.       OutTextXY(X1,Y10,"Normal Width"),
  707.       SetTextStyle(Font,Direction,CharSize),
  708.       LineStyleDemo2(X,Y,Bottom,Step,norm_Width),
  709.       X2 = X + 6*Step,
  710.       X3 = X1 + 6*Step+3,
  711.       SetTextStyle(sANS_SERIF_FONT,horiz_Dir,2),
  712.       SetTextJustify(left_Text,top_Text),
  713.       OutTextXY(X3,Y10,"Thick Width"),
  714.       SetTextStyle(Font,Direction,CharSize),
  715.       SetTextJustify(center_Text,top_Text),
  716.       LineStyleDemo2(X2,Y,Bottom,Step,thick_Width),
  717.       SetTextJustify(left_Text,top_Text),
  718.       Pause.
  719.  
  720.   LineStyleDemo2(InitX,Y,Bottom,Step,Width):-
  721.       Y20     = Y + 20,
  722.       Bottom40 = Bottom - 40,
  723.       Bottom30 = Bottom-30,
  724.       for (0,4,Style),
  725.         SetLineStyle(Style,0,Width),
  726.         X    = InitX + Style*Step,
  727.         Line(X,Y20,X,Bottom40),
  728.         Str_Int(Buf,Style),
  729.         OutTextXY(X,Bottom30,Buf),
  730.       fail.
  731.   LineStyleDemo2(_,_,_,_,_).
  732.  
  733. /************************************************************************
  734.         Display user definable line styles
  735. *************************************************************************/
  736.  
  737. PREDICATES
  738.   UserLineStyleDemo
  739.   UserLineStyleDemo2(Integer,Integer,Integer,Integer)
  740.   UserLineStyleDemo3(Integer,Integer,Integer,Integer,Integer)
  741.  
  742. CLAUSES
  743.   UserLineStyleDemo:-
  744.       MainWindow("User defined line styles"),
  745.       GetViewSettings(_,Top,Right,Bottom,_),
  746.       H = Bottom-Top,
  747.       Y = 10,
  748.       SetTextJustify(center_Text,top_Text),
  749.       assert(lineStyleDBA(0,0,true)),    % Style, I, Flag
  750.       for (0,Right,J),
  751.         X = 4 + J*5,
  752.         X < (Right-2),
  753.         retract(lineStyleDBA(Style,I,Flag)),
  754.         UserLineStyleDemo2(Style,Style2,I,Flag),
  755.         SetLineStyle(userbit_Line,Style2,norm_Width),
  756.         HY = H - Y,
  757.         Line(X,Y,X,HY),
  758.         I2 = (I+1) mod 16,
  759.         UserLineStyleDemo3(Style2,Flag,Flag2,I2,I3),
  760.         assert(lineStyleDBA(Style2,I3,Flag2)),
  761.       fail.
  762.  
  763.   UserLineStyleDemo:-
  764.       SetTextJustify(left_Text,top_Text),
  765.       Pause.
  766.  
  767.   UserLineStyleDemo2(Style,Style2,I,true):-
  768.       bitleft(1,I,IL),
  769.       bitor(Style,IL,Style2).
  770.  
  771.   UserLineStyleDemo2(Style,Style2,I,false):-
  772.       bitright($8000,I,IR), bitxor(IR,$FFFF,IR2),
  773.       bitand(Style,IR2,Style2).
  774.  
  775.   UserLineStyleDemo3($FFFF,_,false,_,0):-!.
  776.   UserLineStyleDemo3(0,_,true,I,I):-!.
  777.   UserLineStyleDemo3(_,Flag,Flag,I,I).
  778.  
  779. /************************************************************************
  780.     Display all the characters in each of the available fonts
  781. *************************************************************************/
  782.  
  783. PREDICATES
  784.   TextDump
  785.   TextDump2(Integer,Integer,Integer)
  786.   EvalSize(Integer,Integer)
  787.   CGASizes(Integer,Integer)
  788.   NormSizes(Integer,Integer)
  789.  
  790. CLAUSES
  791.   TextDump:-
  792.     for (0,5,Font),
  793.       GetFontName(Font,FontName),
  794.       format(Buf,"%s Character Set",FontName),
  795.       MainWindow(Buf),
  796.       GetViewSettings(Left,_,Right,_,_),
  797.       SetTextJustify(left_Text, top_Text),
  798.       MoveTo(2,3),
  799.       WWidth    = Right - Left,
  800.       TextHeight("H",LWidth),
  801.       TextDump2(Font,LWidth,WWidth),
  802.       Pause,
  803.     fail.
  804.   TextDump.
  805.  
  806.   TextDump2(default_Font,Lwidth,WWidth):-
  807.       SetTextStyle(default_Font,horiz_Dir,1),
  808.       for (0,256,Ch),
  809.         Char_Int(Ch2,Ch), Str_Char(Buf,Ch2),
  810.         OutText(Buf),
  811.         GetX(X),
  812.         X+LWidth > WWidth,
  813.           GetY(Y), TextHeight("H",TH), YT=Y+TH+3,
  814.           MoveTo(2, YT),
  815.       fail.
  816.   TextDump2(default_Font,_,_):- !.
  817.   TextDump2(Font,Lwidth,WWidth):-
  818.       EvalSize(Font,Size),
  819.       SetTextStyle(Font,horiz_Dir,Size),
  820.       Char_Int('!',Start),
  821.       for (Start,127,Ch),
  822.         Char_Int(Ch2,Ch), Str_Char(Buf,Ch2),
  823.         OutText(Buf),
  824.         GetX(X),
  825.         X+LWidth > WWidth,
  826.           GetY(Y), TextHeight("H",TH), YT=Y+TH+3,
  827.           MoveTo(2, YT),
  828.       fail.
  829.   TextDump2(_,_,_).
  830.  
  831.   EvalSize(Font,Size):- GetMaxY(Y), Y<200,!, CGASizes(Font,Size).
  832.   EvalSize(Font,Size):- NormSizes(Font,Size).
  833.  
  834.   CGASizes(0,1).  CGASizes(1,3).  CGASizes(2,7).
  835.   CGASizes(3,3).  CGASizes(4,3).
  836.  
  837.   NormSizes(0,1).  NormSizes(1,4).  NormSizes(2,7).
  838.   NormSizes(3,4).  NormSizes(4,6).
  839.  
  840. /************************************************************************
  841.     Show each font in several sizes to the user
  842. *************************************************************************/
  843.  
  844. PREDICATES
  845.   TextDemo
  846.   TextDemo2(Integer,Integer,Integer)
  847.   TextDemo3(Integer,Integer,Integer,Integer,Integer,Integer,Integer)
  848.   FontSize(Integer,Integer,Integer)
  849.   CharSizes(Integer,Integer)
  850.  
  851. CLAUSES
  852.   TextDemo:-
  853.       for(0,5,Font),
  854.       GetFontName(Font,FontName),
  855.         format(Buf,"% Demonstration",FontName),
  856.         Mainwindow(Buf),
  857.       GetViewSettings(Left,Top,Right,Bottom,_),
  858.       CharSizes(Font,CharSiz),
  859.        SetTextStyle(Font, vert_Dir, CharSiz),
  860.       Y = (Bottom - Top)/1.1,
  861.       SetTextJustify(center_Text,bottom_Text),
  862.       TextWidth("M",Width), TxtWidth2    = 2*Width,
  863.       OutTextXY(TxtWidth2, Y, "Vertical -->"),
  864.       SetTextStyle(Font,horiz_Dir,CharSiz),
  865.       SetTextJustify(left_Text,top_Text),
  866.       TextWidth("M",Width2), TxtWidth22    = 2*Width2,
  867.       OutTextXY(TxtWidth22,2,"Horizontal -->"),
  868.       SetTextJustify(center_Text,center_Text),
  869.       X = (Right - Left) / 2,
  870.       TextHeight("H",Y2),
  871.       TextDemo2(Font,Y2,X),
  872.       TextHeight("H",H),
  873.       TextDemo3(Y2,H,Font,horiz_Dir,user_Char_Size, Right,Left),
  874.       Pause,
  875.     fail.
  876.   TextDemo.
  877.  
  878.   TextDemo2(Font,InitY,X):-
  879.       assert(textHeightDBA(InitY)),
  880.        for (0,5,I),
  881.         FontSize(Font,I,Size),
  882.         SetTextStyle(Font,horiz_Dir,Size),
  883.         TextHeight("H",H),
  884.         retract(textHeightDBA(Y1)),
  885.         Y = Y1 + H,
  886.         assert(textHeightDBA(Y)),
  887.         format(Buf,"Size %",Size),
  888.         OutTextXY(X,Y,Buf),
  889.       fail.
  890.   TextDemo2(_,_,_):- retract(textHeightDBA(_)),!.
  891.  
  892.   TextDemo3(Y2,H,Font,horiz_Dir,user_Char_Size, Right,Left):-
  893.         Font <> default_Font,!,
  894.       YH2    = Y2 + 4*H + H div 2,
  895.       SetTextJustify(center_Text,top_Text),
  896.       SetUserCharSize(5,6,3,2),
  897.       SetTextStyle(Font,horiz_Dir,user_Char_Size),
  898.       RL2    = (Right - Left)  div  2,
  899.       OutTextXY(RL2,YH2,"User Defined Size").
  900.   TextDemo3(_,_,_,_,_,_,_).
  901.  
  902.   FontSize(small_Font,I,I4):- !,I4=I+4.
  903.   FontSize(_,I,I1):- I1 = I + 1.
  904.  
  905.   CharSizes(0,1).  CharSizes(1,3).  CharSizes(2,7).
  906.   CharSizes(3,3).  CharSizes(4,3).
  907.  
  908. /************************************************************************
  909.     Demonstrate the effects of changing mode
  910. *************************************************************************/
  911.  
  912. PREDICATES
  913.   CRTModeDemo
  914.  
  915. CLAUSES
  916.   CRTModeDemo:-
  917.       MainWIndow("SetGraphMode / RestoreCRTMode demo"),
  918.       GetViewSettings(Left,Top,Right,Bottom,_),
  919.     SetTextJustify(center_Text,center_Text),
  920.       RL2    = (Right - Left) div 2,
  921.       BT2    = (Bottom- Top) div 2,
  922.       OutTextXY(RL2,BT2,"Now you are in graphics mode ..."),
  923.       StatusLine("Press any key for text mode ..."), readchar(_),
  924.       GetGraphMode(GraphMode),
  925.       RestoreCRTMode, /*txtMode(R,C), textmode(R,C),*/
  926.       write("\nNow you are in text mode.\n\n"),
  927.       write("\nPress any key to go back to graphics ..."), readchar(_),
  928.       SetGraphMode(GraphMode),
  929.       MainWindow("SetGraphMode / RestoreCRTMode demo"),
  930.       SetTextJustify(center_Text,center_Text),
  931.       OutTextXY(RL2,BT2,"Back in Graphics Mode ..."),
  932.       Pause.
  933.  
  934. /************************************************************************
  935.     Display the standard fill patterns available
  936. *************************************************************************/
  937.  
  938. PREDICATES
  939.   FillStyleDemo
  940.  
  941. CLAUSES
  942.   FillStyleDemo:-
  943.     MainWindow("Pre-defined Fill Styles"),
  944.     GetViewSettings(_,_,Right,Bottom,_),
  945.     W = 2*( (Right+1) div 13 ), H = 2*( (Bottom-10) div 10 ),
  946.     maxColors(MaxColors), /*MaxColors1 = MaxColors-1,*/
  947.     for (0,3,J),
  948.       Y    = H div 2 + (H div 2)*3*J,
  949.       for (0,4,I),
  950.         Style    = J*4 + I,
  951.         X        = W div 2 + (W div 2)*3*I,
  952.         Color    = (J*4+I) mod (MaxColors+1), BlackToWhite(Color,Color2),
  953.         SetFillStyle(Style,Color2),
  954.         XW = X + W, YH = Y + H,
  955.         Bar(X,Y,XW,YH),
  956.         Str_Int(Buf,Style),
  957.         XW2 = X + W div 2, YH4 = Y + H + 4,
  958.         OutTextXY(XW2,YH4,Buf),
  959.       fail.
  960.   FillStyleDemo:-
  961.       SetTextJustify(left_Text,top_Text),
  962.       Pause.
  963.  
  964. /************************************************************************
  965.     Demonstrate how to use the user definable fill patterns
  966. *************************************************************************/
  967.  
  968. PREDICATES
  969.   FillPatternDemo
  970.   UserPattern(Integer,intlist)
  971.  
  972. CLAUSES
  973.   FillPatternDemo:-
  974.     MainWindow("User Defined Fill Styles"),
  975.     GetViewSettings(_,_,Right,Bottom,_),
  976.     W = 2*( (Right+1) div 13 ), H = 2*( (Bottom-10) div 10 ),
  977.     maxColors(MaxColors),
  978.     for (0,3,J),
  979.       Y    = H div 2 + (H div 2)*3*J,
  980.       for (0,4,I),
  981.         Style = J*4 + I,
  982.         X      = W div 2 + (W div 2)*3*I,
  983.         Color = (J*4+I) mod (MaxColors+1), BlackToWhite(Color,Color2),
  984.         SetFillStyle(Style,Color2),
  985.         UserPattern(Style,UPattern),
  986.         SetFillPattern(UPattern,Color2),
  987.         XW = X + W, YH = Y + H,
  988.         Bar(X,Y,XW,YH),
  989.         Rectangle(X,Y,XW,YH),
  990.         Str_Int(Buf,Style),
  991.         XW2    = X + W div 2,
  992.         YH4    = Y + H + 4,
  993.         OutTextXY(XW2,YH4,Buf),
  994.       fail.
  995.   FillPatternDemo:-
  996.       SetTextJustify(left_Text,top_Text),
  997.       Pause.
  998.  
  999.   UserPattern(0, [$AA,    $55,    $AA,    $55,    $AA,    $55,    $AA,    $55]).
  1000.   UserPattern(1, [$33,    $33,    $CC,    $CC,    $33,    $33,    $CC,    $CC]).
  1001.   UserPattern(2, [$F0,    $F0,    $F0,    $F0,    $0F,    $0F,    $0F,    $0F]).
  1002.   UserPattern(3, [$00,    $10,    $28,    $44,    $28,    $10,    $00,    $00]).
  1003.   UserPattern(4, [$00,    $70,    $20,    $27,    $24,    $24,    $07,    $00]).
  1004.   UserPattern(5, [$00,    $00,    $00,    $18,    $18,    $00,    $00,    $00]).
  1005.   UserPattern(6, [$00,    $00,    $3C,    $3C,    $3C,    $3C,    $00,    $00]).
  1006.   UserPattern(7, [$00,    $7E,    $7E,    $7E,    $7E,    $7E,    $7E,    $00]).
  1007.   UserPattern(8, [$00,    $00,    $22,    $08,    $00,    $22,    $1C,    $00]).
  1008.   UserPattern(9, [$FF,    $7E,    $3C,    $18,    $18,    $3C,    $7E,    $FF]).
  1009.   UserPattern(10,[$00,    $10,    $10,    $7C,    $10,    $10,    $00,    $00]).
  1010.   UserPattern(11,[$00,    $42,    $24,    $18,    $18,    $24,    $42,    $00]).
  1011.  
  1012. /************************************************************************
  1013.     Display a random pattern of polygons until the user says enough
  1014. *************************************************************************/
  1015.  
  1016. Constants
  1017.   MaxPoints    = 6
  1018.  
  1019. PREDICATES
  1020.   PolyDemo
  1021.   BuildPts(Integer,Integer,Integer,Integer,Integer,intlist)
  1022.  
  1023. CLAUSES
  1024.   PolyDemo:-
  1025.     MainWindow("DrawPoly / FillPoly Demonstration"),
  1026.     StatusLine("Esc Aborts - Press a key to stop"),
  1027.     maxColors(MaxColor), /*MaxColor1 = MaxColor-1,*/
  1028.     maxX(MaxX), maxY(MaxY),
  1029.     Repeat,
  1030.       Random(MaxColor,R), Color = 1 + R,
  1031.       Random(10,R10),
  1032.       SetFillStyle(R10,Color),
  1033.       SetColor(Color),
  1034.       BuildPts(maxPoints,0,0,MaxX,MaxY,Poly),
  1035.       FillPoly(Poly),
  1036.     KeyPressed,!,
  1037.     Pause.
  1038.  
  1039.   BuildPts(0,InitX,InitY,_,_,[InitX,InitY]):-!.
  1040.   BuildPts(maxPoints,_,_,MaxX,MaxY,[X,Y|Points]):- !,
  1041.       Random(MaxX,X2),X=X2,
  1042.       Random(MaxY,Y2),Y=Y2,
  1043.       I2    = maxPoints-1,
  1044.       BuildPts(I2,X2,Y2,MaxX,MaxY,Points).
  1045.   BuildPts(I,Ix1,Iy1,MaxX,MaxY,[X,Y|Points]):- !,
  1046.         Ix=Ix1,  Iy=Iy1,
  1047.       Random(MaxY,X),
  1048.       Random(MaxY,Y),
  1049.       I2    = I -1,
  1050.       BuildPts(I2,Ix,Iy,MaxX,MaxY,Points).
  1051.  
  1052. /************************************************************************
  1053.     Give a closing screen to the user before leaving
  1054. *************************************************************************/
  1055.  
  1056. PREDICATES
  1057.   SayGoodBye
  1058.  
  1059. CLAUSES
  1060.   SayGoodBye:-
  1061.       MainWindow("== Finale =="),
  1062.     GetViewSettings(Left,Top,Right,Bottom,_),
  1063.     SetTextStyle(gOTHIC_FONT,horiz_Dir,5),
  1064.     SetTextJustify(center_Text,center_Text),
  1065.     maxColors(MaxColor), Color = 1+round(MaxColor / 2.5),
  1066.     SetColor(Color),
  1067.     H = Bottom - Top, W = Right  - Left,
  1068.     W2 = W div 2, H2 = H div 2,
  1069.     OutTextXY(W2,H2,"That's all folks!"),
  1070.     StatusLine("Press any key to Exit"),
  1071.     readchar(_),
  1072.     ClearDevice.
  1073.  
  1074. /************************************************************************
  1075.     Display the current color palette on the screen
  1076. *************************************************************************/
  1077.  
  1078. PREDICATES
  1079.   ColorDemo
  1080.  
  1081. CLAUSES
  1082.   ColorDemo:-
  1083.     MainWindow("Color Demonstration"),
  1084.     GetViewSettings(_,_,Right,Bottom,_),
  1085.     Width  = 2*( (Right+1) div 16 ),
  1086.     Height = 2*( (Bottom-10) div 10 ),
  1087.     maxColors(MaxColors),
  1088.     for (0,3,J),
  1089.       for (0,5,I),
  1090.           Color = (5*J + I+1) mod (MaxColors+1),
  1091.         X    = Width div 2  + (Width div 2) * 3*I,
  1092.         Y    = Height div 2 + (Height div 2)* 3*J,
  1093.         SetFillStyle(solid_Fill,Color),
  1094.         SetColor(Color),
  1095.         XW = X+Width, YH = Y + Height,
  1096.         Bar(X,Y,XW,YH),
  1097.         BlackToWhite(Color,Color2), SetColor(Color2),
  1098.         Rectangle(X,Y,XW,YH),
  1099.         str_int(Cnum,Color),
  1100.         XW2 = X+(Width div 2),  YH4 = Y + Height +4,
  1101.         OutTextXY(XW2,YH4, Cnum),
  1102.       fail.
  1103.   ColorDemo:- Pause.
  1104.  
  1105. /************************************************************************
  1106.     Display a pattern of random dots on the screen
  1107.     and pick them back up again
  1108. *************************************************************************/
  1109.  
  1110. DOMAINS
  1111.   Pixel     = p(Integer,Integer,Integer)
  1112.   PixelList = Pixel*
  1113.  
  1114. PREDICATES
  1115.   PutPixelDemo
  1116.   PutPixels(Pixellist,Integer,Integer,Integer,Integer)
  1117.   OutPixels(Pixellist)
  1118.   DelPIxels(Pixellist)
  1119.  
  1120. CLAUSES
  1121.   PutPixelDemo:-
  1122.     MainWindow("PutPixel Demonstration"),
  1123.     GetViewSettings(Left,Top,Right,Bottom,_),
  1124.     H = Bottom - Top,
  1125.     W = Right - Left,
  1126.     maxColors(MaxColors),
  1127.      PutPixels(Points,5000,H,W,Maxcolors),
  1128.     DelPixels(Points),
  1129.     for (0,2,I),
  1130.       OutPixels(Points),
  1131.       I<1,
  1132.       DelPixels(Points),
  1133.     fail.
  1134.   PutPixelDemo:-
  1135.     Pause.
  1136.  
  1137.   PutPixels([],0,_,_,_):- !.
  1138.   PutPixels([p(X,Y,Color)|Points],I,H,W,Maxcolors):-
  1139.       random(W,X),
  1140.       random(H,Y),
  1141.       random(MaxColors,Color),
  1142.       PutPixel(X,Y,Color),
  1143.       I2 = I - 1,!,
  1144.       PutPixels(Points,I2,H,W,Maxcolors).
  1145.  
  1146.   OutPixels([p(X,Y,Color)|Points]):-!,
  1147.       PutPixel(X,Y,Color),
  1148.       OutPixels(Points).
  1149.   OutPixels(_).
  1150.  
  1151.   DelPixels([p(X,Y,_)|Points]):- !,PutPixel(X,Y,black),DelPixels(Points).
  1152.   DelPixels(_).
  1153.  
  1154. /************************************************************************
  1155.      Displays a random pattern of polygons until the user says enough
  1156. *************************************************************************/
  1157.  
  1158. PREDICATES
  1159.   PaletteDemo
  1160.   PaletteDemo2(Integer)
  1161.   PaletteDemo3
  1162.  
  1163. CLAUSES
  1164.   PaletteDemo:-
  1165.     GetPalette(PaletteList),
  1166.     driver(GraphDriver,_,_),
  1167.     PaletteDemo2(GraphDriver),
  1168.     setallpalette(PaletteList).
  1169.  
  1170.   Palettedemo2(ega):- Palettedemo3,!.
  1171.   Palettedemo2(vga):- Palettedemo3,!.
  1172.   Palettedemo2(_).
  1173.  
  1174.   PaletteDemo3:-
  1175.     MainWindow("Palette Demonstration"),
  1176.     StatusLine("Press any key to continue, Esc to Abort"),
  1177.     GetViewSettings(Left,Top,Right,Bottom,_),
  1178.     Width    = (Right-Left) div 15,
  1179.     Height    = (Bottom-Top) div 10,
  1180.     maxColors(MaxColors),
  1181.     for (0,10,J),
  1182.       Y      = (Height+1)*J,
  1183.       for (0,15,I),
  1184.         Color = 1 + ((J*15 + I)*2) mod (MaxColors-2),
  1185.         X      = (Width+1)*I,
  1186.         SetFillStyle(solid_Fill,Color),
  1187.         XW      = X + Width,
  1188.         YH      = Y + Height,
  1189.         Bar(X,Y,XW,YH),
  1190.       fail.
  1191.   PaletteDemo3:-
  1192.       maxColors(MaxColors),MAX1=MaxColors-2,
  1193.       Repeat,
  1194.         random(MAX1,R), RMax = 1 + R,
  1195.         random(65,R65),
  1196.         SetPalette(RMax,R65),
  1197.       KeyPressed,!,Pause.
  1198.  
  1199. /************************************************************************
  1200.     Main GOAL
  1201. ************************************************************************/
  1202.  
  1203. Goal    Initialize,    % Set system into graphic mode
  1204.         ReportStatus,
  1205.         ColorDemo,
  1206.         PaletteDemo,
  1207.         GraphDefaults,
  1208.         PutPixelDemo,
  1209.         ArcDemo,
  1210.         CircleDemo,
  1211.         Bar3DDemo,
  1212.         BarDemo,
  1213.         PieDemo,
  1214.         LineRelDemo,
  1215.         LineToDemo,
  1216.         LineStyleDemo,
  1217.         UserLineStyleDemo,
  1218.         TextDump,
  1219.         TextDemo,
  1220.         CRTModeDemo,
  1221.         FillStyleDemo,
  1222.         FillPatternDemo,
  1223.         PolyDemo,
  1224.         SayGoodBye,
  1225.     ToText.
  1226.  
  1227.