Exemplo n.º 1
0
def sphere(r):
    canvas = blank_canvas()
    cx, cy = kWidth//2, kHeight//2
    for x in range(kWidth):
        for y in range(kHeight):
            a = random.uniform(0,1)
            if math.sqrt((x-cx)**2 + (y-cy)**2) < r:
                D = 0.5 + ( math.asin( (x-cx)/math.sqrt(r**2 - (y-cy)**2) ) ) / math.pi
                a = random.uniform(0,1)
                a = norm_exp(a,-1)
                #a = sigmoid(a)
                if a >= D:
                    canvas[y][x] = kBlack
                else:
                    canvas[y][x] = kWhite
            else:
                if (x/kWidth) > a:
                    canvas[y][x] = kBlack

    data = img_to_bytes(canvas)
    P = ThermalPrinter.ThermalPrinter("/dev/ttyUSB0")
    B = Bitmap.Bitmap()
    B.image_data = data
    B.height = kHeight
    B.width_bytes = kWidth//8

    P.print_bitmap(B)
    canvas.reverse()
    P.image_data = img_to_bytes(canvas)
    P.print_bitmap(B)
    P.feed(1)
    P.send_bytes("title1")
    P.feed(3)
Exemplo n.º 2
0
Arquivo: SR1.py Projeto: Carlosc23/SR2
 def glCreateWindow(self, width, height):
     """
     Function that instantiate a new Object from Bitmap, this initialize the framebuffer
     :param width: width of the image that will be render
     :param height: height of the the image that will be render
     :return:
     """
     self.window = Bitmap(width, height)
Exemplo n.º 3
0
def print_work(canvas, title):
    data = img_to_bytes(canvas)
    P = ThermalPrinter.ThermalPrinter("/dev/ttyUSB0")
    B = Bitmap.Bitmap()
    B.image_data = data
    B.height = len(canvas)
    B.width_bytes = len(canvas[0])//8

    P.print_bitmap(B)
    P.feed(1)
    P.send_bytes(title)
    P.feed(3)
Exemplo n.º 4
0
def main():
    # example use  python3 Task_06.py example0.tga -e 4
    tga, header, footer, wid, hi = read_tga(sys.argv[1])
    if sys.argv[2] == '-e':
        bitmap = Bitmap(tga[18:len(tga) - 26], wid, hi)
        k = int(sys.argv[3])
        res1, b, res2, quantified = encode(bitmap, k)
        res1, res2 = bytes(convert_to_list(res1)), bytes(convert_to_list(res2))

        save_output(header, footer, res1, b, res2, quantified)
    elif sys.argv[2] == "-d":
        data = tga[18:-26]
        bitmap = decode(data)
        with open("out_dec_low.tga", "wb") as f:
            f.write(header + bitmap + footer)
