summaryrefslogtreecommitdiff
path: root/apps/plugins/snow.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/snow.c')
-rw-r--r--apps/plugins/snow.c111
1 files changed, 111 insertions, 0 deletions
diff --git a/apps/plugins/snow.c b/apps/plugins/snow.c
new file mode 100644
index 0000000000..df9966eb38
--- /dev/null
+++ b/apps/plugins/snow.c
@@ -0,0 +1,111 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 Itai Shaked
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 **************************************************************************/
19#include "plugin.h"
20
21#ifdef HAVE_LCD_BITMAP
22
23#define NUM_PARTICLES 100
24
25static short particles[NUM_PARTICLES][2];
26static struct plugin_api* rb;
27
28static bool particle_exists(int particle)
29{
30 if (particles[particle][0]>=0 && particles[particle][1]>=0 &&
31 particles[particle][0]<112 && particles[particle][1]<64)
32 return true;
33 else
34 return false;
35}
36
37static int create_particle(void)
38{
39 int i;
40
41 for (i=0; i<NUM_PARTICLES; i++) {
42 if (!particle_exists(i)) {
43 particles[i][0]=(rb->rand()%112);
44 particles[i][1]=0;
45 return i;
46 }
47 }
48 return -1;
49}
50
51static void snow_move(void)
52{
53 int i;
54
55 if (!(rb->rand()%2))
56 create_particle();
57
58 for (i=0; i<NUM_PARTICLES; i++) {
59 if (particle_exists(i)) {
60 rb->lcd_clearpixel(particles[i][0],particles[i][1]);
61 switch ((rb->rand()%7)) {
62 case 0:
63 particles[i][0]++;
64 break;
65
66 case 1:
67 particles[i][0]--;
68 break;
69
70 case 2:
71 break;
72
73 default:
74 particles[i][1]++;
75 break;
76 }
77 if (particle_exists(i))
78 rb->lcd_drawpixel(particles[i][0],particles[i][1]);
79 }
80 }
81}
82
83static void snow_init(void)
84{
85 int i;
86
87 for (i=0; i<NUM_PARTICLES; i++) {
88 particles[i][0]=-1;
89 particles[i][1]=-1;
90 }
91 rb->lcd_clear_display();
92}
93
94enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
95{
96 TEST_PLUGIN_API(api);
97 (void)(parameter);
98 rb = api;
99
100 snow_init();
101 while (1) {
102 snow_move();
103 rb->lcd_update();
104 rb->sleep(HZ/20);
105
106 if (rb->button_get(false) == BUTTON_OFF)
107 return false;
108 }
109}
110
111#endif