Pages

Wednesday, December 19, 2018

All possible combinations in a 7 segment display

I was playing around with a display of 7 segment digits and was looking for some cool shape I could print in it. I wasn't been very creative and I noticed that, after all, only 128 combinations can be made with those kinds of displays. So I decided to write a dirty Python 3 script for generating all possible combinations, and here I show you the output.



I also leave here the dirty script.


import os

#params
width = 20 #how many each row
q = 128 #how many in total

def gen7seg(segs):
    line1 = ""
    line2 = ""
    line3 = ""

    line1 += " "
    if( (segs >> 6) & 1): line1 += "_ "
    else: line1 += "  "
    
    if( (segs >> 1) & 1): line2 += "|"
    else: line2 += " "
    if( (segs >> 0) & 1): line2 += "_"
    else: line2 += " "
    if( (segs >> 5) & 1): line2 += "|"
    else: line2 += " "

    if( (segs >> 2) & 1): line3 += "|"
    else: line3 += " "
    if( (segs >> 3) & 1): line3 += "_"
    else: line3 += " " 
    if( (segs >> 4) & 1): line3 += "|"
    else: line3 += " "

    return [line1, line2, line3]   

printed = 0

finished = False
while(not finished):
    out_line1 = ""
    out_line2 = ""
    out_line3 = ""
    for _ in range(width):
        [a, b, c] = gen7seg(printed)
        out_line1 += (" " + a)
        out_line2 += (" " + b)
        out_line3 += (" " + c)
        if(printed < q-1): printed += 1
        else: 
            finished = True
            break
    
    print(out_line1)
    print(out_line2)
    print(out_line3)


input()




Speak if it was useful for something.

No comments:

Post a Comment