Added MP3::Info.pm inside script to make it standalone.
[kugel-rb.git] / apps / plugins / snow.c
blob3ef34bb8b8ebae92812f1743cea0f18b5564a30c
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Itai Shaked
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.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 **************************************************************************/
19 #include "plugin.h"
21 #ifdef HAVE_LCD_BITMAP
23 #define NUM_PARTICLES 100
25 static short particles[NUM_PARTICLES][2];
26 static struct plugin_api* rb;
28 static bool particle_exists(int particle)
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;
37 static int create_particle(void)
39 int i;
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;
48 return -1;
51 static void snow_move(void)
53 int i;
55 if (!(rb->rand()%2))
56 create_particle();
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;
66 case 1:
67 particles[i][0]--;
68 break;
70 case 2:
71 break;
73 default:
74 particles[i][1]++;
75 break;
77 if (particle_exists(i))
78 rb->lcd_drawpixel(particles[i][0],particles[i][1]);
83 static void snow_init(void)
85 int i;
87 for (i=0; i<NUM_PARTICLES; i++) {
88 particles[i][0]=-1;
89 particles[i][1]=-1;
91 rb->lcd_clear_display();
94 enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
96 int button;
97 TEST_PLUGIN_API(api);
98 (void)(parameter);
99 rb = api;
101 snow_init();
102 while (1) {
103 snow_move();
104 rb->lcd_update();
105 rb->sleep(HZ/20);
107 button = rb->button_get(false);
109 if (button == BUTTON_OFF)
110 return PLUGIN_OK;
111 else
112 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
113 return PLUGIN_USB_CONNECTED;
117 #endif