Exemplo n.º 5
0
def wolfram_pattern():
    import wolfram

    row = [0]*kWidth
    row[kWidth//2] = 1
    rule = 30

    P = ThermalPrinter.ThermalPrinter("/dev/ttyUSB0")
    B = Bitmap.Bitmap()
    B.width_bytes = len(row)//8
    B.height = 1

    while 1:
        data = img_to_bytes([row])
        P.print_bitmap(B)
        next_row(row, rule, wrap=True)
Exemplo n.º 6
0
def cam_print():
    import cv2 as cv
    P = ThermalPrinter.ThermalPrinter("/dev/ttyUSB0")
    B = Bitmap.Bitmap()
    run = False
    cap = cv.VideoCapture(1)
    cv.namedWindow('image')
    cv.createTrackbar('A','image',0,255,nothing)
    cv.createTrackbar('B','image',0,255,nothing)
    canvas = []

    while True:
        ret, frame = cap.read()
        frame = frame[0:kWidth, 0:kHeight]

        a = cv.getTrackbarPos('A','image')
        b = cv.getTrackbarPos('B','image')
        edges = cv.Canny(frame,a,b)
        cv.imshow("image", edges)

        if run:
            canvas = [edges[100]]
            bw_image(canvas, invert=False)
            data = img_to_bytes(canvas)
            B.image_data = data
            B.height = 1
            B.width_bytes = len(canvas[0])//8
            P.print_bitmap(B)

        key = cv.waitKey(1) & 0xff
        if key == ord('q'):
            break
        elif key == ord('p'):
            if not run:
                canvas = edges.tolist()
                bw_image(canvas, invert=False)
                print_work(canvas, "")
                break
        elif key == ord('r'):
            run = True

    cap.release()
    cv.destroyAllWindows()
Exemplo n.º 7
0
def spheres(max_r, min_r, n):
    P = ThermalPrinter.ThermalPrinter("/dev/ttyUSB0")
    B = Bitmap.Bitmap()
    B.height = kHeight
    B.width_bytes = kWidth//8
    step = (max_r - min_r)//n
    radii = [max_r]
    while max_r - step > min_r:
        max_r -= step
        radii.append(max_r)
        radii.insert(0, max_r)
    canvas = blank_canvas()
    cx, cy = kWidth//2, kHeight//2
    for r in radii:
        for x in range(kWidth):
            for y in range(kHeight):
                a = random.uniform(0,1)
                if math.sqrt((x-cx)**2 + (y-cy)**2) < r:
                    D = 0.5 + ( math.asin( (x-cx)/math.sqrt(r**2 - (y-cy)**2) ) ) / math.pi
                    a = random.uniform(0,1)
                    a = norm_exp(a,-1)
                    #a = sigmoid(a)
                    if a >= D:
                        canvas[y][x] = kBlack
                    else:
                        canvas[y][x] = kWhite
                else:
                    if (x/kWidth) > a:
                        canvas[y][x] = kBlack
                    else:
                        canvas[y][x] = kWhite
        data = img_to_bytes(canvas)
        B.image_data = data
        P.print_bitmap(B)
    P.feed(1)
    P.send_bytes("spheres - chog 2018")
    P.feed(3)
Exemplo n.º 8
0
def long_truchet():
    canvas = blank_canvas()
    for x in range(0, kWidth//kTileSize):
        for y in range(0, kHeight//kTileSize):
            t = random.randint(0, 3)
            draw_truchet_tile(x,y,t, canvas)

    P = ThermalPrinter.ThermalPrinter("/dev/ttyUSB0")
    B = Bitmap.Bitmap()
    B.width_bytes = len(canvas[0])//8
    B.height = 1

    repeat = 1
    for c in canvas:
        data = img_to_bytes([c])
        repeat = repeat + random.randint(-1,1)
        if repeat < 0:
            repeat = 0
        if repeat > 10:
            repeat = 10
        B.image_data = data
        for i in range(repeat):
            P.print_bitmap(B)
    P.feed(1)
Exemplo n.º 9
0
    def print_bitmap(self, bitmap):
        #for i in range(bitmap.height):
        # can only send upto 256 bytes at a time
        chunk_height_limit = 256 // bitmap.width_bytes

        for row in range(bitmap.height):
            self.send_bytes(ASCII_DC2, '*', 1, bitmap.width_bytes)

            for b in bitmap.image_data[row*bitmap.width_bytes: (row+1)*bitmap.width_bytes]:
                self.send_byte(not_byte(b))


#        for row in range(bitmap.height-chunk_height_limit, -1, -1*chunk_height_limit):
#            print("a")
#            self.send_bytes(ASCII_DC2, '*', chunk_height_limit, bitmap.width_bytes)
#            for b in bitmap.image_data[row*bitmap.width_bytes: (row+chunk_height_limit)*bitmap.width_bytes]:
#                self.send_byte(not_byte(b))



if __name__ == "__main__":
    printer = ThermalPrinter("/dev/ttyUSB0")
    printer.feed(2)
    image = Bitmap.Bitmap()
    image.load_file("demo.bmp")
    printer.print_bitmap(image)
    printer.send_bytes("Choggy Carrots - 2018")
    time.sleep(0.5)
    printer.feed(3)
Exemplo n.º 10
0
def glCreateWindow(width, heigth):
    global screen
    screen = Bitmap(width, heigth)