home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
MM1
/
GRAPHICS
/
ssaver.lzh
/
SRC
/
saver_lines.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-11-02
|
3KB
|
165 lines
/* saver_lines.c */
/* by Joel Mathew Hegberg */
/* a simple ssaver screen-saver program */
/* which runs on any type screen. */
#include <stdio.h>
#include "saver.h"
int orgwin, win, twin;
int gotosleep = FALSE;
int sigcode = 0;
int x1, y1;
int x2, y2;
int dx1, dy1;
int dx2, dy2;
int mx1, my1;
int mx2, my2;
int counter;
int color, maxcolors;
sighandler(signal)
int signal;
{
switch (signal) {
case SLEEP_SIG:
gotosleep = TRUE;
break;
case WAKE_SIG:
gotosleep = FALSE;
break;
case QUIT_SIG:
default:
gotosleep = FALSE;
sigcode = signal;
if (_gs_currscr(STDOUT,&twin) == -1)
exit(0);
if (twin == win) {
_ss_select(STDOUT, orgwin);
}
}
}
main()
{
int evID; /* event ID */
sigmask(1); /* mask signals */
intercept(sighandler);
if ((evID = _ev_link(EV_NAME)) == -1)
exit(1);
DWSet(STDOUT, 0, 0, 0, 80, 26, 0, 0, 1);
if (_gs_currscr(STDOUT,&orgwin) == -1)
exit(0);
CurOff(STDOUT);
BColor(STDOUT, 0);
_gs_wdev(STDOUT, &win); /* get our window device number */
_ss_select(STDOUT, win); /* now select it! */
init_saver();
sigmask(0); /* unmask signals */
_ev_set(evID, 0, 0x8000); /* wake up everybody */
/* we unlink from the event since we are through with it */
_ev_unlink(evID);
while (!sigcode)
{
if (gotosleep)
sleep(0);
else
do_lines();
}
}
init_saver()
{
/* # of colors available on screen */
maxcolors = Get_Num_Colors(STDOUT);
/* line starting coordinates */
x1 = 50;
x2 = 400;
y1 = 100;
y2 = 200;
/* line movement variables */
dx1 = 2;
dx2 = -3;
dy1 = -1;
dy2 = 2;
/* multipliers */
mx1 = 1;
my1 = 1;
mx2 = 3;
my2 = 2;
counter = 0;
color = 1;
}
do_lines()
{
FColor(STDOUT,color); /* set line color */
SetDPtr(STDOUT,x1,y1); /* start coordinate */
Line(STDOUT,x2,y2); /* draw the line */
/* next, move the line according to directionals */
x1 += dx1 * mx1;
x2 += dx2 * mx2;
y1 += dy1 * my1;
y2 += dy2 * my2;
/* now, check if any directionals need to be reversed */
if (x1 < 0 || x1 > 639)
{
x1 -= dx1 * mx1;
dx1 =- dx1;
if (++mx1 > 5)
mx1 = 1;
}
if (x2 < 0 || x2 > 639)
{
x2 -= dx2 * mx2;
dx2 =- dx2;
if (++mx2 > 5)
mx2 = 1;
}
if (y1 < 0 || y1 > 207)
{
y1 -= dy1 * my1;
dy1 =- dy1;
if (++my1 > 5)
my1 = 1;
}
if (y2 < 0 || y2 > 207)
{
y2 -= dy2 * my2;
dy2 =- dy2;
if (++my2 > 5)
my2 = 1;
}
if (++counter > 500) /* after 500 lines, clear the screen */
{
Clear(STDOUT);
counter = 0;
}
if (++color >= maxcolors)
color = 1; /* select next color */
tsleep(2);
}