Example #1
0
    def __init__(self, height, path):
        self.w, self.h, self.frame = image2term(path, height=height)
        self.x = self.y = 0

        tw, th = get_terminal_size_in_pixels()
        self.set_pos(tw / 2 - self.w / 2, th / 2 - self.h / 2)

        bapho_head = image2term('img/baphomet_head.gif',
                                height=0.8 * self.h,
                                invert=True)
        self.frame.extend(
            set_pos(bapho_head[2], self.x + self.w / 2 - bapho_head[0] / 2,
                    self.y + self.h / 2 - bapho_head[1] / 2))

        bapho_title = image2term('img/baphomet_title.jpg',
                                 height=85,
                                 invert=True)
        self.frame.extend(
            set_pos(bapho_title[2], self.x + self.w / 2 - bapho_title[0] / 2,
                    self.y - 20 - bapho_title[1] / 2))

        # Generate seeds.
        random.seed(datetime.now())
        self.seeds = self.generate_seeds(NUM_SEEDS)
        self.reset_seeds_frame()

        # Snakes.
        self.snakes = None
Example #2
0
def image2term(image, threshold=128, height=None, invert=False):
    if image not in img_cache:
        if image.startswith('http://') or image.startswith('https://'):
            i = Image.open(StringIO(
                urllib2.urlopen(image).read())).convert('L')
        else:
            i = Image.open(open(image)).convert('L')

        w, h = i.size
        if height:
            ratio = height / float(h)

            w = int(w * ratio)
            h = int(h * ratio)
            i = i.resize((w, h), Image.ANTIALIAS)
        else:
            tw, th = get_terminal_size_in_pixels()
            if tw < w:
                ratio = tw / float(w)
                w = tw
                h = int(h * ratio)
                if th < h:
                    h = th
            elif th < h:
                ratio = th / float(h)
                h = th
                w = int(w * ratio)
                if tw < w:
                    w = tw
            i = i.resize((w, h), Image.ANTIALIAS)
        img_cache[image] = i

    x = y = 0
    i = img_cache[image]
    w, h = i.size
    frame = []

    try:
        i_converted = i.tobytes()
    except AttributeError:
        i_converted = i.tostring()

    for pix in i_converted:
        if invert:
            if ord(pix) > threshold:
                frame.append((x, y, COLOR_WHITE))
        else:
            if ord(pix) < threshold:
                frame.append((x, y, COLOR_WHITE))
        x += 1
        if x >= w:
            y += 1
            x = 0
    return (w, h, frame)
Example #3
0
def image2term(image, threshold=128, height=None, invert=False):
    if image not in img_cache:
        if image.startswith('http://') or image.startswith('https://'):
            i = Image.open(StringIO(urllib2.urlopen(image).read())).convert('L')
        else:
            i = Image.open(open(image)).convert('L')

        w, h = i.size
        if height:
            ratio = height/float(h)

            w = int(w * ratio)
            h = int(h * ratio)
            i = i.resize((w, h), Image.ANTIALIAS)
        else:
            tw,th = get_terminal_size_in_pixels()
            if tw < w:
                ratio = tw / float(w)
                w = tw
                h = int(h * ratio)
                if th < h:
                    h = th
            elif th < h:
                ratio = th / float(h)
                h = th
                w = int(w * ratio)
                if tw < w:
                    w = tw
            i = i.resize((w, h), Image.ANTIALIAS)
        img_cache[image] = i

    x = y = 0
    i = img_cache[image]
    w,h = i.size
    frame = []

    try:
         i_converted = i.tobytes()
    except AttributeError:
         i_converted = i.tostring()

    for pix in i_converted:
        if invert:
            if ord(pix) > threshold:
                frame.append((x,y,COLOR_WHITE))
        else:
            if ord(pix) < threshold:
                frame.append((x,y,COLOR_WHITE))
        x += 1
        if x >= w:
            y += 1
            x = 0
    return (w,h,frame)
Example #4
0
    def __init__(self,height,path):
        self.w, self.h, self.frame = image2term(path,height=height)
        self.x = self.y = 0

        tw, th = get_terminal_size_in_pixels()
        self.set_pos(tw/2 - self.w/2,th/2 - self.h/2)

        bapho_head = image2term('img/baphomet_head.gif', height=0.8*self.h, invert=True)
        self.frame.extend(set_pos(bapho_head[2],self.x + self.w/2 - bapho_head[0]/2,self.y + self.h/2 - bapho_head[1]/2))

        bapho_title = image2term('img/baphomet_title.jpg', height=85,invert=True)
        self.frame.extend(set_pos(bapho_title[2],self.x + self.w/2 - bapho_title[0]/2,self.y - 20 - bapho_title[1]/2))

        # Generate seeds.
        random.seed(datetime.now())
        self.seeds = self.generate_seeds(NUM_SEEDS)
        self.reset_seeds_frame()

        # Snakes.
        self.snakes = None