<commit_before># Import the motor module and prepare to draw
import pygame
import numpy
import motor
import math

# For headless pygame
import os, sys
from time import sleep

# Headless pygame hack see:
# http://www.pygame.org/wiki/HeadlessNoWindowsNeeded
os.environ["SDL_VIDEODRIVER"] = "dummy"

# Return a black/white array for a file
#  with the black/white values
def load_image(image_string):
    png = pygame.image.load(image_string)
    png = pygame.transform.rotate(png, 90)
    arr = pygame.surfarray.array2d(png)
    whiteval = numpy.amin(arr)
    blackval = numpy.amax(arr) 
    return (arr, whiteval, blackval)

# Wait until the mouse returns a relative difference with sign
def get_mouse_sign():
    (x,y) = pygame.mouse.get_rel()
    sign_x = 0
    math.copysign(sign_x, x)
    print sign_x
    return sign_x

def wait_for_mouse(sign):
    while get_mouse_sign() != sign:
        sleep(0.01)
    return True

def draw(image, pen_down_val, pen_up_val, half_period, total_belay_time):
    #alternate = False
    #(row, col) = image.shape()
    # Adjust belay time based on how many lines we have
    belay_time = total_belay_time / 1
    for line in image:
        wait_for_mouse(1)
        #if alternate:
        #    line.reverse()
        motor.draw_line(1, line, pen_down_val, pen_up_val, half_period)
        motor.step_lock(2, belay_time, motor.M_FOR)
        # Do some ASCII art so we can see how far we are
        motor.fake_draw_line(1, line, pen_down_val, pen_up_val, half_period)
    return True

def rewind():
    # Lift up the pen and return the walker to start
    motor.set_motor_state(1, motor.M_FOR)
    # Rewind the motor until an interrupt on the switch
    motor.set_motor_state(2, motor.M_REV)
    print "Rewinding. Press button to stop."
    motor.wait_for_button('rising')
    motor.set_motor_state(2, motor.M_OFF)
    return True

if __name__ == "__main__":
    # Init pygame for mouse input
    pygame.init()
    pygame.display.set_mode((1, 1))
    # Allow arbitrary mouse bounds
    pygame.mouse.set_visible(False)

    # Initalize motor program<commit_msg>Threshold + fix mid-line start<commit_after># Import the motor module and prepare to draw
import pygame
import numpy
import motor
import math

# For headless pygame
import os, sys
from time import sleep

# Headless pygame hack see:
# http://www.pygame.org/wiki/HeadlessNoWindowsNeeded
os.environ["SDL_VIDEODRIVER"] = "dummy"

# Return a black/white array for a file
#  with the black/white values
def load_image(image_string):
    png = pygame.image.load(image_string)
    png = pygame.transform.rotate(png, 90)
    arr = pygame.surfarray.array2d(png)
    whiteval = numpy.amin(arr)
    blackval = numpy.amax(arr) 
    return (arr, whiteval, blackval)

# Wait until the mouse returns a relative difference with sign
def get_mouse_sign():
    (x,y) = pygame.mouse.get_rel()
    sign_x = 0
    math.copysign(sign_x, x)
    print sign_x
    return sign_x

def wait_for_mouse(sign):
    while get_mouse_sign() != sign:
        sleep(0.01)
    return True

def draw(image, pen_down_val, pen_up_val, half_period, total_belay_time):
    #alternate = False
    #(row, col) = image.shape()
    # Adjust belay time based on how many lines we have
    belay_time = total_belay_time / 1
    for line in image:
        wait_for_mouse(-5)
        wait_for_mouse(5)
        #if alternate:
        #    line.reverse()
        motor.draw_line(1, line, pen_down_val, pen_up_val, half_period)
        motor.step_lock(2, belay_time, motor.M_FOR)
        # Do some ASCII art so we can see how far we are
        motor.fake_draw_line(1, line, pen_down_val, pen_up_val, half_period)
    return True

def rewind():
    # Lift up the pen and return the walker to start
    motor.set_motor_state(1, motor.M_FOR)
    # Rewind the motor until an interrupt on the switch
    motor.set_motor_state(2, motor.M_REV)
    print "Rewinding. Press button to stop."
    motor.wait_for_button('rising')
    motor.set_motor_state(2, motor.M_OFF)
    return True

if __name__ == "__main__":
    # Init pygame for mouse input
    pygame.init()
    pygame.display.set_mode((1, 1))
    # Allow arbitrary mouse bounds
    pygame.mouse.set_visible(False)

    # Initalize motor program
{'fraction_non_alphanumeric': 0.08994334277620397, 'fraction_numerical': 0.008262511803588292, 'mean_word_length': 3.297160243407708, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4568908', 'n_tokens_mistral': 1473, 'n_tokens_neox': 1436, 'n_words': 415}