Skip to content

Instantly share code, notes, and snippets.

@atrifex
Last active February 12, 2019 04:50
Show Gist options
  • Save atrifex/47e62ea2f690d2df659affbee099847d to your computer and use it in GitHub Desktop.
Save atrifex/47e62ea2f690d2df659affbee099847d to your computer and use it in GitHub Desktop.
Guitar string picking practice
# Std
import argparse
import curses
import random
import time
# Parse arguments
parser = argparse.ArgumentParser(description="Program to help you pick random strings on command.")
parser.add_argument('-i','--interval', help='Description for foo argument', type=float, default=2.0)
args = parser.parse_args()
# Get screen information
screen = curses.initscr()
screen_height, screen_width = screen.getmaxyx()
# Set up window
begin_y = screen_height/2
begin_x = screen_width/2
# Warning message
warning_msg = "Get Ready"
screen.addstr(begin_y, begin_x - len(warning_msg)/2, "Get Ready")
for i in reversed(range(1, 4)):
screen.addstr(begin_y + 1, begin_x - 7/2, "***{}***".format(i))
screen.refresh()
time.sleep(1)
screen.erase()
# Initialize variables
strings = set(range(1, 7))
prev_string = None
count = 0
while True:
count += 1
# Choose a rand string
cur_string = random.sample(strings, 1)[0]
strings.discard(cur_string)
if prev_string is not None:
strings.add(prev_string)
prev_string = cur_string
# Print string and count
string_msg = "String: {}".format(cur_string)
screen.addstr(begin_y, begin_x - len(string_msg), string_msg)
screen.addstr(screen_height - 1, 1, "Count: {}".format(count))
screen.refresh()
# Sleep
time.sleep(args.interval)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment