home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-387-Vol-3of3.iso
/
x
/
x11p-13.zip
/
RCS
/
do_lines.c,v
< prev
next >
Wrap
Text File
|
1989-12-13
|
16KB
|
854 lines
head 2.9;
access ;
symbols pre-merge:2.0;
locks ; strict;
comment @ * @;
2.9
date 89.12.13.19.07.37; author joel; state Exp;
branches ;
next 2.8;
2.8
date 89.12.07.16.34.21; author joel; state Exp;
branches ;
next 2.7;
2.7
date 89.11.20.13.25.34; author joel; state Exp;
branches ;
next 2.6;
2.6
date 89.10.23.18.11.00; author joel; state Exp;
branches ;
next 2.5;
2.5
date 89.10.02.13.40.11; author joel; state Exp;
branches ;
next 2.4;
2.4
date 89.06.23.14.13.29; author joel; state Exp;
branches ;
next 2.3;
2.3
date 89.05.11.16.44.23; author joel; state Exp;
branches ;
next 2.2;
2.2
date 89.05.03.14.17.36; author joel; state Exp;
branches ;
next 2.1;
2.1
date 89.04.19.14.28.03; author joel; state Exp;
branches ;
next 2.0;
2.0
date 89.01.31.17.03.29; author erik; state Exp;
branches ;
next 1.3;
1.3
date 89.01.31.17.03.29; author joel; state Exp;
branches ;
next 1.2;
1.2
date 88.08.01.12.37.43; author joel; state Exp;
branches ;
next 1.1;
1.1
date 88.06.10.13.34.31; author joel; state Exp;
branches ;
next ;
desc
@@
2.9
log
@Generate same lines as ever if we have enough objects to go round the compass at least once. However, if fewer than the complete pattern, this code spreads
lines out completely around compass
@
text
@/*****************************************************************************
Copyright 1988, 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of Digital not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
******************************************************************************/
#include "x11perf.h"
static XPoint *points;
static GC pgc;
int InitLines(xp, p, reps)
XParms xp;
Parms p;
int reps;
{
int size;
int half; /* Half of width if wide line */
int i;
int rows; /* Number of rows filled in current column */
int x, y; /* Next point */
int xdir, ydir; /* Which direction x, y are going */
int bigxdir;
int x1, y1; /* offsets to compute next point from current */
int phase; /* how far into 0..4*(size_1) we are */
float phasef; /* how far we are in real numbers */
float phaseinc; /* how much to increment phasef at each segment */
int size4; /* 4 * size */
pgc = xp->fggc;
size = p->special;
size4 = 4 * (size+1);
half = (size + 19) / 20;
points = (XPoint *)malloc((p->objects+1) * sizeof(XPoint));
/* All this x, x1, x1inc, etc. stuff is to create a pattern that
(1) scans down the screen vertically
(2) rotates the endpoints through all possible orientations
(3) bounces off bottom and top of window as needed
(4) moves left or right at each bounce to make things less boring
*/
x = half;
y = half;
xdir = 1;
ydir = 1;
bigxdir = 1;
phasef = 0.0;
phaseinc = ((float)size4) / ((float)p->objects);
if (phaseinc < 1.0) phaseinc = 1.0;
rows = 0;
points[0].x = x;
points[0].y = y;
for (i = 1; i != (p->objects+1); i++) {
phase = phasef;
switch (phase / (size+1)) {
case 0:
x1 = size;
y1 = phase;
break;
case 1:
x1 = size - phase % (size+1);
y1 = size;
break;
case 2:
x1 = phase % (size+1);
y1 = size;
break;
case 3:
x1 = size;
y1 = size - phase % (size+1);
break;
} /* end switch */
/* Move down or up the screen */
y += (ydir * y1);
/* If off either top or bottom, backtrack to previous position and go
the other way instead. Also move in bigxdir if not already. */
rows++;
if (y < half || y >= (HEIGHT-half) || rows > MAXROWS) {
rows = 0;
if (bigxdir > 0) {
if (x + size < WIDTH - half) {
xdir = 1;
} else {
bigxdir = -1;
}
} else {
if (x - size > half) {
xdir = -1;
} else {
bigxdir = 1;
}
}
ydir = -ydir;
y += (2 * ydir * y1);
/* If still off top or bottom, we can't do the line we want.
This will happen infrequently if the window is not twice the
length of the line. So instead, let's draw a line that puts
the line after this approximately through the center of the
window. Since it is very unlikely that both x and y will
need such adjustment, line length (in pixels) should not
change...we just can't get the slope we want for this line. */
if (y < half) {
y = (HEIGHT - y1)/2;
ydir = 1;
} else if (y > (HEIGHT - half)) {
y = (HEIGHT + y1)/2;
ydir = -1;
}
}
/* Move x left or right by x1 */
x += (xdir * x1);
xdir = -xdir;
/* Again, if we are off the bottom then we can't really draw the line
we want. */
if (x < half) {
x = (WIDTH - x1)/2;
xdir = 1;
} else if (x > (WIDTH - half)) {
x = (WIDTH + x1)/2;
xdir = -1;
}
points[i].x = x;
points[i].y = y;
/* Increment phasef */
phasef += phaseinc;
if (phasef >= size4) phasef -= size4;
}
return reps;
}
int InitWideLines(xp, p, reps)
XParms xp;
Parms p;
int reps;
{
int size;
(void)InitLines(xp, p, reps);
size = p->special;
XSetLineAttributes(xp->d, xp->bggc, (int) ((size + 9) / 10),
LineSolid, CapRound, JoinRound);
XSetLineAttributes(xp->d, xp->fggc, (int) ((size + 9) / 10),
LineSolid, CapRound, JoinRound);
return reps;
}
int InitDashedLines(xp, p, reps)
XParms xp;
Parms p;
int reps;
{
char dashes[2];
(void)InitLines(xp, p, reps);
/* Modify GCs to draw dashed */
XSetLineAttributes(xp->d, xp->bggc, 0, LineOnOffDash, CapButt, JoinMiter);
XSetLineAttributes(xp->d, xp->fggc, 0, LineOnOffDash, CapButt, JoinMiter);
dashes[0] = 3; dashes[1] = 2;
XSetDashes(xp->d, xp->fggc, 0, dashes, 2);
XSetDashes(xp->d, xp->bggc, 0, dashes, 2);
return reps;
}
int InitWideDashedLines(xp, p, reps)
XParms xp;
Parms p;
int reps;
{
int size;
XGCValues gcv;
char dashes[2];
(void)InitWideLines(xp, p, reps);
size = p->special;
size = (size + 9) / 10;
/* Modify GCs to draw dashed */
dashes[0] = 2*size; dashes[1] = 2*size;
gcv.line_style = LineOnOffDash;
XChangeGC(xp->d, xp->fggc, GCLineStyle, &gcv);
XChangeGC(xp->d, xp->bggc, GCLineStyle, &gcv);
XSetDashes(xp->d, xp->fggc, 0, dashes, 2);
XSetDashes(xp->d, xp->bggc, 0, dashes, 2);
return reps;
}
int InitDoubleDashedLines(xp, p, reps)
XParms xp;
Parms p;
int reps;
{
char dashes[2];
(void)InitLines(xp, p, reps);
/* Modify GCs to draw dashed */
XSetLineAttributes(xp->d, xp->bggc, 0, LineDoubleDash, CapButt, JoinMiter);
XSetLineAttributes(xp->d, xp->fggc, 0, LineDoubleDash, CapButt, JoinMiter);
dashes[0] = 3; dashes[1] = 2;
XSetDashes(xp->d, xp->fggc, 0, dashes, 2);
XSetDashes(xp->d, xp->bggc, 0, dashes, 2);
return reps;
}
int InitWideDoubleDashedLines(xp, p, reps)
XParms xp;
Parms p;
int reps;
{
int size;
XGCValues gcv;
char dashes[2];
(void)InitWideLines(xp, p, reps);
size = p->special;
size = (size + 9) / 10;
/* Modify GCs to draw dashed */
dashes[0] = 2*size; dashes[1] = 2*size;
gcv.line_style = LineDoubleDash;
XChangeGC(xp->d, xp->fggc, GCLineStyle, &gcv);
XChangeGC(xp->d, xp->bggc, GCLineStyle, &gcv);
XSetDashes(xp->d, xp->fggc, 0, dashes, 2);
XSetDashes(xp->d, xp->bggc, 0, dashes, 2);
return reps;
}
void DoLines(xp, p, reps)
XParms xp;
Parms p;
int reps;
{
int i;
for (i = 0; i != reps; i++)
{
XDrawLines(xp->d, xp->w, pgc, points, p->objects+1, CoordModeOrigin);
if (pgc == xp->bggc)
pgc = xp->fggc;
else
pgc = xp->bggc;
}
}
void EndLines(xp, p)
XParms xp;
Parms p;
{
free(points);
}
@
2.8
log
@Changed interface to p->reps
@
text
@d42 4
a45 3
int x1inc, y1inc; /* How to get to next x1, y1 */
int minorphase; /* # iterations left with current x1inc, y1inc */
int majorphase; /* count 0..3 for which type of x1inc, y1inc */
d50 1
d65 4
a68 2
x = half; y = half;
xdir = 1; ydir = 1;
d70 3
a72 5
x1 = size; y1 = 0;
x1inc = 0; y1inc = 1;
minorphase = size;
majorphase = 0;
d79 24
a102 1
/* Move on down or up the screen */
d125 14
a140 3
/* Update y1 by 0 or 1 */
y1 += y1inc;
d144 9
a152 4
/* Update x1 by 0 or 1 */
x1 += x1inc;
d156 4
a159 12
/* Change increments if needed */
minorphase--;
if (minorphase < 0) {
minorphase = size;
majorphase = (majorphase + 1) % 4;
switch (majorphase) {
case 0: x1 = size; x1inc = 0; y1 = 0; y1inc = 1; break;
case 1: x1 = size; x1inc = -1; y1 = size; y1inc = 0; break;
case 2: x1 = 0; x1inc = 1; y1 = size; y1inc = 0; break;
case 3: x1 = size; x1inc = 0; y1 = size; y1inc = -1; break;
}
}
@
2.7
log
@Declare pgc as static, so switch between fggc and bggc happens every time,
not just within one iteration of tests. (Helps make things look better on
slow machines, which may only run 1 iteration.)
@
text
@d29 1
a29 1
Bool InitLines(xp, p)
d32 1
d128 1
a128 1
return True;
d131 1
a131 1
Bool InitWideLines(xp, p)
d134 1
d138 1
a138 1
(void)InitLines(xp, p);
d146 1
a146 1
return True;
d149 1
a149 1
Bool InitDashedLines(xp, p)
d152 1
d156 1
a156 1
(void)InitLines(xp, p);
d164 1
a164 1
return True;
d167 1
a167 1
Bool InitWideDashedLines(xp, p)
d170 1
d176 1
a176 1
(void)InitWideLines(xp, p);
d187 1
a187 1
return True;
d190 1
a190 1
Bool InitDoubleDashedLines(xp, p)
d193 1
d197 1
a197 1
(void)InitLines(xp, p);
d205 1
a205 1
return True;
d208 1
a208 1
Bool InitWideDoubleDashedLines(xp, p)
d211 1
d217 1
a217 1
(void)InitWideLines(xp, p);
d228 1
a228 1
return True;
d231 1
a231 1
void DoLines(xp, p)
d234 1
d238 1
a238 1
for (i = 0; i != p->reps; i++)
@
2.6
log
@Make sure that wide lines aren't clipped.
@
text
@d26 2
a27 1
static XPoint *points;
d45 2
a228 1
GC pgc;
a230 1
pgc = xp->fggc;
@
2.5
log
@Moved wide lines into here
@
text
@d33 1
d45 1
d59 1
a59 1
x = 0; y = 0;
d79 1
a79 1
if (y < 0 || y >= HEIGHT || rows > MAXROWS) {
d82 1
a82 1
if (x + size < WIDTH) {
d88 1
a88 1
if (x - size > 0) {
@
2.4
log
@Added double-dashed lines
@
text
@d125 17
d159 22
d193 22
@
2.3
log
@Parameters to all routines now (xp, p)
MAXROWS used in all routines
Junked most global communication variables
@
text
@d142 17
@
2.2
log
@Massive changes, I'm not going to go into details.
@
text
@d1 23
a26 2
static GC bggc, fggc;
static Window w;
d28 2
a29 2
Bool InitLines(d, p)
Display *d;
d32 1
a32 1
int size;
d34 1
d37 1
d54 1
d57 1
a57 1
x = (WIDTH-size)/2; y = 0;
d59 1
a61 1
d65 2
d70 1
a70 8
for (i = 1; i < (p->objects+1); i++) {
/* Move x left or right by x1 */
x += (xdir * x1);
xdir = -xdir;
/* Update x1 by 0 or 1 */
x1 += x1inc;
d75 17
a91 2
the other way instead */
if (y < 0 || y >= HEIGHT) {
d99 7
a121 1
CreatePerfStuff(d, 1, WIDTH, HEIGHT, &w, &bggc, &fggc);
d125 2
a126 2
Bool InitDashedLines(d, p)
Display *d;
d131 1
a131 1
(void)InitLines(d, p);
d134 5
a138 5
XSetLineAttributes(d, bggc, 0, LineOnOffDash, CapButt, JoinMiter);
XSetLineAttributes(d, fggc, 0, LineOnOffDash, CapButt, JoinMiter);
dashes[0] = 1; dashes[1] = 3;
XSetDashes(d, fggc, 0, dashes, 2);
XSetDashes(d, bggc, 0, dashes, 2);
d142 3
a144 3
void DoLines(d, p)
Display *d;
Parms p;
d149 2
a150 2
pgc = bggc;
for (i=0; i<p->reps; i++)
d152 3
a154 3
XDrawLines(d, w, pgc, points, p->objects+1, CoordModeOrigin);
if (pgc == bggc)
pgc = fggc;
d156 1
a156 1
pgc = bggc;
d160 3
a162 3
void EndLines(d, p)
Display *d;
Parms p;
a163 3
XDestroyWindow(d, w);
XFreeGC(d, bggc);
XFreeGC(d, fggc);
@
2.1
log
@Changed lines not to use random numbers, but to walk up and down the
screen exercising all orientations, and thrashing the TLB as much as
possible.
@
text
@d5 1
a5 6
static Window w[4];
static XRectangle ws[3] = {
{150, 150, 90, 90},
{300, 180, 90, 90},
{450, 210, 90, 90}
};
d7 1
a7 1
void InitSizedLines(d, p, size)
d10 1
a11 1
{
d20 2
a21 3
for (i = 0; i < 4; i++)
w[i] = None;
i = 0;
d81 2
a82 5
CreatePerfStuff(d, 1, WIDTH, HEIGHT, w, &bggc, &fggc);
for (i = 0; i < p->special; i++)
w[i+1] = CreatePerfWindow(
d, ws[i].x, ws[i].y, ws[i].width, ws[i].height);
d85 1
a85 1
void InitLines1(d, p)
a86 48
Parms p;
{
InitSizedLines(d, p, 1);
}
void InitLines10(d, p)
Display *d;
Parms p;
{
InitSizedLines(d, p, 10);
}
void InitLines100(d, p)
Display *d;
Parms p;
{
InitSizedLines(d, p, 100);
}
void InitLines500(d, p)
Display *d;
Parms p;
{
InitSizedLines(d, p, 500);
/*
int i;
for (i = 0; i < 4; i++)
w[i] = None;
i = 0;
points = (XPoint *)malloc((p->objects+1) * sizeof(XPoint));
for (i = 0; i < (p->objects+1); i++)
{
points[i].x = rand() % WIDTH;
points[i].y = rand() % HEIGHT;
}
CreatePerfStuff(d, 1, WIDTH, HEIGHT, w, &bggc, &fggc);
for (i = 0; i < p->special; i++)
w[i+1] = CreatePerfWindow(
d, ws[i].x, ws[i].y, ws[i].width, ws[i].height);
*/
}
void InitDashedLines100(d, p)
Display *d;
a88 1
XGCValues gcv;
d91 1
a91 1
InitLines100(d, p);
d99 1
d112 1
a112 1
XDrawLines(d, w[0], pgc, points, p->objects+1, CoordModeOrigin);
d124 1
a124 4
int i;
for (i = 0; i < 4; i++)
if (w[i] != None)
XDestroyWindow(d, w[i]);
@
2.0
log
@version from /usr/src/pmax
@
text
@d7 3
a9 3
{100, 100, 200, 200},
{150, 150, 200, 200},
{200, 200, 200, 200}
d18 6
d29 37
a65 8
points[0].x = WIDTH / 2;
points[0].y = HEIGHT / 2;
for (i = 1; i < (p->objects+1); i++)
{
if (points[i-1].x < size || ((rand() >> 12) & 1)) {
points[i].x = points[i-1].x + size;
} else {
points[i].x = points[i-1].x - size;
d67 18
a84 4
if (points[i-1].y < size || ((rand() >> 12) & 1)) {
points[i].y = points[i-1].y + size;
} else {
points[i].y = points[i-1].y - size;
d91 1
d93 2
a94 2
void InitSmallLines(d, p)
d102 1
a102 1
void InitMedLines(d, p)
d110 1
a110 1
void InitLines(d, p)
d114 10
d139 1
a139 1
d142 1
a142 1
void InitDashedLines(d, p)
d149 1
a149 1
InitLines(d, p);
@
1.3
log
@Added -fg -bg capabilities
Added 1-pixel and 10-pixel lines, though this is pretty crude right now.
@
text
@@
1.2
log
@Dashed lines added
@
text
@d4 1
a4 1
static GC whitegc, blackgc;
d12 48
d75 1
a75 1
CreatePerfStuff(d, 1, WIDTH, HEIGHT, w, &whitegc, &blackgc);
d92 2
a93 2
XSetLineAttributes(d, whitegc, 0, LineOnOffDash, CapButt, JoinMiter);
XSetLineAttributes(d, blackgc, 0, LineOnOffDash, CapButt, JoinMiter);
d95 2
a96 2
XSetDashes(d, blackgc, 0, dashes, 2);
XSetDashes(d, whitegc, 0, dashes, 2);
d106 1
a106 1
pgc = whitegc;
d110 2
a111 2
if (pgc == whitegc)
pgc = blackgc;
d113 1
a113 1
pgc = whitegc;
d125 2
a126 2
XFreeGC(d, whitegc);
XFreeGC(d, blackgc);
@
1.1
log
@Initial revision
@
text
@d34 17
@