File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -465,3 +465,36 @@ def fn_with_code_in_docstring():
465465 True.
466466 """
467467 return True
468+
469+
470+ class BinaryCanvas (object ):
471+ """A canvas with which to make binary art, one bit at a time."""
472+
473+ def __init__ (self , size = 10 ):
474+ self .pixels = [[0 ] * size for _ in range (size )]
475+ self ._size = size
476+ self ._row = 0 # The row of the cursor.
477+ self ._col = 0 # The column of the cursor.
478+
479+ def __str__ (self ):
480+ return '\n ' .join (
481+ ' ' .join (str (pixel ) for pixel in row ) for row in self .pixels )
482+
483+ def show (self ):
484+ print (self )
485+ return self
486+
487+ def move (self , row , col ):
488+ self ._row = row % self ._size
489+ self ._col = col % self ._size
490+ return self
491+
492+ def on (self ):
493+ return self .set (1 )
494+
495+ def off (self ):
496+ return self .set (0 )
497+
498+ def set (self , value ):
499+ self .pixels [self ._row ][self ._col ] = value
500+ return self
You can’t perform that action at this time.
0 commit comments