Path: utzoo!attcan!uunet!bbn.com!rsalz From: rsalz@uunet.uu.net (Rich Salz) Newsgroups: comp.sources.unix Subject: v18i065: GL Graphics Library for AT-clone Unix, Part07/07 Message-ID: <1619@fig.bbn.com> Date: 24 Mar 89 17:59:50 GMT Lines: 1481 Approved: rsalz@uunet.UU.NET Submitted-by: umix!m-net!dtlewis!lewis Posting-number: Volume 18, Issue 65 Archive-name: gl_plot/part07 # To recover, type "sh archive" echo restoring INSTALL sed 's/^X//' > INSTALL < demo.c < X#if MIX_C X#else X#include X#endif /* MIX_C */ X Xextern int lines(), strings(), chars(), strokeset(), fillscreen(); Xextern int charset(), ellipses(), arcs(), testplot(), showcursor(); Xextern int linestyles(), curvestyles(); X Xstatic int mode; X Xvoid usage(progname) Xchar *progname; X{ X fprintf (stderr,"Usage: %s \n\n",progname); X fprintf (stderr,"Where is:\n",0); X fprintf (stderr,"\t4 (CGA 4 color 320 x 200)\n",0); X fprintf (stderr,"\t6 (CGA 2 color 640 x 200)\n",0); X fprintf (stderr,"\t8 (Hercules page 0, 720 x 348)\n",0); X fprintf (stderr,"\t9 (Hercules page 1, 720 x 348)\n",0); X fprintf (stderr,"\t16 (EGA color 640 x 350)\n",0); X fprintf (stderr,"\t256 (IBM / Epson compatible printer)\n",0); X fprintf (stderr,"\t257 (Laserjet+ printer)\n\n",0); X} X Xmain(argc,argv) Xint argc; Xchar *argv[]; X{ X char str[80]; X long time(); X struct tm *gmtime(); X void srand(); X X printf("\nThis demonstration will show the operation of the gl ",0); X printf("graphics functions.\n",0); X printf("The key stops the demo. Press ",0); X printf("to view each\n",0); X printf("successive screen.\n\n",0); X printf("Note: The GLMODE shell variable may be used to specify ",0); X printf("the graphics\n",0); X printf("mode to use.\n\n",0); X printf("Press to continue...",0); X gets(str); X X /* Get the mode to use. */ X X if (argc < 2) mode = ENV_MODE; X else if (argc == 2) { X if (sscanf(argv[1],"%d",&(mode)) != 1) { X usage(argv[0]); X exit (1); X } X } X else { X usage(argv[0]); X exit (1); X } X X /* Set video mode. */ X if (g_init(mode)) { X usage(argv[0]); X fprintf(stderr,"WARNING: Possible invalid shared memory ",0); X fprintf(stderr,"key for requested video mode.\n",0); X exit (1); X } X X /* Draw patterns. */ X X if (mode > MAXVIDEO) printf("\nRasterizing output...",0); X if (lines()) fprintf(stderr,"Failed call to lines().\n"); X if (mode > MAXVIDEO) X printf("\nPress to send to printer...",0); X gets(str); X X if (mode > MAXVIDEO) printf("\nRasterizing output...",0); X g_clear(); X if (linestyles()) fprintf(stderr,"Failed call to linestyles().\n"); X if (mode > MAXVIDEO) X printf("\nPress to send to printer...",0); X gets(str); X X if (mode > MAXVIDEO) printf("\nRasterizing output...",0); X g_clear(); X if (strings()) fprintf(stderr,"Failed call to strings().\n"); X if (mode > MAXVIDEO) X printf("\nPress to send to printer...",0); X gets(str); X X if (mode > MAXVIDEO) printf("\nRasterizing output...",0); X g_clear(); X slanttext(); X if (mode > MAXVIDEO) X printf("\nPress to send to printer...",0); X gets(str); X X if (mode > MAXVIDEO) printf("\nRasterizing output...",0); X g_clear(); X strokeset(); X if (mode > MAXVIDEO) X printf("\nPress to send to printer...",0); X gets(str); X X if (mode > MAXVIDEO) printf("\nRasterizing output...",0); X g_clear(); X if (chars()) fprintf(stderr,"Failed call to chars().\n"); X if (mode > MAXVIDEO) X printf("\nPress to send to printer...",0); X gets(str); X X if (mode > MAXVIDEO) printf("\nRasterizing output...",0); X g_clear(); X fillscreen(); X if (mode > MAXVIDEO) X printf("\nPress to send to printer...",0); X gets(str); X X if (mode > MAXVIDEO) printf("\nRasterizing output...",0); X g_clear(); X charset(); X if (mode > MAXVIDEO) X printf("\nPress to send to printer...",0); X gets(str); X X if (mode > MAXVIDEO) printf("\nRasterizing output...",0); X g_clear(); X ellipses(); X if (mode > MAXVIDEO) X printf("\nPress to send to printer...",0); X gets(str); X X if (mode > MAXVIDEO) printf("\nRasterizing output...",0); X g_clear(); X curvestyles(); X if (mode > MAXVIDEO) X printf("\nPress to send to printer...",0); X gets(str); X X if (mode > MAXVIDEO) printf("\nRasterizing output...",0); X g_clear(); X arcs(); X showcursor(); X X g_finish(); X X printf("\n\n\n\nThe next demonstration screen will use the ",0); X printf("plot(3) interface, rather than\n",0); X printf("direct calls to the gl library. The plot(3) interface ",0); X printf("determines graphic \n",0); X printf("mode from the GLMODE shell variable, or if GLMODE is not ",0); X printf("defined, uses a \n",0); X printf("default mode value (defined in config.h). \n\n",0); X printf("If you called this program with an argument on the ",0); X printf("command line, the \n",0); X printf("next screen may use a different graphics mode ",0); X printf("than you specified. \n\n",0); X printf("Press to continue or to stop...",0); X X gets(str); X X testplot(); X gets(str); X} XxX--EOF--XxX echo restoring mode.sh sed 's/^X//' > mode.sh < mode.xenix < n_point.c < testpat.c < X#if MIX_C X#else X#include X#endif /* MIX_C */ X#if XEN2DOS X#include X#endif /* XEN2DOS */ X#if USOFT X#include X#endif /* USOFT */ X#include "gl.h" X X#ifndef M_PI_2 X#define M_PI_2 1.5707963268 X#endif /* M_PI_2 */ X#ifndef M_PI_4 X#define M_PI_4 0.7853981634 X#endif /* M_PI_4 */ X Xstatic char str[20]; X X/* Routines to put test patterns on the screen. */ X Xint lines() { X X if (n_line(4000,4000,20000,20000)) return(1); X X if (n_movepen(6000,6000)) return(1); X if (n_draw(12000,6000)) return(1); X if (n_draw(12000,12000)) return(1); X if (n_draw(6000,12000)) return(1); X if (n_draw(6000,6000)) return(1); X X if (n_movepen(6000,6000)) return(1); X if (n_draw(12000,12000)) return(1); X X g_pix_color(CYAN); X X if (n_box(700,700,900,1200)) return(1); X if (n_box(900,1200,1100,1700)) return(1); X if (n_box(20000,20000,30000,30000)) return(1); X X if (n_box(1000,10000,12000,12000)) return(1); X if (n_box(9000,9000,13000,13000)) return(1); X if (n_box(8000,8000,14000,14000)) return(1); X if (n_box(7000,7000,15000,15000)) return(1); X if (n_box(6000,6000,16000,16000)) return(1); X X if (n_movepen(2000,13000)) return(1); X if (n_draw(4000,13000)) return(1); X if (n_movepen(4000,13300)) return(1); X if (n_draw(2000,13300)) return(1); X X g_pix_color(GREEN); X X if (n_movepen(2000,14000)) return(1); X if (n_draw(30000,14400)) return(1); X if (n_draw(2000,14800)) return(1); X if (n_draw(30000,15200)) return(1); X if (n_draw(2000,15600)) return(1); X if (n_draw(30000,16000)) return(1); X if (n_draw(2000,16400)) return(1); X if (n_draw(30000,16800)) return(1); X if (n_draw(2000,17200)) return(1); X if (n_draw(30000,17600)) return(1); X if (n_draw(2000,18000)) return(1); X if (n_draw(30000,18400)) return(1); X if (n_draw(0,18800)) return(1); X if (n_draw(32000,19200)) return(1); X if (n_draw(0,19600)) return(1); X if (n_draw(32000,20000)) return(1); X if (n_draw(0,20400)) return(1); X if (n_draw(32000,20800)) return(1); X if (n_draw(0,21200)) return(1); X if (n_draw(32000,21600)) return(1); X if (n_draw(0,22000)) return(1); X if (n_draw(32000,22400)) return(1); X X if (n_movepen(6000,4000)) return(1); X if (n_draw(6200,30000)) return(1); X if (n_draw(6400,4000)) return(1); X if (n_draw(6600,30000)) return(1); X if (n_draw(6800,4000)) return(1); X if (n_draw(7000,30000)) return(1); X if (n_draw(7200,4000)) return(1); X if (n_draw(7400,30000)) return(1); X if (n_draw(7600,4000)) return(1); X if (n_draw(7800,30000)) return(1); X if (n_draw(8000,4000)) return(1); X if (n_draw(8200,30000)) return(1); X if (n_draw(8400,4000)) return(1); X X g_pix_color(BLUE); X X if (n_movepen(2000,2000)) return(1); X if (n_draw(32000,4000)) return(1); X if (n_draw(31000,32000)) return(1); X if (n_draw(1000,30000)) return(1); X if (n_draw(2000,2000)) return(1); X if (n_draw(31000,32000)) return(1); X X if (n_movepen(0,0)) return(1); X if (n_draw(32767,0)) return(1); X if (n_draw(32767,32767)) return(1); X if (n_draw(0,32767)) return(1); X if (n_draw(0,0)) return(1); X if (n_draw(32767,32767)) return(1); X if (n_movepen(0,32767)) return(1); X if (n_draw(32767,0)) return(1); X X return(0); X} X Xint linestyles() { X n_box(1000,1000,30000,30000); X g_style(DOTTED); X n_box(2000,2000,29000,29000); X g_style(DOTDASHED); X n_box(3000,3000,28000,28000); X g_style(DASHED); X n_box(4000,4000,27000,27000); X g_style(SHORTDASHED); X n_box(5000,5000,26000,26000); X g_style(LONGDASHED); X n_box(6000,6000,25000,25000); X g_style(SOLID); X n_box(7000,7000,24000,24000); X g_style(DASHED); X n_movepen(15500,7000); X n_draw(24000,15500); X n_draw(15500,24000); X n_draw(7000,15500); X n_draw(15500,7000); X g_style(SOLID); X n_movepen(12000,15000); X c_cellstr("Line Styles"); X X return(0); X} X Xcurvestyles() { X n_ellipse(15500,15500,15000,15000); X g_style(DOTTED); X n_ellipse(15500,15500,14000,13000); X g_style(DOTDASHED); X n_ellipse(15500,15500,13000,11000); X g_style(DASHED); X n_ellipse(15500,15500,12000,9000); X g_style(SHORTDASHED); X n_ellipse(15500,15500,11000,7000); X g_style(LONGDASHED); X n_ellipse(15500,15500,10000,5000); X g_style(SOLID); X n_ellipse(15500,15500,9000,3000); X n_movepen(12000,15000); X c_cellstr("Ellipses"); X X return(0); X} X Xint strings() { X X n_movepen(10,5000); X if (n_grafstr("AbCdEfGhIjKlMnOpQrStUvWxYz")) X return(1); X X /* Don't worry about errors from here on out. We will get */ X /* an error return code each time we try to write off the edge */ X /* of the screen. */ X X g_pix_color(MAGENTA); X X g_fontctl(2.0, 1.0, 1.0, 0.0, 0.0); X n_movepen(100, 10000); X n_grafstr("AbCdEfGhIjKlMnOpQrStUvWxYz"); X g_fontctl(4.0, 1.0, 1.0, 0.0, 0.0); X n_movepen(100, 15000); X n_grafstr("AbCdEfGhIjKlMnO"); X g_fontctl(3.0, 1.0, 1.0, 0.0, 0.0); X n_movepen(100, 20000); X n_grafstr("Z#\$%^&*()+"); X g_fontctl(3.0, 2.0, 1.0, 0.0, 0.0); X n_movepen(100, 24000); X n_grafstr("Z#\$%^&*()+"); X g_fontctl(3.0, 2.0, 2.0, 0.0, 0.0); X n_movepen(100, 28000); X n_grafstr("Z#\$%^&*()+"); X X return (0); X X} X Xint chars() { X X int idx; X char string1[65]; X char string2[65]; X char string3[65]; X char string4[65]; X X g_pix_color(RED); X X if (c_cursor(1,1)) return(1); X if (c_cellstr("* <== This is (1,1)")) return(1); X X /* Don't worry about errors from here on out. We will get */ X /* an error return code each time we try to write off the edge */ X /* of the screen. */ X X c_cursor(2,30); X c_cellstr("* <== This is (2,30)"); X X c_cursor(3,60); X c_cellstr("* <== This is (3,60)"); X X c_cursor(10,40); X c_cellstr("* <== This is (10,40)"); X X c_cursor(25,40); X c_cellstr("X"); X X c_cursor(25,80); X c_cellstr("X"); X X c_cursor(43,90); X c_cellstr("X"); X X c_cursor(2,1); X c_cellstr("This"); X c_cursor(3,1); X c_cellstr(" Is "); X c_cursor(4,1); X c_cellstr(" A "); X c_cursor(5,1); X c_cellstr("TEST"); X c_cursor(6,1); X c_cellstr("XXXX"); X c_cursor(7,1); X c_cellstr("XXXX"); X X for (idx=0;idx<64;idx++) { X string1[idx]=idx; X string2[idx]=idx+64; X string3[idx]=idx+128; X string4[idx]=idx+192; X } X string1[64]=0; X string2[64]=0; X string3[64]=0; X string4[64]=0; X X /* The first character of string1[] is a null, making it a */ X /* null string. No good. Make it the same as the second. */ X X string1[0] = string1[1]; X X c_cursor(11,1); X c_cellstr(string1); X c_cursor(12,2); X c_cellstr(string2); X c_cursor(13,3); X c_cellstr(string3); X c_cursor(14,4); X c_cellstr(string4); X c_cursor(15,5); X c_cellstr(string1); X c_cursor(16,6); X c_cellstr(string2); X c_cursor(17,7); X c_cellstr(string3); X c_cursor(18,8); X c_cellstr(string4); X X for (idx=1;idx<=10;idx++) { X if (! c_cursor(idx,20)) c_cellstr("XHIHX"); X } X X return (0); X} X Xint charset() { X int x,y; X X char cval = 0; X g_pix_color(CYAN); X for (y=1; y<=60; y++) { X for (x=1; x<=140; x++) { X if (! c_cursor(y,x)) { X c_cellchar(cval); X cval = (++cval) & 0xff; X } X } X } X} X Xint strokeset() { X int x,y; X X char cval = 0; X g_pix_color(CYAN); X g_fontctl(2.0, 1.0, 1.0, 0.0, 0.0); X for (y=1; y<=60; y += 2) { X for (x=1; x<=140; x += 2) { X if (! c_cursor(y,x)) { X n_grafchar(cval); X cval = (++cval) & 0x7f; X } X } X } X} X Xint slanttext() { X X g_pix_color(LT_CYAN); X n_movepen(6000,100); X g_fontctl(4.0, 1.0, 1.0, 0.0, 0.0); X n_grafstr("Text"); X X n_movepen(6000,4100); X n_grafstr("Can be"); X X g_pix_color(LT_GREEN); X n_movepen(6000,8100); X g_fontctl(4.0, 1.0, 1.0, 0.0, 0.2); X n_grafstr("Slanted!"); X X g_pix_color(YELLOW); X n_movepen(10,30000); X g_fontctl(4.0, 1.0, 1.0, M_PI_2, 0.0); X n_grafstr("Rotated!"); X X g_pix_color(LT_RED); X n_movepen(6000,28000); X g_fontctl(4.0, 1.0, 1.0, M_PI_4, 0.0); X n_grafstr("Or "); X g_fontctl(4.0, 1.0, 1.0, M_PI_4, 0.2); X n_grafstr("Both!"); X} X Xint fillscreen() { X int x,y; X char cval; X g_pix_color(CYAN); X for (x=1; x<=140; x++) { X for (y=1; y<=60; y++) { X cval = ((x+y-1)%10+'0'); X if (! c_cursor(y,x)) c_cellchar(cval); X } X } X n_box(0,0,32767,32767); X} X Xellipses() { X int idx; X X g_pix_color(CYAN); X n_ellipse(10000,10000,4000,6000); X n_ellipse(24000,15000,5000,6000); X n_ellipse(20000,10000,6000,4000); X n_ellipse(18000,18000,4000,3000); X n_ellipse(10000,20000,7000,6000); X n_ellipse(15000,24000,8000,8000); X n_ellipse(10000,28000,5000,6000); X X for (idx=10; idx< 20000; idx +=400) { X n_ellipse(1000+idx,1000+idx,idx,idx); X } X} X Xarcs() { X int idx; X X g_pix_color(RED); X for (idx=10; idx< 20000; idx +=200) { X n_arc(15000,15000,1000+idx,1000+idx,(float)idx,(float)idx+0.4); X } X} X Xplotpattern(size) Xint size; X{ X /* Use the plot(3) interface to draw a bunch of junk, scaled */ X /* according to the value of size. */ X X space(0,0,size,size); X move(1000,1000); X label("This is the BSD plot(3) interface."); X circle(1000,1000,100); X circle(1000,1000,200); X circle(1000,1000,400); X circle(1000,1000,800); X cont(2000,2000); X move(0,0); X cont(0,3120); X cont(3120,3120); X cont(3120,0); X cont(0,0); X} X Xplotcircles() { X erase(); X X space(0,0,1000,1000); X X move(0,0); X cont(999,0); X cont(999,999); X cont(0,999); X cont(0,0); X X circle(500,500,100); X circle(500,500,200); X circle(500,500,300); X circle(500,500,400); X circle(500,500,500); X circle(500,500,600); X circle(500,500,700); X circle(500,500,800); X} X Xplotarcs() { X erase(); X X arc(500,500,600,500,400,400); X arc(500,500,700,500,400,400); X arc(500,500,800,500,400,400); X arc(500,500,900,500,400,400); X arc(500,500,1000,500,400,400); X arc(500,500,1100,500,400,400); X arc(500,500,1200,500,400,400); X arc(500,500,1300,500,400,400); X} X Xint plotstyles() { X space(0,0,1000,1000); X erase(); X move(0,0); X cont(1000,0); X cont(1000,1000); X cont(0,1000); X cont(0,0); X linemod("dotdashed"); X line(100,0,900,100); X linemod("solid"); X line(100,100,900,100); X line(100,100,900,200); X linemod("dotted"); X line(100,200,900,200); X line(100,200,900,300); X linemod("shortdashed"); X line(100,300,900,300); X line(100,300,900,400); X linemod("longdashed"); X line(100,400,900,400); X line(100,400,900,500); X linemod("dotdashed"); X line(100,500,900,500); X line(100,500,900,600); X linemod("take the default (solid)"); X line(100,600,900,600); X line(100,600,900,700); X linemod("dotted"); X line(100,700,900,700); X line(100,700,900,800); X linemod("shortdashed"); X line(100,800,900,800); X line(100,800,900,900); X linemod("longdashed"); X line(100,900,900,900); X line(100,900,900,1000); X} X Xtestplot() X{ X /* Exercise the plot(3) interface. */ X openpl(); X plotpattern(3120); X plotpattern(6240); X plotpattern(12480); X gets(str); X plotcircles(); X gets(str); X plotarcs(); X gets(str); X plotstyles(); X gets(str); X closepl(); X exit(0); X} X Xint cursor(x,y) Xint x, y; X{ X n_line(x-800,y,x+800,y); X n_line(x,y-1000,x,y+1000); X return(0); X} X Xint showcursor() { X X#define MAX_BOUND_ 28000 X#define MIN_BOUND 4000 X X int idx,i,j,xinc,yinc; X X if (n_box(0,0,32767,32767)) return(1); X if (n_box(1000,1200,31767,31567)) return(1); X if (n_box(2000,2400,30767,30367)) return(1); X X g_pix_mode(XOR); X X xinc = 380; X yinc = 330; X i = 14300; X j = 17324; X X cursor (i,j); X X for (idx=0; idx<1600; idx++) { X cursor (i,j); X if (i < MIN_BOUND || i > MAX_BOUND_) xinc = - xinc; X if (j > MAX_BOUND_) yinc = - yinc - 10; X if (j < MIN_BOUND) yinc = - yinc; X i += xinc; X j += yinc; X cursor (i,j); X } X X g_pix_mode(OR); X X return(0); X} XxX--EOF--XxX echo restoring xdemo.c sed 's/^X//' > xdemo.c < X#include "config.h" X#include "gl.h" X#if MS_DOS X#include X#define DOS_GET_TIME 0x2c X#define DOS_KBY_STAT 0x0b; X#define DOS 0x21 X#endif /* MS_DOS */ X#if MIX_C X#else X#include X#include X#if MS_DOS X#include X#endif /* MS_DOS */ X#endif /* MIX_C */ X X#define MAXINT 32767 X#define NUMLINES 32 X X#define MSG_COUNT 11 X X#if MS_DOS Xstatic REGISTERS inreg, outreg; X#endif /* MS_DOS */ X Xvoid border() { X /* Draw a border and text message. */ X int color; X color = g_pix_color(CYAN); X n_box(0,0,32767,32767); X n_movepen(2000,30000); X g_fontctl(2.5, 1.0, 1.0, 0.0, 0.0); X n_grafstr("XOR Write Mode"); X g_pix_color(1); X n_line(16383,6000,16383,26767); X n_line(6000,16383,26767,16383); X g_pix_color(color); X} X Xvoid usage(progname) Xchar *progname; X{ X fprintf (stderr,"Usage: %s \n\n",progname); X fprintf (stderr,"Where is:\n",0); X fprintf (stderr,"\t4 (CGA 4 color 320 x 200)\n",0); X fprintf (stderr,"\t6 (CGA 2 color 640 x 200)\n",0); X fprintf (stderr,"\t8 (Hercules page 0, 720 x 348)\n",0); X fprintf (stderr,"\t9 (Hercules page 1, 720 x 348)\n",0); X fprintf (stderr,"\t16 (EGA color 640 x 350)\n",0); X fprintf (stderr,"\t256 (IBM / Epson compatible printer)\n",0); X fprintf (stderr,"\t257 (Laserjet+ printer)\n\n",0); X} X Xvoid pattern() { X X long x1; X long y1; X long x2; X long y2; X int x1rate; X int y1rate; X int x2rate; X int y2rate; X int rand(); X int idx_to_buff; X struct endpoints { X int x1; X int x2; X int y1; X int y2; X } buff[NUMLINES]; X X /* Initialize. */ X X /* Modify the slopes and starting location of the endpoint */ X /* motion, to give different patterns every time we run the */ X /* program. */ X x1 = rand(); X y1 = rand(); X x2 = rand(); X y2 = rand(); X x1rate = rand() & 0x0FF + 256; X y1rate = rand() & 0x0FF + 256; X x2rate = rand() & 0x0FF + 256; X y2rate = rand() & 0x0FF + 256; X if (rand() & 0x01) x1rate *= -1; X if (rand() & 0x01) y1rate *= -1; X if (rand() & 0x01) x2rate *= -1; X if (rand() & 0x01) y2rate *= -1; X X /* Initialize the line buffer to invalid values (so they don't */ X /* get plotted). */ X X for (idx_to_buff=0; idx_to_buff < NUMLINES; idx_to_buff++) { X buff[idx_to_buff].x1 = -1; X buff[idx_to_buff].y1 = -1; X buff[idx_to_buff].x2 = -1; X buff[idx_to_buff].y2 = -1; X } X X idx_to_buff = 0; X X /* Start the display pattern. */ X X /* Loop until key is pressed. */ X for (;;) { X X#if MS_DOS X /* Call to get keyboard status, so DOS can check for */ X /* interrupt signal (^C). */ X inreg.AH = DOS_KBY_STAT; X DO_BIOS(DOS, &inreg, &outreg); X#endif /* MS_DOS */ X X /* Increment buffer pointer, wrapping around buffer. */ X ++idx_to_buff; X idx_to_buff %= NUMLINES; X X /* Erase (redraw in XOR mode) old line. */ X n_line( buff[idx_to_buff].x1, X buff[idx_to_buff].y1, X buff[idx_to_buff].x2, X buff[idx_to_buff].y2 X ); X X /* Get coordinates of new line. */ X if (((x1 += x1rate) < 0) || (x1 > MAXINT)) { X x1rate *= -1; X x1 += (2 * x1rate); X } X if (((y1 += y1rate) < 0) || (y1 > MAXINT)) { X y1rate *= -1; X y1 += (2 * y1rate); X } X if (((x2 += x2rate) < 0) || (x2 > MAXINT)) { X x2rate *= -1; X x2 += (2 * x2rate); X } X if (((y2 += y2rate) < 0) || (y2 > MAXINT)) { X y2rate *= -1; X y2 += (2 * y2rate); X } X X /* Store it in buffer. */ X buff[idx_to_buff].x1 = x1; X buff[idx_to_buff].y1 = y1; X buff[idx_to_buff].x2 = x2; X buff[idx_to_buff].y2 = y2; X X /* Draw new line. */ X n_line( buff[idx_to_buff].x1, X buff[idx_to_buff].y1, X buff[idx_to_buff].x2, X buff[idx_to_buff].y2 X ); X } X} X Xvoid message() { X /* Write a cute message every time we get a time signal. */ X X#if MS_DOS X#else X static int msg_count = 0; X#endif /* MS_DOS */ X int save_color; X int save_pix_mode; X save_color = g_pix_color(RED); X save_pix_mode = g_pix_mode(XOR); X c_cursor(2,2); X c_cellstr("Press to quit..."); X g_pix_color(save_color); X g_pix_mode(save_pix_mode); X#if MS_DOS X#else X if (msg_count < MSG_COUNT) { X /* Do it MSG_COUNT times, then stop. */ X signal(SIGALRM,message); X alarm(1); X msg_count++; X } X else { X /* Erase the border by redrawing it. */ X border(); X } X#endif /* MS_DOS */ X} X Xmain(argc,argv) Xint argc; Xchar *argv[]; X{ X int mode; X long timeval; X long time(); X struct tm *timestruct; X struct tm *gmtime(); X void srand(); X X /* Get the mode to use. */ X X if (argc < 2) mode = ENV_MODE; X else if (argc == 2) { X if (sscanf(argv[1],"%d",&(mode)) != 1) { X usage(argv[0]); X exit (1); X } X } X else { X usage(argv[0]); X exit (1); X } X X /* Set video mode. */ X if (g_init(mode)) { X usage(argv[0]); X fprintf(stderr,"WARNING: Possible invalid shared memory ",0); X fprintf(stderr,"key for requested video mode.\n",0); X exit (1); X } X X /* Set for XOR mode. */ X g_pix_mode(XOR); X X /* Set pattern color. */ X g_pix_color(GREEN); X X /* Draw a border and a text message. */ X border(); X X#if MS_DOS X message(); X#else X /* Fork and start flashing a cute message. */ X if (fork() == 0) { X /* Child process here. */ X /* Child should exit on receipt of a SIGINT signal */ X signal(SIGINT, SIG_DFL); X /* Set a timer to post message. */ X signal(SIGALRM,message); X alarm(3); X for(;;) pause(); X } X X /* Parent process continues here. */ X#endif /* MS_DOS */ X X /* Get the current time, and use it as a seed value for the */ X /* rand() function. */ X X#if MS_DOS X /* Get the current time using DOS function 0x2c */ X inreg.AH = DOS_GET_TIME; X DO_BIOS(DOS, &inreg, &outreg); X srand((unsigned)outreg.DL); X#else X timeval = time((long *) 0); X timestruct = gmtime(&timeval); X srand((unsigned)timestruct->tm_sec); X#endif /*MS_DOS */ X X /* Draw the pattern. */ X X pattern(); X} XxX--EOF--XxX echo restoring xform.c sed 's/^X//' > xform.c < X#endif /* MIX_C */ X#include "bitmaps.h" X#include "graphics.h" X Xextern struct GL_graphics graphics; Xextern long longsin(), longcos(); X X/* I_rot_2d_s rotates a point about the origin in two dimensions. */ X/* It operates on integer values, and is used used for text rotations */ X/* in normalized 2-D coordinate space. */ X/* Since this is intended for text, the y values will be scaled */ X/* according to the value of graphics.aspect_ratio. */ X/* Note that in this coordinate system, the angle is "backwards", */ X/* since the origin is in the upper left of the screen. Since we */ X/* normally want a positive angle to appear counterclockwise on the */ X/* screen, the angle parameter will normally be negated prior to */ X/* calling this routine. */ X Xint i_rot_2d_s(x, y, theta) Xint *x, *y; Xdouble theta; X{ X X#if NOFLOAT X long x_temp = (long)(*x); X long y_temp = (long)(*y); X X /* Temporary variable is used to force explicit order of */ X /* integer calculations. This probably isn't really needed */ X /* with most compilers, but better to be safe than sorry. */ X X long ltemp; X X /* Scale the (floating point) aspect ratio up to a reasonable */ X /* integer value. */ X X long lratio = (long)(graphics.aspect_ratio * 16.0); X X /* Pre-calculate the sin and cos values (save calls to trig */ X /* routines.) */ X X long lsinval = longsin(theta); X long lcosval = longcos(theta); X X ltemp = y_temp * lsinval; X ltemp /= 16; /* Scale down first to avoid overflow. */ X ltemp *= lratio; X X *x = (int)((x_temp * lcosval - ltemp) / TRIG_SCALE); X X ltemp = x_temp * lsinval; X ltemp /= lratio; X ltemp *= 16; /* Scale it back. */ X X *y = (int)((ltemp + y_temp * lcosval) / TRIG_SCALE); X X#else X double x_temp = (double)(*x); X double y_temp = (double)(*y); X X /* Pre-calculate the sin and cos values (save calls to trig */ X /* routines.) */ X X double sinval = sin(theta); X double cosval = cos(theta); X X *x = (int)(x_temp * cosval X - y_temp * sinval * graphics.aspect_ratio); X *y = (int)(x_temp * sinval / graphics.aspect_ratio X + y_temp * cosval); X X#endif /* NOFLOAT */ X X return(0); X} X X/* I_rot_2d rotates a point about the origin in two dimensions. */ X/* It operates on integer values, and is used used for rotations in */ X/* normalized 2-D coordinate space. */ X/* Note that in this coordinate system, the angle is "backwards", */ X/* since the origin is in the upper left of the screen. Since we */ X/* normally want a positive angle to appear counterclockwise on the */ X/* screen, the angle parameter will normally be negated prior to */ X/* calling this routine. */ X/* This routine does not account for aspect ratio. */ X Xint i_rot_2d(x, y, theta) Xint *x, *y; Xdouble theta; X{ X X#if NOFLOAT X long x_temp = (long)(*x); X long y_temp = (long)(*y); X X /* Pre-calculate the sin and cos values (save calls to trig */ X /* routines.) */ X X long lsinval = longsin(theta); X long lcosval = longcos(theta); X X *x = (int)((x_temp * lcosval - y_temp * lsinval) X /TRIG_SCALE); X *y = (int)((x_temp * lsinval + y_temp * lcosval) X /TRIG_SCALE); X#else X double x_temp = (double)(*x); X double y_temp = (double)(*y); X X /* Pre-calculate the sin and cos values (save calls to trig */ X /* routines.) */ X X double sinval = sin(theta); X double cosval = cos(theta); X X *x = (int)(x_temp * cosval - y_temp * sinval); X *y = (int)(x_temp * sinval + y_temp * cosval); X#endif /* NOFLOAT */ X X return(0); X} X X XxX--EOF--XxX -- Please send comp.sources.unix-related mail to rsalz@uunet.uu.net.