Article 182 of unix-pc.sources: Path: tut.cis.ohio-state.edu!mailrus!ames!vsi1!altnet!uunet!portal!cup.portal.com!Joe_E_Powell From: Joe_E_Powell@cup.portal.com Newsgroups: unix-pc.sources Subject: Misc graphics examples using wrastop(3) Message-ID: <9084@cup.portal.com> Date: 14 Sep 88 23:42:36 GMT Distribution: usa Organization: The Portal System (TM) Lines: 277 XPortal-User-Id: 1.1001.3095 #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh 'README' <<'END_OF_FILE' XThe following three programs are all pretty simple, and I'm not terribly proud Xof them. They do show how you MIGHT want to use wrastop(3) to write some crude Xgraphics programs. X Xgraphics - implements a line drawing routine and a box drawing routine Xmathplot - plots a sin wave, a cosine wave and a tangent wave with the X line y = 0; Xpaint - implements a simple paint program. Use the left mouse button X to plot a point. Hold the left mouse button down and X move it around to draw continuously. X XYou exit all three of these programs by pressing the Enter key. X XIf anyone can improve upon them, please let me know how you did so. X XJoe E. Powell Xsun!portal!cup.portal.com!joe_e_powell END_OF_FILE if test 692 -ne `wc -c <'README'`; then echo shar: \"'README'\" unpacked with wrong size! fi # end of 'README' fi if test -f 'MANIFEST' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'MANIFEST'\" else echo shar: Extracting \"'MANIFEST'\" \(382 characters\) sed "s/^X//" >'MANIFEST' <<'END_OF_FILE' X File Name Archive # Description X----------------------------------------------------------- X Makefile 1 Makefile for the three programs X README 1 General information X graphics.c 1 Line and box drawing routines X mathplot.c 1 Plot of sin, cos, tan waves X paint.c 1 Simple paint program END_OF_FILE if test 382 -ne `wc -c <'MANIFEST'`; then echo shar: \"'MANIFEST'\" unpacked with wrong size! fi # end of 'MANIFEST' fi if test -f 'Makefile' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'Makefile'\" else echo shar: Extracting \"'Makefile'\" \(349 characters\) sed "s/^X//" >'Makefile' <<'END_OF_FILE' X# Simple graphics programs through the use of wrastop X XCC = /usr/lbin/ccc XLIB = -ltam -ltermcap XMLIB = -lm XCFLAGS = -O -v X Xall: paint graphics mathplot X Xpaint: X $(CC) paint.c -o paint $(LIB) -s X Xgraphics: X $(CC) graphics.c -o graphics $(LIB) -s X Xmathplot: X $(CC) mathplot.c -o mathplot $(LIB) $(MLIB) -s X Xclean: X rm -f paint.o graphics.o mathplot.o END_OF_FILE if test 349 -ne `wc -c <'Makefile'`; then echo shar: \"'Makefile'\" unpacked with wrong size! fi # end of 'Makefile' fi if test -f 'graphics.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'graphics.c'\" else echo shar: Extracting \"'graphics.c'\" \(1252 characters\) sed "s/^X//" >'graphics.c' <<'END_OF_FILE' X#include X#include X Xint wn; Xstruct wstat curstat; Xunsigned short point[2] = { 0xffff, 0xffff }; X Xvoid line(), box(); X Xmain() X{ X winit(); X wn = wcreate(0, 0, 25, 80, NBORDER); X clear(); X line(0, 0, 100, 100); X line(50, 90, 180, 300); X line(10, 10, 20, 200); X box(10, 20, 40, 50); X box(100, 120, 140, 250); X box(150, 150, 90, 0); X getch(); X clear(); X curstat.begy = 1; X curstat.begx = 0; X curstat.height = 25; X curstat.width = 80; X curstat.uflags = NBORDER; X wsetstat(wn, &curstat); X wexit(); X} X Xvoid line(sx, sy, ex, ey) Xint sx, sy, ex, ey; X{ X register int t, dist; X int xerr = 0, yerr = 0, dx = ex-sx, dy = ey-sy, incx, incy; X X if (dx > 0) X incx = 1; X else if (dx == 0) X incx = 0; X else X incx = -1; X if (dy > 0) X incy = 1; X else if (dy == 0) X incy = 0; X else X incy = -1; X dx = abs(dx); X dy = abs(dy); X dist = (dx > dy) ? dx : dy; X for (t = 0; t <= dist + 1; t++) { X wrastop(wn, point, 2, 0, 0, 0, 0, sx, sy, 1, 1, SRCSRC, DSTOR, 0); X xerr += dx; X yerr += dy; X if (xerr > dist) { X xerr -= dist; X sx += incx; X } X if (yerr > dist) { X yerr -= dist; X sy += incy; X } X } X} X Xvoid box(sx, sy, ex, ey) Xint sx, sy, ex, ey; X{ X line(sx, sy, ex, sy); X line(sx, sy, sx, ey); X line(sx, ey, ex, ey); X line(ex, sy, ex, ey); X} END_OF_FILE if test 1252 -ne `wc -c <'graphics.c'`; then echo shar: \"'graphics.c'\" unpacked with wrong size! fi # end of 'graphics.c' fi if test -f 'mathplot.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'mathplot.c'\" else echo shar: Extracting \"'mathplot.c'\" \(852 characters\) sed "s/^X//" >'mathplot.c' <<'END_OF_FILE' X#include X#include X#include X Xint wn; Xstruct wstat curstat; Xunsigned short point[2] = { 0xffff, 0xffff }; X Xmain() X{ X register int x; X X winit(); X wn = wcreate(0, 0, 25, 80, NBORDER); X clear(); X for (x = 0; x < 720; x++) { X wrastop(wn, point, 2, 0, 0, 0, 0, x, X 150 - (int)(150.0 * sin((double)x * 0.017453292)), X 1, 1, SRCSRC, DSTOR, 0); X wrastop(wn, point, 2, 0, 0, 0, 0, x, X 150 - (int)(150.0 * cos((double)x * 0.017453292)), X 1, 1, SRCSRC, DSTOR, 0); X wrastop(wn, point, 2, 0, 0, 0, 0, x, X 150 - (int)(150.0 * tan((double)x * 0.017453292)), X 1, 1, SRCSRC, DSTOR, 0); X wrastop(wn, point, 2, 0, 0, 0, 0, x, 150, 1, 1, SRCSRC, DSTOR, 0); X } X getch(); X clear(); X curstat.begy = 1; X curstat.begx = 0; X curstat.height = 25; X curstat.width = 80; X curstat.uflags = NBORDER; X wsetstat(wn, &curstat); X wexit(); X} END_OF_FILE if test 852 -ne `wc -c <'mathplot.c'`; then echo shar: \"'mathplot.c'\" unpacked with wrong size! fi # end of 'mathplot.c' fi if test -f 'paint.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'paint.c'\" else echo shar: Extracting \"'paint.c'\" \(846 characters\) sed "s/^X//" >'paint.c' <<'END_OF_FILE' X#include X#include X#include X Xstruct wstat curstat; Xstruct umdata mouse; Xshort wn; Xunsigned short point[2] = { 0xffff, 0xffff }; X Xmain() X{ X register int key; X int x, y, but, why; X X winit(); X keypad(0, 1); X wn = wcreate(1, 0, 24, 80, NBORDER); X wprintf(wn, "\033[=1C"); X mouse.um_flags = MSDOWN | MSOUT; X mouse.um_x = mouse.um_y = 0; X mouse.um_w = mouse.um_h = 1; X mouse.um_icon = 0; X clear(); X while (1) { X wsetmouse(wn, &mouse); X key = wgetc(wn); X if (key == Mouse) { X wreadmouse(wn, &x, &y, &but, &why); X if (but & 4) X wrastop(wn, point, 2, 0, 0, 0, 0, x, y, 1, 1, SRCSRC, DSTOR, 0); X } else break; X } X clear(); X ioctl(0, TCFLSH, 2); X curstat.begy = 1; X curstat.begx = 0; X curstat.height = 24; X curstat.width = 80; X curstat.uflags = NBORDER; X wsetstat(wn, &curstat); X wprintf(wn, "\033[=0C"); X wexit(0); X} END_OF_FILE if test 846 -ne `wc -c <'paint.c'`; then echo shar: \"'paint.c'\" unpacked with wrong size! fi # end of 'paint.c' fi echo shar: End of shell archive. exit 0