@@ -485,25 +485,25 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_line_obj, 6, 6, framebuf_lin
485485#define ELLIPSE_MASK_Q3 (0x04)
486486#define ELLIPSE_MASK_Q4 (0x08)
487487
488- STATIC void draw_ellipse_points (const mp_obj_framebuf_t * fb , mp_int_t cx , mp_int_t cy , mp_int_t x , mp_int_t y , mp_int_t col , mp_int_t mask ) {
488+ STATIC void draw_ellipse_points (const mp_obj_framebuf_t * fb , mp_int_t cx , mp_int_t cy , mp_int_t x , mp_int_t y , mp_int_t col , mp_int_t mask , mp_int_t ex , mp_int_t ey ) {
489489 if (mask & ELLIPSE_MASK_FILL ) {
490490 if (mask & ELLIPSE_MASK_Q1 ) {
491- fill_rect (fb , cx , cy - y , x + 1 , 1 , col );
491+ fill_rect (fb , cx , cy - y - ey , x + 1 + ex , 1 , col );
492492 }
493493 if (mask & ELLIPSE_MASK_Q2 ) {
494- fill_rect (fb , cx - x , cy - y , x + 1 , 1 , col );
494+ fill_rect (fb , cx - x - ex , cy - y - ey , x + 1 + ex , 1 , col );
495495 }
496496 if (mask & ELLIPSE_MASK_Q3 ) {
497- fill_rect (fb , cx - x , cy + y , x + 1 , 1 , col );
497+ fill_rect (fb , cx - x - ex , cy + y + ey , x + 1 + ex , 1 , col );
498498 }
499499 if (mask & ELLIPSE_MASK_Q4 ) {
500- fill_rect (fb , cx , cy + y , x + 1 , 1 , col );
500+ fill_rect (fb , cx , cy + y + ey , x + 1 + ex , 1 , col );
501501 }
502502 } else {
503- setpixel_checked (fb , cx + x , cy - y , col , mask & ELLIPSE_MASK_Q1 );
504- setpixel_checked (fb , cx - x , cy - y , col , mask & ELLIPSE_MASK_Q2 );
505- setpixel_checked (fb , cx - x , cy + y , col , mask & ELLIPSE_MASK_Q3 );
506- setpixel_checked (fb , cx + x , cy + y , col , mask & ELLIPSE_MASK_Q4 );
503+ setpixel_checked (fb , cx + x + ex , cy - y - ey , col , mask & ELLIPSE_MASK_Q1 );
504+ setpixel_checked (fb , cx - x - ex , cy - y - ey , col , mask & ELLIPSE_MASK_Q2 );
505+ setpixel_checked (fb , cx - x - ex , cy + y + ey , col , mask & ELLIPSE_MASK_Q3 );
506+ setpixel_checked (fb , cx + x + ex , cy + y + ey , col , mask & ELLIPSE_MASK_Q4 );
507507 }
508508}
509509
@@ -517,6 +517,14 @@ STATIC mp_obj_t framebuf_ellipse(size_t n_args, const mp_obj_t *args_in) {
517517 } else {
518518 mask |= ELLIPSE_MASK_ALL ;
519519 }
520+ mp_int_t ex = 0 ;
521+ mp_int_t ey = 0 ;
522+ if (n_args > 8 ) {
523+ ex = mp_obj_get_int (args_in [8 ]);
524+ }
525+ if (n_args > 9 ) {
526+ ey = mp_obj_get_int (args_in [9 ]);
527+ }
520528 mp_int_t two_asquare = 2 * args [2 ] * args [2 ];
521529 mp_int_t two_bsquare = 2 * args [3 ] * args [3 ];
522530 mp_int_t x = args [2 ];
@@ -527,7 +535,7 @@ STATIC mp_obj_t framebuf_ellipse(size_t n_args, const mp_obj_t *args_in) {
527535 mp_int_t stoppingx = two_bsquare * args [2 ];
528536 mp_int_t stoppingy = 0 ;
529537 while (stoppingx >= stoppingy ) { // 1st set of points, y' > -1
530- draw_ellipse_points (self , args [0 ], args [1 ], x , y , args [4 ], mask );
538+ draw_ellipse_points (self , args [0 ], args [1 ], x , y , args [4 ], mask , ex , ey );
531539 y += 1 ;
532540 stoppingy += two_asquare ;
533541 ellipse_error += ychange ;
@@ -548,7 +556,7 @@ STATIC mp_obj_t framebuf_ellipse(size_t n_args, const mp_obj_t *args_in) {
548556 stoppingx = 0 ;
549557 stoppingy = two_asquare * args [3 ];
550558 while (stoppingx <= stoppingy ) { // 2nd set of points, y' < -1
551- draw_ellipse_points (self , args [0 ], args [1 ], x , y , args [4 ], mask );
559+ draw_ellipse_points (self , args [0 ], args [1 ], x , y , args [4 ], mask , ex , ey );
552560 x += 1 ;
553561 stoppingx += two_bsquare ;
554562 ellipse_error += xchange ;
@@ -560,9 +568,19 @@ STATIC mp_obj_t framebuf_ellipse(size_t n_args, const mp_obj_t *args_in) {
560568 ychange += two_asquare ;
561569 }
562570 }
571+ if (ex && ey ) {
572+ if (mask & ELLIPSE_MASK_FILL ) {
573+ fill_rect (self , args [0 ] - ex - args [2 ], args [1 ] - ey , (ex + args [2 ]) * 2 + 1 , ey * 2 , args [4 ]);
574+ } else {
575+ fill_rect (self , args [0 ] - ex , args [1 ] - ey - args [3 ], ex * 2 , 1 , args [4 ]);
576+ fill_rect (self , args [0 ] - ex , args [1 ] + ey + args [3 ], ex * 2 , 1 , args [4 ]);
577+ fill_rect (self , args [0 ] - ex - args [2 ], args [1 ] - ey , 1 , ey * 2 , args [4 ]);
578+ fill_rect (self , args [0 ] + ex + args [2 ], args [1 ] - ey , 1 , ey * 2 , args [4 ]);
579+ }
580+ }
563581 return mp_const_none ;
564582}
565- STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (framebuf_ellipse_obj , 6 , 8 , framebuf_ellipse );
583+ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (framebuf_ellipse_obj , 6 , 10 , framebuf_ellipse );
566584
567585#if MICROPY_PY_ARRAY && !MICROPY_ENABLE_DYNRUNTIME
568586// TODO: poly needs mp_binary_get_size & mp_binary_get_val_array which aren't
0 commit comments