Skip to content

Codespace venchand urban space winner 6pw55gwg4whx5x9 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 34 additions & 17 deletions exercise_files/02_07_challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
import time
from termcolor import colored

# This is the Canvas class. It defines some height and width, and a
# This is the Canvas class. It defines some height and width, and a
# matrix of characters to keep track of where the TerminalScribes are moving


class Canvas:
def __init__(self, width, height):
self._x = width
self._y = height
# This is a grid that contains data about where the
# This is a grid that contains data about where the
# TerminalScribes have visited
self._canvas = [[' ' for y in range(self._y)] for x in range(self._x)]

Expand All @@ -30,6 +32,7 @@ def print(self):
for y in range(self._y):
print(' '.join([col[y] for col in self._canvas]))


class TerminalScribe:
def __init__(self, canvas):
self.canvas = canvas
Expand Down Expand Up @@ -70,24 +73,38 @@ def draw(self, pos):
# Sleep for a little bit to create the animation
time.sleep(self.framerate)

# Create a new Canvas instance that is 30 units wide by 30 units tall
def draw_right(self, size):
while size > 0:
size -= 1
scribe.right()

def draw_left(self, size):
while size > 0:
size -= 1
scribe.left()

def draw_down(self, size):
while size > 0:
size -= 1
scribe.down()

def draw_up(self, size):
while size > 0:
size -= 1
scribe.up()

def draw_square(self, size):
self.draw_right(size)
self.draw_down(size)
self.draw_left(size)
self.draw_up(size)


# Create a new Canvas instance that is 30 units wide by 30 units tall
canvas = Canvas(30, 30)

# Create a new scribe and give it the Canvas object
scribe = TerminalScribe(canvas)

# Draw a small square
scribe.right()
scribe.right()
scribe.right()
scribe.down()
scribe.down()
scribe.down()
scribe.left()
scribe.left()
scribe.left()
scribe.up()
scribe.up()
scribe.up()


scribe.draw_square(20)