1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
24
25
26 /*
27 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
29 */
30
31 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.2 */
32 /*LINTLIBRARY*/
33
34 #include <stdlib.h>
35 #include <math.h>
36 #include "con.h"
37
38 short xnow, ynow;
39
40 static void
iline(short cx0,short cy0,short cx1,short cy1)41 iline(short cx0, short cy0, short cx1, short cy1)
42 {
43 int maxp, tt;
44 short j;
45 char chx, chy;
46 float xd, yd;
47
48 movep(cx0, cy0);
49 maxp = (int)(sqrt(dist2(cx0, cy0, cx1, cy1)) / 2.);
50 xd = cx1 - cx0;
51 yd = cy1 - cy0;
52 if (xd >= 0)
53 chx = RIGHT;
54 else chx = LEFT;
55 if (yd >= 0)
56 chy = UP;
57 else chy = DOWN;
58 if (maxp == 0) {
59 xd = 0;
60 yd = 0;
61 } else {
62 xd /= maxp;
63 yd /= maxp;
64 }
65 inplot();
66 for (tt = 0; tt <= maxp; tt++) {
67 j = (short)(cx0 + xd * tt - xnow);
68 xnow += j;
69 j = abs(j);
70 while (j-- > 0)
71 spew(chx);
72 j = (short)(cy0 + yd * tt - ynow);
73 ynow += j;
74 j = abs(j);
75 while (j-- > 0)
76 spew(chy);
77 spew('.');
78 }
79 outplot();
80 }
81
82 void
line(short x0,short y0,short x1,short y1)83 line(short x0, short y0, short x1, short y1)
84 {
85 iline(xconv(xsc(x0)), yconv(ysc(y0)),
86 xconv(xsc(x1)), yconv(ysc(y1)));
87 }
88
89
90 void
cont(short x0,short y0)91 cont(short x0, short y0)
92 {
93 iline(xnow, ynow, xconv(xsc(x0)), yconv(ysc(y0)));
94 }
95