home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / borland / jnfb88.arc / LCV1N2.ARC / P-BAR.PRO < prev   
Text File  |  1987-10-27  |  3KB  |  87 lines

  1. /* Listing 1 -- PROLOG MAIN MODULE */
  2.  
  3. global predicates
  4.    draw_bar(integer,integer,integer,integer) - 
  5.                        (i,i,i,i) language c
  6.    clear_screen language c
  7.    remove_cursor language c
  8.    draw_axis language c
  9.    restore_cursor language c
  10.  
  11. predicates
  12.    main
  13.    process
  14.    set_up_bar(integer,integer,integer,integer,real)
  15.  
  16. goal                             /* PROLOG module must contain */
  17.    main.                     /* a GOAL in order to compile */
  18.                          /* to .OBJ. */
  19.  
  20. clauses
  21.    main:-                         /* Set up user interface. */
  22.       makewindow(1,7,7,"Graphics",0,0,25,80),
  23.       process.                  /* Process the problem. */
  24.    main:-                         /* Continue? */
  25.       write("Do you want to continue? y or n"),
  26.       readchar(Answer), Answer = 'y',
  27.       main.                     /* Call main recursively. */
  28.    main:-               /* We're done. */
  29.       nl,write("Press any key to end."),
  30.       readchar(_),            
  31.       clear_screen(),          /* Clean up for next applic.*/
  32.       restore_cursor().
  33.  
  34.    process:-              /* Process the problem. */
  35.       write("Enter the number of bars: "), 
  36.       readint(NumOfBars),
  37.       clearwindow,
  38.       NumOfBars <= 10,          /* The system is currently */
  39.                                 /* set up to handle 10 bars.*/
  40.       write("Enter max value on Y scale: "),
  41.       readint(Max),
  42.       Max > 0,                  /* Avoid division by zero. */
  43.       clearwindow,
  44.       YScale = 18/Max,          /* Our axis is currently set */
  45.                   /*   up as 18 by 60. */
  46.       Width = 60/NumOfBars,
  47.       Xstart = 2,          /* Start the first bar next */
  48.                   /*   to the y axis. */
  49.       clear_screen(),           /* Call C functions. */
  50.       remove_cursor(),          /* Who needs it? */
  51.       draw_axis(),
  52.       Num = 1,                  /* Set Num for first bar. */
  53.                   /* And begin. */
  54.       set_up_bar(Num,NumOfBars, Width, Xstart, Yscale),
  55.       fail.                     /* Fail when we're finished */
  56.                   /*  and reclaim memory. */
  57.             
  58.                   /* Error report. */
  59.    process:-        
  60.       write("System is currently set up to draw 10 bars"),
  61.       write(" & Y > 0, <= 30,000 max."),
  62.       nl, fail.         
  63.               
  64.    set_up_bar(0,_,_,_,_):-!.         /* There are no bars to */
  65.                   /* process, so we're done. */
  66.    set_up_bar(Num,NumOfBars,Width,Xstart,Yscale):-
  67.       Num <= NumOfBars,         /* Are we done? */
  68.       write("Enter the value for bar ",Num ,": "),
  69.       readint(Y),
  70.       Height=Y*YScale,          /* Calculate height of bar. */
  71.                       /* Call C function to draw. */
  72.       Height <= 18,             /* Value <= Y max? */
  73.       draw_bar(Num,Xstart,Height,Width),
  74.                   /* Get next x position. */
  75.       XNewPos= Xstart + Width + 1,
  76.       XNuNew=Num + 1,           /* Keep count of bars. */
  77.                   /* Continue getting bar */ 
  78.                   /* values until we're done. */
  79.       !,set_up_bar(XNuNew,NumOfBars,Width,XNewPos,Yscale).
  80.    set_up_bar(Num,NumOfBars,_,_,_):-
  81.       Num >= NumOfBars,!.         /* We're done. */
  82.    set_up_bar(Num,NumOfBars,_,_,_):-
  83.       Num <= NumOfBars,         /* There's an input error. */
  84.       write("Bar value exceeds Y max."),
  85.       !.
  86.  
  87.