summaryrefslogtreecommitdiff
path: root/apps/plugins/mandelbrot.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/mandelbrot.c')
-rw-r--r--apps/plugins/mandelbrot.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/apps/plugins/mandelbrot.c b/apps/plugins/mandelbrot.c
index 450a4ebfee..786e31dc40 100644
--- a/apps/plugins/mandelbrot.c
+++ b/apps/plugins/mandelbrot.c
@@ -48,14 +48,14 @@ void init_mandelbrot_set(void){
48 48
49void calc_mandelbrot_set(void){ 49void calc_mandelbrot_set(void){
50 50
51 unsigned int start_tick; 51 unsigned int start_tick, last_yield;
52 int n_iter; 52 int n_iter;
53 int x_pixel, y_pixel; 53 int x_pixel, y_pixel;
54 int x, x2, y, y2, a, b; 54 int x, x2, y, y2, a, b;
55 int x_fact, y_fact; 55 int x_fact, y_fact;
56 int brightness; 56 int brightness;
57 57
58 start_tick = *rb->current_tick; 58 start_tick = last_yield = *rb->current_tick;
59 59
60 gray_clear_display(); 60 gray_clear_display();
61 61
@@ -63,9 +63,9 @@ void calc_mandelbrot_set(void){
63 y_fact = (y_max - y_min) / LCD_HEIGHT; 63 y_fact = (y_max - y_min) / LCD_HEIGHT;
64 64
65 for (x_pixel = 0; x_pixel<LCD_WIDTH; x_pixel++){ 65 for (x_pixel = 0; x_pixel<LCD_WIDTH; x_pixel++){
66 a = (x_pixel * x_fact) + x_min; 66 a = (x_pixel * x_fact) + x_min;
67 for(y_pixel = LCD_HEIGHT-1; y_pixel>=0; y_pixel--){ 67 for(y_pixel = LCD_HEIGHT-1; y_pixel>=0; y_pixel--){
68 b = (y_pixel * y_fact) + y_min; 68 b = (y_pixel * y_fact) + y_min;
69 x = 0; 69 x = 0;
70 y = 0; 70 y = 0;
71 n_iter = 0; 71 n_iter = 0;
@@ -89,9 +89,15 @@ void calc_mandelbrot_set(void){
89 } else { 89 } else {
90 brightness = 255 - (31 * (n_iter & 7)); 90 brightness = 255 - (31 * (n_iter & 7));
91 } 91 }
92 graybuffer[y_pixel]=brightness; 92 graybuffer[y_pixel]=brightness;
93 /* be nice to other threads:
94 * if at least one tick has passed, yield */
95 if (*rb->current_tick > last_yield){
96 rb->yield();
97 last_yield = *rb->current_tick;
98 }
93 } 99 }
94 gray_drawgraymap(graybuffer, x_pixel, 0, 1, LCD_HEIGHT, 1); 100 gray_drawgraymap(graybuffer, x_pixel, 0, 1, LCD_HEIGHT, 1);
95 } 101 }
96} 102}
97 103