Browse Source

horizontal scrollers and color shifters

master
crunk 3 years ago
commit
3a52870cc2
  1. 0
      README.md
  2. 28
      pyproject.toml
  3. 12
      test
  4. 110
      tombofdoom.py

0
README.md

28
pyproject.toml

@ -0,0 +1,28 @@
# NOTE: you have to use single-quoted strings in TOML for regular expressions.
# It's the equivalent of r-strings in Python. Multiline strings are treated as
# verbose regular expressions by Black. Use [ ] to denote a significant space
# character.
[tool.black]
line-length = 79
target-version = ['py37', 'py38']
include = '\.pyi?$'
exclude = '''
/(
\.eggs
| \.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
# The following are specific to Black, you probably don't want those.
| blib2to3
| tests/data
| profiling
)/
'''

12
test

@ -0,0 +1,12 @@
███████████████████████████████████████████████████████████████████████████████
██╔════════════╗█╔════════════╗█╔════════════╗█╔════════════╗█╔════════════╗███
██║ ▄▄▄▄ ▄▄▄ ║█║ ▄▄▄▄▄▄▄▄▄▄ ║█║ ██████████ ║█║ ██████████ ║█║ ██████████ ║███
██║ ████ ████ ║█║ ██████████ ║█║ ██████████ ║█║ ▀▀▀▀▀▀▀▀▀▀ ║█║ ██████████ ║███
██║ ████ ████ ║█║ ███ ███ ║█║ ██ ███▀ ║█║ ▄▄▄▄▄▄▄▄▄▄ ║█║ ███ ███ ║███
██║ ████ ████ ║█║ ██████████ ║█║ ████████ ║█║ ██████ ║█║ ██████████ ║███
██║ ████ ████ ║█║ ████▌▐████ ║█║ █████████ ║█║ ██████ ║█║ ████▌▐████ ║███
██║ ▓███ ▄████ ║█║ ▓███▌▐████ ║█║ ▓███▌▐███ ║█║ ██████ ║█║ ▓███▌▐████ ║███
██║ ▒▓███████▀ ║█║ ▒▓██▌▐████ ║█║ ▒▓██▌▐███ ║█║ ▓█████ ║█║ ▒▓██▌▐████ ║███
██║ ░▒▓█████▀ ║█║ ░▒▓█▌▐████ ║█║ ░▒▓█▌▐████ ║█║ ░▒▓█████▄▄ ║█║ ░▒▓█▌▐████ ║███
██╚════════════╝█╚════════════╝█╚════════════╝█╚════════════╝█╚════════════╝███
███████████████████████████████████████████████████████████████████████████████

110
tombofdoom.py

@ -0,0 +1,110 @@
import curses
import time
# Using readlines()
file1 = open("test", "r")
lines = file1.readlines()
debug_text = False
def show_debug_text(stdscr, width, height, start_x_file):
"""debug text for the tomb of doom"""
whstr = "Width: {}, Height: {}".format(width, height)
stdscr.addstr(0, 0, whstr, curses.color_pair(1))
file_string = "X position of text: {}".format(start_x_file)
stdscr.addstr(1, 0, file_string, curses.color_pair(1))
def draw_scroll(stdscr):
# Clear and refresh the screen for a blank screen
# Set delay to no, to not wait for keyboard press
stdscr.nodelay(1)
stdscr.clear()
stdscr.refresh()
start_x_file = 80
rotation = 1
# 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_BLACK)
curses.init_pair(3, curses.COLOR_GREEN, curses.COLOR_BLACK)
curses.init_pair(4, curses.COLOR_BLUE, curses.COLOR_BLACK)
curses.init_pair(5, curses.COLOR_MAGENTA, curses.COLOR_BLACK)
curses.init_pair(6, curses.COLOR_YELLOW, curses.COLOR_BLACK)
while True:
# Loop where k is the last character pressed
stdscr.clear()
height, width = stdscr.getmaxyx()
# Declaration of strings
title = "Curses horizontal scroller test"[: width - 1]
subtitle = "Crunk Varia"[: width - 1]
hwidth = width // 2
# Centering calculations
start_x_title = int((hwidth) - (len(title) // 2) - len(title) % 2)
start_x_subtitle = int(
(hwidth) - (len(subtitle) // 2) - len(subtitle) % 2
)
start_y = int((height) - 2)
if debug_text:
show_debug_text(stdscr, width, height, start_x_file)
line_count = 0
for line in lines:
ch_count = 0
for character in line:
if (
ch_count + start_x_file < width
and ch_count + start_x_file > 0
):
stdscr.addch(
3 + line_count,
start_x_file + ch_count,
character,
curses.color_pair(rotation),
)
ch_count += 1
line_count += 1
# Turning on attributes for title
stdscr.attron(curses.color_pair(2))
stdscr.attron(curses.A_BOLD)
# Rendering title
stdscr.addstr(start_y, start_x_title, title)
# Turning off attributes for title
stdscr.attroff(curses.color_pair(2))
stdscr.attroff(curses.A_BOLD)
stdscr.addstr(start_y + 1, start_x_subtitle, subtitle)
# Refresh the screen
stdscr.refresh()
time.sleep(1.0 / 30)
start_x_file -= 1
if start_x_file < -80:
start_x_file = 80
rotation += 1
if rotation > 6:
rotation = 1
key_pressed = stdscr.getch() != -1
if key_pressed:
raise KeyboardInterrupt()
def main():
curses.wrapper(draw_scroll)
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
curses.endwin()
curses.curs_set(1)
curses.reset_shell_mode()
curses.echo()
Loading…
Cancel
Save