| 30 | |
| 31 | |
| 32 | def drawFromData(image_data, image_width, image_height, left, top, pixel_size): |
| 33 | turtle.penup() |
| 34 | |
| 35 | inBinary = bin(int(image_data, 16)) |
| 36 | |
| 37 | # Remove '0b' from the start of the hex number: |
| 38 | inBinary = inBinary[2:] |
| 39 | |
| 40 | # Add leading zeros to the binary number, if needed: |
| 41 | inBinary = inBinary.rjust(image_width * image_height, '0') |
| 42 | |
| 43 | for y in range(image_height): |
| 44 | for x in range(image_width): |
| 45 | turtle.goto(left + (x * pixel_size), top - (y * pixel_size)) |
| 46 | |
| 47 | if inBinary[y * image_width + x] == '1': # (!) Try switching this to '0'. |
| 48 | turtle.begin_fill() |
| 49 | turtle.setheading(0) |
| 50 | turtle.forward(pixel_size) # draw top of the box |
| 51 | turtle.right(90) |
| 52 | turtle.forward(pixel_size) # draw right edge of the box |
| 53 | turtle.right(90) |
| 54 | turtle.forward(pixel_size) # draw bottom of the box |
| 55 | turtle.right(90) |
| 56 | turtle.forward(pixel_size) # draw left edge of the box |
| 57 | turtle.end_fill() # fill in the box |
| 58 | |
| 59 | |
| 60 | try: |