1 /* $NetBSD: twinkle2.c,v 1.6 2005/05/23 04:04:49 christos Exp $ */
5 * Copyright (c) 1980, 1993
6 * The Regents of the University of California. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * @(#)twinkle2.c 8.1 (Berkeley) 6/8/93
48 static LOCS Layout
[NCOLS
* NLINES
]; /* current board layout */
50 static int Pattern
, /* current pattern number */
51 Numstars
; /* number of stars in pattern */
53 static void puton(char);
55 static void makeboard(void);
56 static int ison(int, int);
70 srand(getpid()); /* initialize random sequence */
75 if ((sp
= getenv("TERM")) != NULL
)
80 printf("Need a terminal on fd=%d\n", 0);
87 TI
= tgetstr("ti", &ptr
);
89 printf("terminal does not have the ti capability\n");
92 VS
= tgetstr("vs", &ptr
);
94 printf("terminal does not have the vs capability\n");
97 CL
= tgetstr("cl", &ptr
);
99 printf("terminal does not have the cl capability\n");
107 tputs(CL
, NLINES
, putchar
);
109 makeboard(); /* make the board setup */
110 puton('*'); /* put on '*'s */
111 puton(' '); /* cover up with ' 's */
116 * On program exit, move the cursor to the lower left corner by
117 * direct addressing, since current location is not guaranteed.
118 * We lie and say we used to be at the upper right corner to guarantee
119 * absolute addressing.
124 signal(SIGINT
, SIG_IGN
);
125 mvcur(0, COLS
- 1, LINES
- 1, 0);
137 static int lasty
, lastx
;
139 end
= &Layout
[Numstars
];
140 for (lp
= Layout
; lp
< end
; lp
++) {
141 r
= rand() % Numstars
;
147 for (lp
= Layout
; lp
< end
; lp
++)
148 /* prevent scrolling */
149 if (!AM
|| (lp
->y
< NLINES
- 1 || lp
->x
< NCOLS
- 1)) {
150 mvcur(lasty
, lastx
, lp
->y
, lp
->x
);
153 if ((lastx
= lp
->x
+ 1) >= NCOLS
)
164 * Make the current board setup. It picks a random pattern and
165 * calls ison() to determine if the character is on that pattern
174 Pattern
= rand() % MAXPATTERNS
;
176 for (y
= 0; y
< NLINES
; y
++)
177 for (x
= 0; x
< NCOLS
; x
++)
183 Numstars
= lp
- Layout
;
187 * Return TRUE if (y, x) is on the current pattern.
193 case 0: /* alternating lines */
196 if (x
>= LINES
&& y
>= NCOLS
)
198 if (y
< 3 || y
>= NLINES
- 3)
200 return (x
< 3 || x
>= NCOLS
- 3);
201 case 2: /* holy pattern! */
202 return ((x
+ y
) & 01);
203 case 3: /* bar across center */
204 return (y
>= 9 && y
<= 15);