Can anyone tell me why num_chars and num_rows have to be the same?
from ctypes import *
num_chars = 8
num_rows = 8
num_cols = 6
buffer = create_string_buffer (num_chars*num_rows*num_cols+num_chars)
for char in range(num_chars):
for row in range(num_rows):
for col in range(num_cols):
if char == num_chars-1 and col == num_cols-1:
buffer[row*num_rows*num_cols+char*num_cols+col+row] = '|'
buffer[row*num_rows*num_cols+char*num_cols+col+row+1] = '\n'
elif col == num_cols-1:
buffer[row*num_rows*num_cols+char*num_cols+col+row] = '|'
else:
buffer[row*num_rows*num_cols+char*num_cols+col+row] = ('.', '*')[char>row]
print buffer.value
The output
.....|*****|*****|*****|*****|*****|*****|*****|
.....|.....|*****|*****|*****|*****|*****|*****|
.....|.....|.....|*****|*****|*****|*****|*****|
.....|.....|.....|.....|*****|*****|*****|*****|
.....|.....|.....|.....|.....|*****|*****|*****|
.....|.....|.....|.....|.....|.....|*****|*****|
.....|.....|.....|.....|.....|.....|.....|*****|
.....|.....|.....|.....|.....|.....|.....|.....|
And now changing num_chars to 15.
.....|*****|*****|*****|*****|*****|*****|*****|*****|*****|*****|*****|*****|*****|*****|
*****|*****|*****|*****|*****|*****|*****|*****|
*****|*****|*****|*****|*****|*****|*****|*****|
*****|*****|*****|*****|*****|*****|*****|*****|
*****|*****|*****|*****|*****|*****|*****|*****|
*****|*****|*****|*****|*****|*****|*****|*****|
*****|*****|*****|*****|*****|*****|*****|*****|
.....|*****|*****|*****|*****|*****|*****|*****|