1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2004 Matthias Wientapper
13 * All files in this archive are subject to the GNU General Public License.
14 * See the file COPYING in the source tree root for full license agreement.
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
19 ****************************************************************************/
23 #ifdef HAVE_LCD_BITMAP // this is not fun on the player
26 static struct plugin_api
* rb
;
28 static int lcd_aspect_ratio
;
35 static unsigned char *gbuf
;
36 static unsigned int gbuf_size
= 0;
39 void init_mandelbrot_set(void){
40 x_min
= -5<<25; // -2.0<<26
41 x_max
= 1<<26; // 1.0<<26
42 y_min
= -1<<26; // -1.0<<26
43 y_max
= 1<<26; // 1.0<<26
44 delta
= (x_max
- x_min
) >> 3; // /8
48 void calc_mandelbrot_set(void){
50 unsigned int start_tick
;
53 int x
, x2
, y
, y2
, a
, b
;
57 start_tick
= *rb
->current_tick
;
59 // rb->lcd_clear_display();
64 x_fact
= (x_max
- x_min
) / LCD_WIDTH
;
65 y_fact
= (y_max
- y_min
) / LCD_HEIGHT
;
67 for(y_pixel
= LCD_HEIGHT
-1; y_pixel
>=0; y_pixel
--){
68 b
= (y_pixel
* y_fact
) + y_min
;
69 for (x_pixel
= LCD_WIDTH
-1; x_pixel
>=0; x_pixel
--){
70 a
= (x_pixel
* x_fact
) + x_min
;
75 while (++n_iter
<=max_iter
) {
81 if (x2
+ y2
> (4<<26)) break;
89 if (n_iter
> max_iter
){
90 brightness
= 0; // black
92 brightness
= 255 - (31 * (n_iter
& 7));
95 gray_drawpixel( x_pixel
, y_pixel
, brightness
);
101 enum plugin_status
plugin_start(struct plugin_api
* api
, void* parameter
)
106 TEST_PLUGIN_API(api
);
110 /* This plugin uses the grayscale framework, so initialize */
113 /* get the remainder of the plugin buffer */
114 gbuf
= (unsigned char *) rb
->plugin_get_buffer(&gbuf_size
);
116 /* initialize the grayscale buffer:
117 * 112 pixels wide, 8 rows (64 pixels) high, (try to) reserve
118 * 16 bitplanes for 17 shades of gray.*/
119 grayscales
= gray_init_buffer(gbuf
, gbuf_size
, 112, 8, 16, NULL
) + 1;
120 if (grayscales
!= 17){
121 rb
->snprintf(buff
, sizeof(buff
), "%d", grayscales
);
122 rb
->lcd_puts(0, 1, buff
);
128 gray_show_display(true); /* switch on grayscale overlay */
130 init_mandelbrot_set();
131 lcd_aspect_ratio
= ((LCD_WIDTH
<<13) / LCD_HEIGHT
)<<13;
136 calc_mandelbrot_set();
140 switch (rb
->button_get(true)) {
142 gray_release_buffer();
146 x_min
-= ((delta
>>13)*(lcd_aspect_ratio
>>13));
147 x_max
+= ((delta
>>13)*(lcd_aspect_ratio
>>13));
150 delta
= (x_max
- x_min
) >> 3;
156 x_min
+= ((delta
>>13)*(lcd_aspect_ratio
>>13));
157 x_max
-= ((delta
>>13)*(lcd_aspect_ratio
>>13));
160 delta
= (x_max
- x_min
) >> 3;
203 init_mandelbrot_set();
207 case SYS_USB_CONNECTED
:
208 gray_release_buffer();
210 return PLUGIN_USB_CONNECTED
;
213 gray_release_buffer();