home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / games / stdemo.zip / STDEMO.C
Text File  |  1989-03-20  |  10KB  |  368 lines

  1. Article 2689 (41 more) in net.sources:
  2. From: ravi@eneevax.UUCP (Ravi Kulkarni)
  3. Newsgroups: net.micro.atari,net.sources
  4. Subject: ST Graphics demos (source) - long
  5. Message-ID: <355@eneevax.UUCP>
  6. Date: 26 Aug 85 14:43:04 GMT
  7. Date-Received: 28 Aug 85 09:03:29 GMT
  8. Distribution: net
  9. Organization: U of Maryland, EE Dept., College Park, MD
  10. Lines: 356
  11.  
  12. --MORE--(8%)Here are a few graphics demos that I ported from the sun. They run fine
  13. on my monochrome monitor, but I haven't tried it with a color monitor.
  14. I would imagine that they will run but without any color. You need the
  15. DR C development system or other c compiler with the gem bindings. No
  16. fancy windowing but they show the graphics capability of the ST very
  17. nicely.
  18.  
  19. -------------------------------------------------------------------------
  20. : Run this shell script with "sh" not "csh"
  21. PATH=:/bin:/usr/bin:/usr/ucb
  22. export PATH
  23. all=FALSE
  24. if [ $1x = -ax ]; then
  25.         all=TRUE
  26. fi
  27. /bin/echo 'Extracting qix.inp'
  28. sed 's/^X//' <<'//go.sysin dd *' >qix.inp
  29. [u] qix.68k=apstart,qix,aesbind,vdibind,osbind
  30. //go.sysin dd *
  31. made=TRUE
  32. if [ $made = TRUE ]; then
  33.         /bin/chmod 644 qix.inp
  34.         /bin/echo -n '  '; /bin/ls -ld qix.inp
  35. fi
  36. /bin/echo 'Extracting qix.c'
  37. sed 's/^X//' <<'//go.sysin dd *' >qix.c
  38. #include <osbind.h>
  39.  
  40. #define Chance 80
  41. #define Div 5
  42. #define Diff 4
  43. #define Max 20
  44. #define Nqix 50
  45. #define abs(x) ((x)<0?(-(x)):(x))
  46.  
  47. int contrl[12], intin[256], ptsin[256], intout[256], ptsout[256];
  48. int i,evwhich,dummy,rand,handle;
  49. int xstart,ystart,xwidth,ywidth,xcen,ycen;
  50. int pxy[4],mx;
  51. long    Randx=1;
  52.  
  53. main()
  54. {
  55.         /* Set the system up to do GEM calls */
  56.         appl_init();
  57.  
  58.         /* Get the handle of the desktop */
  59.  
  60.         handle=graf_handle(&dummy,&dummy,&dummy,&dummy);
  61.  
  62.         /* Open the workstation. */
  63.  
  64.         for(i=1; i<10; ++i)  intin[i] = 1;
  65.         intin[10] = 2;
  66.  
  67.         v_opnvwk(intin, &handle, intout);
  68.         pxy[0]=0; 
  69.         pxy[1]=0;
  70.         pxy[2]=intout[0];
  71.         pxy[3]=intout[1];
  72.         xwidth=pxy[2]; 
  73.         ywidth= pxy[3];
  74.         graf_mouse(0,i);
  75.         draw_sample();
  76.         v_clsvwk(handle);
  77.  
  78.         /* Release GEM calls */
  79.  
  80.         appl_exit();
  81.  
  82.  
  83. }
  84.  
  85.  
  86. draw_sample()
  87. {
  88.         int   temp[4], rgb_in[4], iter, loop;
  89.         int   dx0, dy0, dx1, dy1;
  90.         int   x0[Nqix], x1[Nqix], y0[Nqix], y1[Nqix];
  91.         int   flag;
  92.  
  93.  
  94.         v_clrwk(handle);
  95.         vswr_mode(handle,3);
  96.         Srand( (long) Gettime());
  97.         i=0;
  98.         flag=0;
  99.         dx0=5;
  100.         dy0=2;
  101.         dx1= -4;
  102.         dy1=3;
  103.         x0[0] = (int)(xwidth/3);
  104.         y0[0] = (int)(ywidth/3);
  105.         x1[0] = (int)(2*xwidth/3);
  106.         y1[0] = (int)(2*ywidth/3);
  107.  
  108.         while (!Bconstat(2)){
  109.                 if (flag)
  110.                         Vector( x0[i], y0[i], x1[i], y1[i]);
  111.                 Vector( bounce(x0, i, &dx0, xwidth-1),
  112.                 bounce(y0, i, &dy0, ywidth-1),
  113.                 bounce(x1, i, &dx1, xwidth-1),
  114.                 bounce(y1, i, &dy1, ywidth-1));
  115.  
  116.                 if (++i >= Nqix) {
  117.                         i=0;
  118.                         flag=1;
  119.                 }
  120.         }
  121.  
  122.  
  123.         Vector(x0[i], y0[i], x1[i], y1[i]);
  124.  
  125.         for(flag=(i+1)%Nqix;flag!=i;flag=(flag+1)%Nqix)
  126.                 Vector(x0[flag], y0[flag], x1[flag], y1[flag]);
  127. }
  128.  
  129. Srand(x)
  130. long x;
  131. {       
  132.         Randx = x; 
  133. }
  134.  
  135. Rand()
  136. {       
  137.         return((Randx = Randx * 505360173 + 907633385) & 0x7fffffff); 
  138. }
  139.  
  140. bounce (x, off, dx, lim)
  141. int *x, off, *dx, lim;
  142. {
  143.         int j,t1,t2;
  144.         t1 = (long) Rand();
  145.         t2 = (long) Rand();
  146.         if (t1%100 > Chance)
  147.                 *dx = *dx + t2%Diff-Diff/2;
  148.         if(*dx > Max || *dx < -Max)
  149.                 *dx = *dx / Div;
  150.         j = *dx + x[(off+Nqix-1)%Nqix];
  151.         if (j > lim) {
  152.                 j = lim;
  153.                 *dx = -(*dx);
  154.         }
  155.         else if (j < 0) {
  156.                 j = 0;
  157.                 *dx = -(*dx);
  158.         }
  159.         return (x[off] = j);
  160. }
  161.  
  162. Vector(a,b,c,d)
  163. int a,b,c,d;
  164. {
  165.         ptsin[0] = a;
  166.         ptsin[1] = b;
  167.         ptsin[2] = c;
  168.         ptsin[3] = d;
  169.         v_pline(handle, 2, ptsin);
  170. }
  171.  
  172. //go.sysin dd *
  173. made=TRUE
  174. if [ $made = TRUE ]; then
  175.         /bin/chmod 644 qix.c
  176.         /bin/echo -n '  '; /bin/ls -ld qix.c
  177. fi
  178. /bin/echo 'Extracting qux.inp'
  179. sed 's/^X//' <<'//go.sysin dd *' >qux.inp
  180. [u] qux.68k=apstart,qux,aesbind,vdibind,osbind
  181. //go.sysin dd *
  182. made=TRUE
  183. if [ $made = TRUE ]; then
  184.         /bin/chmod 644 qux.inp
  185.         /bin/echo -n '  '; /bin/ls -ld qux.inp
  186. fi
  187. /bin/echo 'Extracting qux.c'
  188. sed 's/^X//' <<'//go.sysin dd *' >qux.c
  189. #include <osbind.h>
  190.  
  191. #define Queues 4
  192. #define Nqux 32
  193. #define abs(x) ((x)<0?(-(x)):(x))
  194.  
  195. int contrl[12], intin[256], ptsin[256], intout[256], ptsout[256];
  196. int i,evwhich,dummy,rand,handle;
  197. int xstart,ystart,xwidth,ywidth,xcen,ycen;
  198. int pxy[4],mx;
  199. long    Randx = 1;
  200. int     width,height;
  201. main()
  202. {
  203.         /* Set the system up to do GEM calls */
  204.         appl_init();
  205.  
  206.         /* Get the handle of the desktop */
  207.  
  208.         handle=graf_handle(&width,&height,&dummy,&dummy);
  209.  
  210.         /* Open the workstation. */
  211.  
  212.         for(i=1; i<10; ++i)  intin[i] = 1;
  213.         intin[10] = 2;
  214.  
  215.         v_opnvwk(intin, &handle, intout);
  216.         pxy[0]=0; 
  217.         pxy[1]=0;
  218.         pxy[2]=intout[0];
  219.         pxy[3]=intout[1];
  220.         xwidth=pxy[2]; 
  221.         ywidth= pxy[3];
  222.         /*  vs_clip(handle,1,pxy);      */
  223.         graf_mouse(0,i);
  224.         draw_sample();
  225.         v_clsvwk(handle);
  226.  
  227.         /* Release GEM calls */
  228.  
  229.         appl_exit();
  230.  
  231.  
  232. }
  233.  
  234.  
  235. draw_sample()
  236. {
  237.  
  238.  
  239.         int   Dx[Queues], Dy[Queues];
  240.         int   x[Queues][Nqux], y[Queues][Nqux];
  241.         int    i=0, flag=0;
  242.  
  243.         v_clrwk(handle);
  244.         vswr_mode(handle,3);
  245.  
  246.         Srand((long) Gettime());
  247.  
  248.         for(i=0;i<Queues;i++) {
  249.                 Dx[i]=(long) Rand3();
  250.                 Dy[i]=(long) Rand3();
  251.         }
  252.  
  253.  
  254.         x[0][Nqux-1] = (int)(xwidth/3);
  255.         y[0][Nqux-1] = (int)(ywidth/3);
  256.         x[1][Nqux-1] = (int)(2*xwidth/3);
  257.         y[1][Nqux-1] = (int)(2*ywidth/3);
  258.         x[2][Nqux-1] = (int)(xwidth/3);
  259.         y[2][Nqux-1] = (int)(2*ywidth/3);
  260.         x[3][Nqux-1] = (int)(2*xwidth/3);
  261.         y[3][Nqux-1] = (int)(ywidth/3);
  262.  
  263.         i=0;
  264.         while (!Bconstat(2)){
  265.                 if (flag) {
  266.                         Vector (x[0][i], y[0][i], x[1][i], y[1][i]);
  267.                         Vector (x[1][i], y[1][i], x[2][i], y[2][i]);
  268.                         Vector (x[2][i], y[2][i], x[3][i], y[3][i]);
  269.                         Vector (x[1][i], y[1][i], x[3][i], y[3][i]);
  270.                         Vector (x[3][i], y[3][i], x[0][i], y[0][i]);
  271.                         Vector (x[2][i], y[2][i], x[0][i], y[0][i]);
  272.                 }
  273.                 Vector (bounce (x[0], i, Dx+0, xwidth-1),
  274.                 bounce (y[0], i, Dy+0, ywidth-1),
  275.                 bounce (x[1], i, Dx+1, xwidth-1),
  276.                 bounce (y[1], i, Dy+1, ywidth-1));
  277.                 Vector (bounce (x[2], i, Dx+2, xwidth-1),
  278.                 bounce (y[2], i, Dy+2, ywidth-1),
  279.                 bounce (x[3], i, Dx+3, xwidth-1),
  280.                 bounce (y[3], i, Dy+3, ywidth-1));
  281.                 Vector (x[1][i], y[1][i], x[2][i], y[2][i]);
  282.                 Vector (x[1][i], y[1][i], x[3][i], y[3][i]);
  283.                 Vector (x[3][i], y[3][i], x[0][i], y[0][i]);
  284.                 Vector (x[2][i], y[2][i], x[0][i], y[0][i]);
  285.                 if (++i >= Nqux) {
  286.                         i=0;
  287.                         flag=1;
  288.                 }
  289.         }
  290.  
  291.         Vector (x[0][i], y[0][i], x[1][i], y[1][i]);
  292.         Vector (x[1][i], y[1][i], x[2][i], y[2][i]);
  293.         Vector (x[2][i], y[2][i], x[3][i], y[3][i]);
  294.         Vector (x[1][i], y[1][i], x[3][i], y[3][i]);
  295.         Vector (x[3][i], y[3][i], x[0][i], y[0][i]);
  296.         Vector (x[2][i], y[2][i], x[0][i], y[0][i]);
  297.         for(flag=(i+1)%Nqux;flag!=i;flag=(flag+1)%Nqux) {
  298.                 Vector (x[0][flag], y[0][flag], x[1][flag], y[1][flag]);
  299.                 Vector (x[1][flag], y[1][flag], x[2][flag], y[2][flag]);
  300.                 Vector (x[2][flag], y[2][flag], x[3][flag], y[3][flag]);
  301.                 Vector (x[1][flag], y[1][flag], x[3][flag], y[3][flag]);
  302.                 Vector (x[3][flag], y[3][flag], x[0][flag], y[0][flag]);
  303.                 Vector (x[2][flag], y[2][flag], x[0][flag], y[0][flag]);
  304.         }
  305.  
  306. }
  307.  
  308. Srand(x)
  309. long x;
  310. {       
  311.         Randx = x; 
  312. }
  313.  
  314. Rand()
  315. {       
  316.         return((Randx = Randx * 505360173 + 907633385) & 0x7fffffff);
  317. }
  318.  
  319. Rand2()
  320. {       
  321.         return(Rand()>>13); 
  322. }
  323.  
  324. Rand3()
  325. {
  326.         return(((Randx = Randx * 505360173 + 907633385)>>13)&1 ?
  327.         ((((Randx = Randx * 505360173 + 907633385)>>13)&1)+1) :
  328.         -((((Randx = Randx * 505360173 + 907633385)>>13)&1)+1));
  329. }
  330.  
  331. bounce (x, off, dx, lim)
  332. int *x, off, *dx, lim;
  333. {
  334.         int j;
  335.  
  336.         j = *dx + x[!off ? Nqux-1 : off-1];
  337.         if (j > lim) {
  338.                 j = lim;
  339.                 *dx = -(*dx);
  340.         }
  341.         else if (j < 1) {
  342.                 j = 1;
  343.                 *dx = -(*dx);
  344.         }
  345.         return(x[off] = j);
  346. }
  347.  
  348. Vector(a,b,c,d)
  349. int a,b,c,d;
  350. {
  351.         ptsin[0] = a;
  352.         ptsin[1] = b;
  353.         ptsin[2] = c;
  354.         ptsin[3] = d;
  355.         v_pline(handle, 2, ptsin);
  356. }
  357.  
  358. //go.sysin dd *
  359. made=TRUE
  360. if [ $made = TRUE ]; then
  361.         /bin/chmod 644 qux.c
  362.         /bin/echo -n '  '; /bin/ls -ld qux.c
  363. fi
  364.  
  365. --
  366. ARPA:   eneevax!ravi@maryland
  367. UUCP:   [seismo,allegra]!umcp-cs!eneevax!ravi
  368.