Skip to content

Commit ea774f3

Browse files
Mark Shannondpgeorge
authored andcommitted
Make image repr/str -> constructor round trip.
1 parent c78bdbf commit ea774f3

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

source/microbit/microbitimage.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,22 @@ const monochrome_5by5_t microbit_blank_image = {
4242

4343
STATIC void microbit_image_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
4444
microbit_image_obj_t *self = (microbit_image_obj_t*)self_in;
45-
mp_printf(print, "+");
46-
for (int x = 0; x < self->width(); ++x) {
47-
mp_printf(print, "-");
48-
}
49-
mp_printf(print, "+\n");
45+
mp_printf(print, "Image(");
46+
if (kind == PRINT_STR)
47+
mp_printf(print, "\n ");
48+
mp_printf(print, "'");
5049
for (int y = 0; y < self->height(); ++y) {
51-
mp_printf(print, "|");
5250
for (int x = 0; x < self->width(); ++x) {
5351
mp_printf(print, "%c", " 123456789"[self->getPixelValue(x, y)]);
5452
}
55-
mp_printf(print, "|\n");
56-
}
57-
mp_printf(print, "+");
58-
for (int x = 0; x < self->width(); ++x) {
59-
mp_printf(print, "-");
53+
mp_printf(print, "\\n");
54+
if (kind == PRINT_STR && y < self->height()-1)
55+
mp_printf(print, "'\n '");
6056
}
61-
mp_printf(print, "+\n");
57+
mp_printf(print, "'");
58+
if (kind == PRINT_STR)
59+
mp_printf(print, "\n");
60+
mp_printf(print, ")");
6261
}
6362

6463
uint8_t monochrome_5by5_t::getPixelValue(mp_int_t x, mp_int_t y) {
@@ -674,6 +673,7 @@ const mp_obj_type_t microbit_sliced_image_type = {
674673
.buffer_p = {NULL},
675674
.stream_p = NULL,
676675
.bases_tuple = MP_OBJ_NULL,
676+
MP_OBJ_NULL
677677
};
678678

679679
const mp_obj_type_t microbit_sliced_image_iterator_type = {
@@ -691,6 +691,7 @@ const mp_obj_type_t microbit_sliced_image_iterator_type = {
691691
.buffer_p = {NULL},
692692
.stream_p = NULL,
693693
.bases_tuple = MP_OBJ_NULL,
694+
MP_OBJ_NULL
694695
};
695696

696697
typedef struct _scrolling_string_t {
@@ -778,6 +779,7 @@ const mp_obj_type_t microbit_scrolling_string_type = {
778779
.buffer_p = {NULL},
779780
.stream_p = NULL,
780781
.bases_tuple = MP_OBJ_NULL,
782+
MP_OBJ_NULL
781783
};
782784

783785
const mp_obj_type_t microbit_scrolling_string_iterator_type = {
@@ -795,6 +797,7 @@ const mp_obj_type_t microbit_scrolling_string_iterator_type = {
795797
.buffer_p = {NULL},
796798
.stream_p = NULL,
797799
.bases_tuple = MP_OBJ_NULL,
800+
MP_OBJ_NULL
798801
};
799802

800803
}

0 commit comments

Comments
 (0)