binary printing Python turtle

mail@pastecode.io avatar
unknown
python
2 years ago
1.1 kB
163
Indexable
Never
import turtle

SCALE = 20

def main():
    line = input()
    x = int(line)
    bin_print(x)

def bin_print(number):
    bin_digits = bin(number)[2:]
    for char in bin_digits:
        if char == '0':
            zero()
        else:
            one()

def init():
    turtle.penup()
    turtle.speed(10)
    turtle.goto(-200, 120)
    
def step():
    turtle.penup()
    turtle.forward(SCALE * 1.5)

def zero():
    """ Рисует цифру 0 как на почтовом адресе """
    turtle.pendown()
    for side in 1, 2:
        turtle.forward(SCALE)
        turtle.left(90)
        turtle.forward(SCALE*2)
        turtle.left(90)
    turtle.penup()
    step()
    

def one():
    """ Рисует цифру 1 как на почтовом адресе """
    turtle.penup()
    turtle.forward(SCALE)
    turtle.pendown()
    turtle.left(90)
    turtle.forward(SCALE * 2)
    turtle.left(135)
    turtle.forward(SCALE * 2**0.5)
    turtle.penup()
    turtle.left(90)
    turtle.forward(SCALE * 2**0.5)
    turtle.left(45)
    step()

if __name__ == "__main__":
    init()
    main()