OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [services/] [curses/] [pdcurses/] [current/] [tests/] [firework.c] - Blame information for rev 819

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
/* $Id: firework.c,v 1.1 2009/05/10 08:29:53 jld Exp $ */
2
 
3
#include <stdio.h>
4
#include <signal.h>
5
#include <curses.h>
6
#include <ctype.h>
7
#include <stdlib.h>
8
#include <sys/types.h>
9
#include <time.h>
10
 
11
#define DELAYSIZE 200
12
 
13
void myrefresh(void);
14
void get_color(void);
15
void explode(int, int);
16
 
17
short color_table[] =
18
{
19
    COLOR_RED, COLOR_BLUE, COLOR_GREEN, COLOR_CYAN,
20
    COLOR_RED, COLOR_MAGENTA, COLOR_YELLOW, COLOR_WHITE
21
};
22
 
23
int main(int argc, char **argv)
24
{
25
    int i, start, end, row, diff, flag, direction, seed;
26
 
27
#ifdef XCURSES
28
    Xinitscr(argc, argv);
29
#else
30
    initscr();
31
#endif
32
    nodelay(stdscr, TRUE);
33
    noecho();
34
 
35
    if (has_colors())
36
        start_color();
37
 
38
    for (i = 0; i < 8; i++)
39
        init_pair(i, color_table[i], COLOR_BLACK);
40
 
41
    seed = time((time_t *)0);
42
    srand(seed);
43
    flag = 0;
44
 
45
    while (getch() == ERR)      /* loop until a key is hit */
46
    {
47
        do {
48
            start = rand() % (COLS - 3);
49
            end = rand() % (COLS - 3);
50
            start = (start < 2) ? 2 : start;
51
            end = (end < 2) ? 2 : end;
52
            direction = (start > end) ? -1 : 1;
53
            diff = abs(start - end);
54
 
55
        } while (diff < 2 || diff >= LINES - 2);
56
 
57
        attrset(A_NORMAL);
58
 
59
        for (row = 0; row < diff; row++)
60
        {
61
            mvaddstr(LINES - row, row * direction + start,
62
                (direction < 0) ? "\\" : "/");
63
 
64
            if (flag++)
65
            {
66
                myrefresh();
67
                erase();
68
                flag = 0;
69
            }
70
        }
71
 
72
        if (flag++)
73
        {
74
            myrefresh();
75
            flag = 0;
76
        }
77
 
78
        explode(LINES - row, diff * direction + start);
79
        erase();
80
        myrefresh();
81
    }
82
 
83
    endwin();
84
 
85
    return 0;
86
}
87
 
88
void explode(int row, int col)
89
{
90
    erase();
91
    mvaddstr(row, col, "-");
92
    myrefresh();
93
 
94
    --col;
95
 
96
    get_color();
97
    mvaddstr(row - 1, col, " - ");
98
    mvaddstr(row,     col, "-+-");
99
    mvaddstr(row + 1, col, " - ");
100
    myrefresh();
101
 
102
    --col;
103
 
104
    get_color();
105
    mvaddstr(row - 2, col, " --- ");
106
    mvaddstr(row - 1, col, "-+++-");
107
    mvaddstr(row,     col, "-+#+-");
108
    mvaddstr(row + 1, col, "-+++-");
109
    mvaddstr(row + 2, col, " --- ");
110
    myrefresh();
111
 
112
    get_color();
113
    mvaddstr(row - 2, col, " +++ ");
114
    mvaddstr(row - 1, col, "++#++");
115
    mvaddstr(row,     col, "+# #+");
116
    mvaddstr(row + 1, col, "++#++");
117
    mvaddstr(row + 2, col, " +++ ");
118
    myrefresh();
119
 
120
    get_color();
121
    mvaddstr(row - 2, col, "  #  ");
122
    mvaddstr(row - 1, col, "## ##");
123
    mvaddstr(row,     col, "#   #");
124
    mvaddstr(row + 1, col, "## ##");
125
    mvaddstr(row + 2, col, "  #  ");
126
    myrefresh();
127
 
128
    get_color();
129
    mvaddstr(row - 2, col, " # # ");
130
    mvaddstr(row - 1, col, "#   #");
131
    mvaddstr(row,     col, "     ");
132
    mvaddstr(row + 1, col, "#   #");
133
    mvaddstr(row + 2, col, " # # ");
134
    myrefresh();
135
}
136
 
137
void myrefresh(void)
138
{
139
    napms(DELAYSIZE);
140
    move(LINES - 1, COLS - 1);
141
    refresh();
142
}
143
 
144
void get_color(void)
145
{
146
    chtype bold = (rand() % 2) ? A_BOLD : A_NORMAL;
147
    attrset(COLOR_PAIR(rand() % 8) | bold);
148
}

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.