from datetime import datetime as dt from bitmap import Bitmap, PilBitmap h = 500 w = 500 image = Bitmap(w, h, alpha=True) pil_image = PilBitmap(w, h, alpha=True) color_red = 0 for i in range(h): for j in range(w): image.set_rgba_pixel(j, i, color_red, 0, 0, 150) pil_image.set_rgba_pixel(j, i, color_red, 0, 0, 150) color_red += 1 path = "images/im1_" + dt.now().strftime("%Y-%m-%d_%H:%M:%S") + ".png" print("Image saved: " + path) image.save_as_png(path) path = "images/im2_" + dt.now().strftime("%Y-%m-%d_%H:%M:%S") + ".png" print("Image saved: " + path) pil_image.save_as_png(path)
def triangle_shape(x0, y0, x1, y1, x2, y2, image: Bitmap, color): line(x0, y0, x1, y1, image, color) line(x0, y0, x2, y2, image, color) line(x2, y2, x1, y1, image, color) def triangle_a_shape(x0, y0, x1, y1, x2, y2, image: Bitmap, color): line_a(x0, y0, x1, y1, image, color) line_a(x0, y0, x2, y2, image, color) line_a(x2, y2, x1, y1, image, color) if __name__ == "__main__": from timeit import default_timer as timer from datetime import datetime as dt h = 256 w = 256 im = Bitmap(w, h) line_a(10, 10, 150, 30, im, Color(255, 255, 0)) line(10, 20, 150, 40, im, Color(255, 255, 0)) triangle_shape(150, 150, 200, 80, 95, 123, im, Color(255, 255, 0)) triangle_a_shape(120, 120, 170, 50, 65, 93, im, Color(255, 255, 0)) path = "images/im_" + dt.now().strftime("%Y-%m-%d_%H:%M:%S") + ".png" print("Image saved: " + path) im.save_as_png(path)