home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / GRAPHICS / PLOT / SURFUTI3.ZIP / REV.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1991-11-19  |  18.4 KB  |  571 lines

  1. program revolution;
  2. uses crt,surfgraf;
  3. { Written by Ian Murphy }
  4.  
  5. { fri 6th-nov-87 : wrote most of code, addpoint/insert/delete/move, very buggy
  6.   mon 9th-nov-87 : noticed the pointer bug, couldn't track it down.
  7.                    added redraw/ select point.
  8.   tue 10th-nov-87: Found&fixed the above bug. added axes, menu for params
  9.   wed 11th-nov-87: improved parameters menu, added saving data
  10.   thur12th-nov-87: tidied up the bits and pieces
  11.  
  12.   16 Jan. 1987:    Re-written in turbo 4 by Kevin Lowey
  13.   }
  14.  
  15.  
  16.  
  17. { Global variables and constants for SURFMODL }
  18.  
  19.  
  20. const
  21.       spc = ' ';
  22.       shapecode = 2; { surface of revolution}
  23.       maxpts= 100;
  24.       up    = 242; down =250;  left = 245;
  25.       right = 247; esc  =27;   space= 32;
  26.       ret   = 13;
  27.       blank = 0;
  28.       MAXVAR = 20;          { maximum # of numeric inputs on a line }
  29.  
  30. type anystring = string[80];
  31.      vartype = array[1..MAXVAR] of real;
  32.      text80 = string[80];
  33. var
  34.     version,nmatl,maxvert,nsides  : integer;
  35.     r1,r2,r3,ambient : real; color : integer;
  36.     noutln,nslice,material,orient  : integer;
  37.     xscale,yscale,zscale,xshift,yshift,zshift : real;
  38.     xrotate,yrotate,zrotate : real;
  39.     x,y,ptr : array [1..maxpts] of integer;
  40.     firstpt,finalpt,lastpt,numpts,nextpt,curpt : integer;
  41.     i,j,ch : integer;
  42.     mono,arrow,debug,debug2 : boolean ;
  43.     infile,outfile  : text;
  44.     infilename,outfilename : text80;
  45.     title : text80;
  46.     flpurpose : text80;
  47.     gxcenter,gycenter : integer;
  48.     linecolor, linecolor2 : integer;
  49.     hilite : integer;
  50.     ngraphchar : integer;
  51.     tbinit : boolean;
  52.     sys : integer;
  53.     sys_type_set : boolean;
  54.     xfactor : real;
  55.     period : integer;
  56.     prefilename, batfilename : text80;
  57.     { Following vbls not used, but defined only to allow compilation
  58.       of drawplot.pas }
  59.     dorandom : boolean;
  60.     randshade : real;
  61.  
  62. { Dummy STOPSTAT procedure for REVOLUTE }
  63. procedure STOPSTAT;
  64. begin
  65. end;
  66.  
  67. {$i colormod.inc}
  68. {$i oinreal.inc}
  69.  
  70.  
  71. procedure msg(s:anystring);
  72. begin
  73.    if (Ngraphchar >= 40) then begin
  74.      gotoxy (1,2);
  75.      write ('                                              ');
  76.      gotoxy (1,2);
  77.      write (s);
  78.    end;
  79. end;
  80.  
  81. procedure tmsg(s:anystring);
  82. { same as msg, but used in textmode so it doesn't matter whether the system
  83.   has ability to display characters on the graphics screen }
  84. begin
  85.      gotoxy (1,2);
  86.      write ('                                              ');
  87.      gotoxy (1,2);
  88.      write (s);
  89. end;
  90.  
  91. function next_free_pt:integer;
  92. var i : integer;
  93. begin
  94.      if debug then msg('Next_free_pt');
  95.      i := 0;
  96.      repeat
  97.            i := i +1;
  98.      until (x[i] =0) and (y[i]=0);
  99.      next_free_pt := i;
  100. end;
  101.  
  102. function getch:integer;
  103. var ch:char;
  104. begin
  105.      if debug then msg('readch');
  106.      ch := readkey;
  107.      arrow :=false;
  108.      if ((ch=#0) and keypressed) then
  109.      begin
  110.           arrow:=true;
  111.           ch := readkey;
  112.      end;
  113.      if arrow then getch:=ord(ch)+170
  114.      else getch:=ord(ch)
  115. end;
  116.  
  117. function ptrto(cp:integer):integer;
  118. var x,lastx : integer;
  119. begin
  120.      if debug then msg('ptrto');
  121.      x:= firstpt;
  122.      repeat
  123.            if debug2 then writeln ('cp ',cp,' ptr[',x,']=',ptr[x]);
  124.            lastx :=x;
  125.            x := ptr[x];
  126.            if debug2 then write (x);
  127.      until (x=cp)or(x=0);
  128.      ptrto := lastx;
  129.      if debug2 then writeln ('cp ',cp,' ptr[',x,']=',ptr[x]);
  130. end;
  131.  
  132. procedure drawcross(cp,color:integer);
  133. const crossize = 3;
  134. begin
  135.      if debug then msg('drawcross');
  136.      gdraw (x[cp]-crossize,y[cp],x[cp]+crossize,y[cp],color);
  137.      gdraw (x[cp],y[cp]-crossize,x[cp],y[cp]+crossize,color);
  138. end;
  139.  
  140. procedure split (var cp:integer);
  141. var np,lp :integer;
  142. begin
  143.      if debug then msg('split');
  144.      if cp <>firstpt then cp := ptrto(cp);
  145.      np := ptr[cp];
  146.      lp := cp;
  147.      cp := next_free_pt;
  148.      if debug2 then writeln ('lp=',lp,' cp=',cp,' np=',np);
  149.      x[cp] := round((x[lp]+x[np])/2);
  150.      y[cp] := round((y[lp]+y[np])/2);
  151.      ptr[lp] := cp;
  152.      ptr[cp] := np;
  153.      numpts := numpts +1;
  154. end;
  155.  
  156. procedure redraw;
  157. var cp,lp,np,k:integer;
  158. begin
  159.      if debug then msg ('redraw');
  160.      cp := firstpt;
  161.      setgmode;
  162.      gotoxy(1,1);
  163.      if (Ngraphchar >= 80) then
  164.        writeln ('Addpoint Delete Insert Move Redraw Params Writedata')
  165.      else if (Ngraphchar >= 40) then
  166.        writeln ('Add Del Ins Move Redraw Params Write');
  167.      { Hercules users get no text on graphics screen }
  168.  
  169.      gdraw (gxmin,gycenter,gxmax,gycenter,1);
  170.      gdraw (gxcenter,gymin,gxcenter,gymax,1);
  171.  
  172.      repeat
  173.            if debug2 then write (cp:2);
  174.            np := ptr[cp];
  175.            gdraw (x[cp],y[cp],x[np],y[np],linecolor);
  176.            cp := np;
  177.      until ptr[np]=0;
  178. end;
  179.  
  180. procedure pickpoint(var cp:integer;var ch: integer);
  181. var lp,np,tmpcp : integer;
  182. begin
  183.      msg('pick a point');
  184.      tmpcp := cp;
  185.      drawcross(cp,hilite);
  186.      repeat
  187.            ch := getch;
  188.            case ch of
  189.                 right : if cp<>finalpt then
  190.                         begin
  191.                              drawcross(cp,blank);
  192.                              cp := ptr[cp];
  193.                              drawcross(cp,hilite);
  194.                         end;
  195.                 left  : if cp<>firstpt then
  196.                         begin
  197.                              drawcross(cp,blank);
  198.                              cp := ptrto(cp);
  199.                              drawcross(cp,hilite);
  200.                         end;
  201.            end;{case ch of}
  202.     until not(ch in [left,right]);
  203.     drawcross(cp,blank);
  204.     if ch=esc then cp := tmpcp;
  205.     msg('            ');
  206. end;
  207.  
  208. procedure move(cp:integer);
  209. var lp,np,ch,tmpcpx,tmpcpy : integer;
  210. begin
  211.      msg('move the pt');
  212.      if cp=firstpt then lp:=firstpt
  213.         else lp := ptrto(cp);
  214.      if cp=finalpt then np:=finalpt
  215.         else np := ptr[cp];
  216.      tmpcpx := x[cp]; tmpcpy := y[cp];
  217.      gdraw (x[cp],y[cp],x[lp],y[lp],linecolor2);
  218.      gdraw (x[cp],y[cp],x[np],y[np],linecolor2);
  219.      repeat
  220.            ch := getch;
  221.            gdraw (x[cp],y[cp],x[lp],y[lp],blank);
  222.            gdraw (x[cp],y[cp],x[np],y[np],blank);
  223.  
  224.            case ch of
  225.                 left : if x[cp] > gxmin then x[cp] := x[cp] -1;
  226.                 right: if x[cp] < gxmax then x[cp] := x[cp] +1;
  227.                 up   : if y[cp] > gymin then y[cp] := y[cp] -1;
  228.                 down : if y[cp] < gymax then y[cp] := y[cp] +1;
  229.            end; {case}
  230.            gdraw (x[cp],y[cp],x[lp],y[lp],linecolor);
  231.            gdraw (x[cp],y[cp],x[np],y[np],linecolor);
  232.      until not(ch in [up,down,left,right]);
  233.      if ch = esc then
  234.      begin
  235.            gdraw (x[cp],y[cp],x[lp],y[lp],blank);
  236.            gdraw (x[cp],y[cp],x[np],y[np],blank);
  237.            x[cp] := tmpcpx; y[cp] := tmpcpy;
  238.            gdraw (x[cp],y[cp],x[lp],y[lp],linecolor);
  239.            gdraw (x[cp],y[cp],x[np],y[np],linecolor);
  240.      end;
  241.      msg('           ');
  242. end;
  243.  
  244. procedure addpoint(var cp:integer);
  245. var lp,np : integer;
  246. begin
  247.      if debug then msg('addpoint');
  248.      if cp = firstpt then
  249.      begin
  250.           lp := next_free_pt;
  251.           firstpt := lp;
  252.           ptr[lp] := cp;
  253.           x[lp] := x[cp];
  254.           y[lp] := y[cp];
  255.           cp := lp;
  256.           move(cp);
  257.           numpts := numpts +1;
  258.      end
  259.      else
  260.      if cp = finalpt then
  261.      begin
  262.           cp  := finalpt;
  263.           np := next_free_pt;
  264.           finalpt:= np;
  265.           ptr[cp]  := np;
  266.           ptr[lp] := cp;
  267.           x[np] := x[cp];
  268.           y[np] := y[cp];
  269.           cp := finalpt;
  270.           move (cp);
  271.           numpts := numpts +1;
  272.      end
  273.      else
  274.      msg ('You must be at either one of the ends');
  275. end;
  276.  
  277. procedure setparams;
  278. var i,chh,num : integer;
  279.     ch : char;
  280.     Realvar: vartype;      { variables from input }
  281.     Comment: text80;       { user's comment }
  282.  
  283. begin
  284.      nmatl := 1; version := 1;
  285.      maxvert := 4; nsides := 1;
  286.      noutln := numpts;
  287.      repeat
  288. {          clrscr;
  289.            lowvideo;
  290. }
  291.            gotoxy (1,5);
  292.            writeln ('1) r1,r2,r3 ',r1:6:2,spc ,r2:6:2,spc ,r3:6:2);
  293.            writeln ('2) ambient light intensity  ',ambient:6:3);
  294.            writeln ('3) number of points         ',noutln);
  295.            writeln ('4) number of angular slices ',nslice);
  296.            writeln ('5) number of materials   ',nmatl);
  297.            writeln ('6) orientation code      ',orient);
  298.            writeln ('7) scaling factors x,y,z      :',
  299.                      xscale:6:2,spc ,yscale:6:2,spc ,zscale:6:2);
  300.            writeln ('8) displacement factors x,y,z :',
  301.                      xshift:6:2,spc ,yshift:6:2,spc ,zshift:6:2);
  302.            writeln ('9) rotation around x,y,z      :  ',
  303.                      xrotate:6:2,'    ',yrotate:6:2,'     ',zrotate:6:2);
  304.  {         highvideo; }
  305.  
  306.            tmsg (' choose which one to change');
  307.            repeat chh := getch; until chh in [48..57,13];
  308.  
  309.            ch := chr(chh);
  310.            case ch of
  311.            '1' : begin
  312.                     repeat
  313.                        tmsg ('enter r1,r2,r3 : ');
  314.                        num := inreal(input,realvar,comment,0,true);
  315.                        if num=3 then
  316.                        begin
  317.                             r1 := realvar[1];
  318.                             r2 := realvar[2];
  319.                             r3 := realvar[3];
  320.                        end
  321.                        else if num >0 then
  322.                        begin
  323.                             tmsg('expecting 3 numeric values.');
  324.                             delay (1500);
  325.                        end;
  326.                     until (num=0) or (num=3);
  327.                end;
  328.            '2' : begin
  329.                     repeat
  330.                        tmsg ('enter ambient light intensity : ');
  331.                        num := inreal(input,realvar,comment,0,true);
  332.                        if num=1 then ambient := realvar[1]
  333.                        else if num >0 then
  334.                        begin
  335.                             tmsg('expecting 1 numeric value.');
  336.                             delay (1500);
  337.                        end;
  338.                     until (num=0) or (num=1);
  339.  
  340.                end;
  341.            '3' : begin tmsg ('Not settable'); delay(1000);end;
  342.            '4' : begin
  343.                       tmsg ('enter number of angular slices to take : ');
  344.                       readln (nslice);
  345.                  end;
  346.            '5' : begin tmsg ('not settable..defaults to 1'); delay(1000);end;
  347.            '6' : begin tmsg ('not settable..defaults to 3'); delay(1000);end;
  348.            '7' : begin
  349.                     repeat
  350.                        tmsg ('enter scaling factors for x,y,z : ');
  351.                        num := inreal(input,realvar,comment,0,true);
  352.                        if num=3 then
  353.                        begin
  354.                             xscale := realvar[1];
  355.                             yscale := realvar[2];
  356.                             zscale := realvar[3];
  357.                        end
  358.                        else if num >0 then
  359.                        begin
  360.                             tmsg('expecting 3 numeric values.');
  361.                             delay (1500);
  362.                        end;
  363.                     until (num=0) or (num=3);
  364.                end;
  365.            '8' : begin
  366.                     repeat
  367.                        tmsg ('enter disp. factors for x,y,z : ');
  368.                        num := inreal(input,realvar,comment,0,true);
  369.                        if num=3 then
  370.                        begin
  371.                             xshift := realvar[1];
  372.                             yshift := realvar[2];
  373.                             zshift := realvar[3];
  374.                        end
  375.                        else if num >0 then
  376.                        begin
  377.                             tmsg('expecting 3 numeric values.');
  378.                             delay (1500);
  379.                        end;
  380.                     until (num=0) or (num=3);
  381.                end;
  382.            '9' : begin
  383.                     repeat
  384.                        tmsg ('enter rotation for x,y,z (deg) : ');
  385.                        num := inreal(input,realvar,comment,0,true);
  386.                        if num=3 then
  387.                        begin
  388.                             xrotate := realvar[1];
  389.                             yrotate := realvar[2];
  390.                             zrotate := realvar[3];
  391.                        end
  392.                        else if num >0 then
  393.                        begin
  394.                             tmsg('expecting 3 numeric values.');
  395.                             delay (1500);
  396.                        end;
  397.                     until (num=0) or (num=3);
  398.                end;
  399.            end; {case}
  400.     until (chh = 48) or (chh=ret);
  401. end;
  402.  
  403. procedure writedata;
  404. var cp,lp,np,k:integer;
  405.     ch :char;
  406.  
  407. begin
  408.      tmsg ('Do you really want to save the data (Y/N)');
  409.      ch := readkey;
  410.      if ch in ['Y','y'] then
  411.      begin
  412.           if outfilename = '' then
  413.           begin
  414.                tmsg ('File name : ');
  415.                readln (outfilename);
  416.                tmsg ('Plot title : ');
  417.                readln (title);
  418.                { Strip any filename extension off the name }
  419.                period := pos ('.', outfilename);
  420.                if (period > 0) then
  421.                  outfilename := copy (outfilename, 1, period-1);
  422.                { PREPROC file has a .IN extension }
  423.                prefilename := outfilename + '.IN';
  424.                { Batch file has a .BAT extension }
  425.                batfilename := outfilename + '.BAT';
  426.           end;
  427.           assign (outfile,prefilename);
  428.           rewrite (outfile);
  429.  
  430.           writeln (outfile,title);
  431.           writeln (outfile,version);
  432.           writeln (outfile,nmatl:3,maxvert:3,nsides:3);
  433.           writeln (outfile, r1:3:1,spc ,r2:3:1,spc ,r3:3:1,spc
  434.                           ,color:3,spc ,ambient:3:1);
  435.           writeln (outfile,shapecode);
  436.           writeln (outfile,numpts:4  ,nslice:4 ,material:3 ,orient:3);
  437.           write   (outfile,xscale:3:1,spc ,yscale:3:1,spc ,zscale:3:1,spc );
  438.           writeln (outfile,xshift:3:1,spc ,yshift:3:1,spc ,zshift:3:1);
  439.           writeln (outfile,xrotate:3:1,spc ,yrotate:3:1,spc ,zrotate:3:1);
  440.           cp := firstpt;
  441.           repeat
  442.                 writeln (outfile, xfactor*(x[cp]-gxcenter),
  443.                          spc ,gycenter-y[cp]);
  444.                 cp := ptr[cp];
  445.           until ptr[cp]=0;
  446.           { one more write for the last point }
  447.           writeln (outfile, xfactor*(x[cp]-gxcenter),
  448.                    spc ,gycenter-y[cp]);
  449.           writeln (outfile,0);
  450.           close (outfile);
  451.  
  452.           { Now write the batch file }
  453.           assign (outfile,batfilename);
  454.           rewrite (outfile);
  455.           writeln (outfile, 'PREPROC ', prefilename, ' ', outfilename);
  456.           writeln (outfile, 'SURFMODL ', outfilename);
  457.           close (outfile);
  458.           writeln ('To view this file in SURFMODL, just type "',
  459.                    outfilename,'"');
  460.           delay(1500);
  461.      end;
  462. end;
  463.  
  464. begin { main }
  465.      tbinit := false;
  466.      sys_type_set := false;
  467.      flpurpose := '';
  468.      setsys; { set gxmin,gxmax,gymin,gymax,ngraphchar & ncolors }
  469.      { 9.375 is x dimension of screen in inches; 6.625 is y dimension. }
  470.      xfactor := ((Gymax - Gymin) / (Gxmax - Gxmin)) * 9.375 / 6.625;
  471.      debug := false;
  472.      debug2 := false;
  473.      for i := 1 to maxpts do
  474.      begin
  475.           x[i] := 0;  y[i] := 0; ptr[i] :=0;
  476.      end;
  477.      version:= 1; nmatl := 1; maxvert :=4 ;
  478.      nsides := 1; r1 := 1; r2 := 1; r3 := 1;
  479.      ambient:=0.2;color  := 1; noutln  := 1;
  480.      nslice := 20; orient := 3; material:= 1;
  481.      xscale := 1; yscale := 1; zscale :=1;
  482.      xshift := 0; yshift := 0; zshift :=0;
  483.      xrotate:= 0; yrotate:= 0; zrotate:=0;
  484.      if (ncolors > 1) then
  485.        linecolor := 2
  486.      else
  487.        linecolor := 1;
  488.      if (ncolors > 2) then
  489.        linecolor2 := 3
  490.      else
  491.        linecolor2 := 1;
  492.      if (ncolors >= 12) then
  493.        hilite := 12
  494.      else if (ncolors >= 4) then
  495.        hilite := 4
  496.      else
  497.        hilite := 1;
  498.  
  499.      numpts := 2; lastpt  := 1; nextpt  := 1;
  500.      curpt  := 2; firstpt := 1; finalpt := 2;
  501.      gxcenter := round(gxmax/2);
  502.      gycenter := round(gymax/2);
  503.      x[1]   := gxcenter-50; y[1]  := gycenter-10; ptr[1] := 2;
  504.      x[2]   := gxcenter-10; y[2]  := gycenter-10; ptr[2] := 0;
  505.      outfilename :='';
  506.      setgmode;
  507.      redraw;
  508.  
  509.      repeat
  510.            drawcross(curpt,hilite);
  511.            ch :=0;
  512.            repeat pickpoint (curpt,ch);
  513.            until (upcase(chr(ch)) in ['A','I','D','M','R','P','W'])
  514.                  or (ch in [up,down,left,right,esc]);
  515.            drawcross(curpt,blank);
  516.  
  517.            case upcase(CHR(ch)) of
  518.            'A' : addpoint (curpt);
  519.            'I' : begin
  520.                       pickpoint(curpt,ch);
  521.                       split(curpt);
  522.                       move (curpt);
  523.                   end;
  524.            'D' : begin
  525.                       pickpoint(curpt,ch);
  526.                       if curpt=firstpt then
  527.                       begin
  528.                            firstpt := ptr[curpt];
  529.                            x[curpt]:=0; y[curpt]:=0;
  530.                            curpt:=firstpt;
  531.                       end
  532.                       else if curpt=finalpt then
  533.                       begin
  534.                            x[curpt]:=0; y[curpt]:=0;
  535.                            curpt := ptrto(curpt);
  536.                            ptr[curpt]:=0;
  537.                            finalpt:=curpt;
  538.                       end
  539.                       else
  540.                       begin
  541.                            lastpt := ptrto(curpt);
  542.                            nextpt := ptr[curpt];
  543.                            x[curpt] := 0;
  544.                            y[curpt] := 0;
  545.                            ptr[lastpt] := nextpt;
  546.                            curpt := lastpt;
  547.                       end;
  548.                       numpts := numpts -1;
  549.                  end;
  550.            'M' : move(curpt);
  551.            'R' : redraw;
  552.            'P' : begin
  553.                       exgraphic;
  554.                       setparams;
  555.                       setgmode;
  556.                       redraw;
  557.                  end;
  558.            'W' : begin
  559.                       exgraphic;
  560.                       writedata;
  561.                       setgmode;
  562.                       redraw;
  563.                  end;
  564.            end;{case ch of}
  565.            if arrow = true then pickpoint(curpt,ch);
  566.      until (ch=esc);
  567.      exgraphic;
  568.      writeln ('Finished....');
  569. end.
  570. 
  571.