Spaces:
Sleeping
Sleeping
Download simulator.py from jk10978/bitmap-simulator: direct link, hf CLI and curl.
- Browser
- Download file 2.51 kB
-
https://huggingface.co/spaces/jk10978/bitmap-simulator/resolve/main/simulator.py
- Command line
-
hf download hf://spaces/jk10978/bitmap-simulator/simulator.py
-
curl -L -o simulator.py https://huggingface.co/spaces/jk10978/bitmap-simulator/resolve/main/simulator.py
2.51 kB
| from PIL import Image | |
| def get_coordinates_from_index(index, width, height): | |
| if index < 0 or index >= width * height: | |
| return print("Error: Index out of range") | |
| x = index % width | |
| y = index // width | |
| return x, y | |
| def get_new_coordinates(coordinates): | |
| x, y = coordinates | |
| # if x=0 then new_x= 2, if index=1 then new_x= 7, if index=2 then new_x= 12, if index=3 then new_x= 2, if index=4 then new_x= 7, if index=5 then new_x= 12 | |
| new_x = x * 6 + 2 | |
| new_y = y * 6 + 2 | |
| return new_x, new_y | |
| # Increase RGB value by 50 but not (0, 0, 0) values | |
| def increase_rgb_value(color): | |
| r, g, b = color | |
| if r == 0 and g == 0 and b == 0: | |
| return r, g, b | |
| r += 100 | |
| g += 100 | |
| b += 100 | |
| return r, g, b | |
| def draw_new_pixel(image, coordinates, color): | |
| x, y = coordinates | |
| color = increase_rgb_value(color) | |
| image.putpixel(coordinates, color) | |
| image.putpixel((x + 1, y), color) | |
| image.putpixel((x + 2, y), color) | |
| image.putpixel((x - 1, y), color) | |
| image.putpixel((x - 2, y), color) | |
| image.putpixel((x, y + 1), color) | |
| image.putpixel((x, y + 2), color) | |
| image.putpixel((x, y - 1), color) | |
| image.putpixel((x, y - 2), color) | |
| image.putpixel((x + 1, y + 1), color) | |
| image.putpixel((x - 1, y - 1), color) | |
| image.putpixel((x + 1, y - 1), color) | |
| image.putpixel((x - 1, y + 1), color) | |
| def simulate_bitmap(image): | |
| width, height = image.size | |
| list_of_pixels = list(image.getdata()) | |
| # Calculate new Canvas size | |
| new_width = width * 6 | |
| new_height = height * 6 | |
| # Create new image | |
| new_image = Image.new("RGB", (new_width, new_height)) | |
| width, height = image.size | |
| list_of_pixels = list(image.getdata()) | |
| for index, color in enumerate(list_of_pixels): | |
| draw_new_pixel( | |
| new_image, | |
| get_new_coordinates(get_coordinates_from_index(index, width, height)), | |
| color, | |
| ) | |
| new_image.save("tmp/simulated_bitmap.bmp") | |
| return new_image | |
| """ # Open the original .bmp file | |
| image = Image.open("output/combined_output.bmp") | |
| width, height = image.size | |
| list_of_pixels = list(image.getdata()) | |
| print(list_of_pixels) | |
| # Calculate new Canvas size | |
| new_width = width * 6 | |
| new_height = height * 6 | |
| # Create new image | |
| new_image = Image.new("RGB", (new_width, new_height)) | |
| # Draw new image | |
| for index, color in enumerate(list_of_pixels): | |
| draw_new_pixel(get_new_coordinates(get_coordinates_from_index(index)), color) | |
| new_image.save("output/output.bmp") """ | |