Here, I quickly whipped something. It takes arguments for the width and height of the cube. Since the slope of the ribs may vary, it does not elegantly handle different slopes; it just uses a period symbol for sloping edges (and a channel for vertical edges). Here is the code:
from math import sqrt def draw_cube(width, height): cube = [[' ']*width for row in range(height)] vertices = { 'tc': (width//2, 0), 'tl': (0, int(.25*height)), 'tr': (width-1, int(.25*height)), 'cc': (width//2, int(.5*height)), 'bl': (0, int(.75*height)), 'br': (width-1, int(.75*height)), 'bc': (width//2, height-1) } edges = ( ('tc', 'tl'), ('tc', 'tr'), ('tl', 'cc'), ('tl', 'bl'), ('tr', 'cc'), ('tr', 'br'), ('bl', 'bc'), ('br', 'bc'), ('cc', 'bc') ) for edge in edges: v1 = vertices[edge[0]] v2 = vertices[edge[1]] x1 = v1[0] y1 = v1[1] x2 = v2[0] y2 = v2[1] if x1 > x2:
What prints:
....... .... .... .... .... .... .... .... ... |... ...| | .... .... | | .... .... | | .... .... | | .... ... | | | | | | | | | | | | | | | | ...... | .... ..... | ..... ..... | ..... ....|.... .
source share