Created
April 27, 2019 16:47
-
-
Save raymondberg/6f4b2b4cac6b8b3bbe02cee939a1236a to your computer and use it in GitHub Desktop.
Remote Lab Results
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import curses | |
import os | |
import sys | |
## Contributors: Richa, Pedro, Ramon, Doug, Ray | |
def draw_house(screen, color, offset_x=0, offset_y=0): | |
# Your job is to draw a house! Feel free to get creative! | |
draw_horizontal_line(screen, color, 0 + offset_x, 20 + offset_x, 8 + offset_y) | |
draw_horizontal_line(screen, color, 0 + offset_x, 20 + offset_x, 18 + offset_y) | |
draw_vertical_line(screen, color, 0 + offset_x, 8 + offset_y, 18 + offset_y) | |
draw_vertical_line(screen, color, 20 + offset_x, 8 + offset_y, 18 + offset_y) | |
slash_line(screen, color, 10 + offset_x, 20 + offset_x, 0 + offset_y, 8 + offset_y) | |
slash_line(screen, color, 0 + offset_x, 10 + offset_x, 8 + offset_y, 0 + offset_y) | |
def draw_horizontal_line(screen, color, from_x, to_x, y): | |
for x in range(from_x, to_x+1): | |
screen.addstr(y, x, '-', color) | |
def draw_vertical_line(screen, color, x, from_y, to_y): | |
for y in range(from_y, to_y+1): | |
screen.addstr(y, x, '|', color) | |
def slash_line(screen, color, from_x, to_x, from_y, to_y): | |
y=from_y | |
x=from_x | |
#for x in range(from_x to_x+1): | |
if from_y < to_y: | |
## For a line going down and to the right | |
while x <= to_x and y <= to_y: | |
screen.addstr(y - 1, x + 1, '\\', color) | |
y = y + 1 | |
x = x + 1 | |
elif from_y > to_y: | |
## For a line going up and to the right | |
while x <= to_x and y >= to_y: | |
screen.addstr(y - 1, x + 1, '/', color) | |
y = y - 1 | |
x = x + 1 | |
# screen.addstr(-1+ offset_y, 2 + offset_x, '\\', color) | |
# screen.addstr(-2+ offset_y, 1 + offset_x, 'A', color) | |
def draw_square(screen, color, offset_x=0, offset_y=0): | |
screen.addstr(1 + offset_y, 0 + offset_x, 'X', color) | |
screen.addstr(1 + offset_y, 5 + offset_x, 'X', color) | |
screen.addstr(2 + offset_y, 0 + offset_x, 'X', color) | |
screen.addstr(2 + offset_y, 5 + offset_x, 'X', color) | |
screen.addstr(3 + offset_y, 0 + offset_x, 'X', color) | |
screen.addstr(3 + offset_y, 5 + offset_x, 'X', color) | |
screen.addstr(4 + offset_y, 0 + offset_x, 'X', color) #bottom left corner | |
screen.addstr(4 + offset_y, 1 + offset_x, 'X', color) | |
screen.addstr(4 + offset_y, 2 + offset_x, 'X', color) #bottom right corner | |
""" x | |
x x | |
xxx ## current top | |
x x | |
xxx | |
[screen.addstr(-2 +offset_y, i +offset_x, "x", color) for i in range(5)] | |
""" | |
def draw(screen): | |
""" """ | |
k = 0 | |
# Clear and refresh the screen for a blank canvas | |
screen.clear() | |
screen.refresh() | |
# Start colors in curses | |
curses.start_color() | |
curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK) | |
curses.init_pair(2, curses.COLOR_RED, curses.COLOR_WHITE) | |
# Loop where k is the last character pressed | |
while (k != ord('q')): | |
# draw_square(screen, curses.color_pair(1)) | |
# draw_square(screen, curses.color_pair(2), offset_x=10) | |
# draw_square(screen, curses.color_pair(2), offset_y=5) | |
#draw_square(screen, curses.color_pair(1), offset_x=10, offset_y=5) | |
for i in range(5): | |
for j in range(5): | |
draw_house(screen, curses.color_pair(1), offset_x=10+22*i, offset_y=10+10*j) | |
# Refresh the screen | |
screen.refresh() | |
# Wait for next input | |
k = screen.getch() | |
if __name__ == "__main__": | |
curses.wrapper(draw) | |
''' | |
Next steps: Did you know curses lets you figure out what keys are pressed? Got anything you can move around? | |
if k == curses.KEY_DOWN: | |
elif k == curses.KEY_UP: | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment