1 /* $NetBSD: twinkle1.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 * @(#)twinkle1.c 8.1 (Berkeley) 6/8/93
38 * the idea for this program was a product of the imagination of
39 * Kurt Schoens. Not responsible for minds lost or stolen.
50 static LOCS Layout
[NCOLS
* NLINES
]; /* current board layout */
52 static int Pattern
, /* current pattern number */
53 Numstars
; /* number of stars in pattern */
55 static void puton(char);
56 static void makeboard(void);
57 static int ison(int, int);
63 srand(getpid()); /* initialize random sequence */
69 leaveok(stdscr
, TRUE
);
70 scrollok(stdscr
, FALSE
);
73 makeboard(); /* make the board setup */
74 puton('*'); /* put on '*'s */
75 puton(' '); /* cover up with ' 's */
80 * On program exit, move the cursor to the lower left corner by
81 * direct addressing, since current location is not guaranteed.
82 * We lie and say we used to be at the upper right corner to guarantee
83 * absolute addressing.
88 signal(SIGINT
, SIG_IGN
);
89 mvcur(0, COLS
- 1, LINES
- 1, 0);
96 * Make the current board setup. It picks a random pattern and
97 * calls ison() to determine if the character is on that pattern
106 Pattern
= rand() % MAXPATTERNS
;
108 for (y
= 0; y
< NLINES
; y
++)
109 for (x
= 0; x
< NCOLS
; x
++)
115 Numstars
= lp
- Layout
;
119 * Return TRUE if (y, x) is on the current pattern.
125 case 0: /* alternating lines */
128 if (x
>= LINES
&& y
>= NCOLS
)
130 if (y
< 3 || y
>= NLINES
- 3)
132 return (x
< 3 || x
>= NCOLS
- 3);
133 case 2: /* holy pattern! */
134 return ((x
+ y
) & 01);
135 case 3: /* bar across center */
136 return (y
>= 9 && y
<= 15);
149 end
= &Layout
[Numstars
];
150 for (lp
= Layout
; lp
< end
; lp
++) {
151 r
= rand() % Numstars
;
157 for (lp
= Layout
; lp
< end
; lp
++) {
158 mvaddch(lp
->y
, lp
->x
, ch
);