[
  {
    "path": ".gitignore",
    "content": "/src/__init__.py\n*.pyc\n"
  },
  {
    "path": "LICENSE",
    "content": "Creative Commons Legal Code\n\nCC0 1.0 Universal\n\n\tCREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE\n\tLEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN\n\tATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS\n\tINFORMATION ON AN \"AS-IS\" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES\n\tREGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS\n\tPROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM\n\tTHE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED\n\tHEREUNDER.\n\nStatement of Purpose\n\nThe laws of most jurisdictions throughout the world automatically confer\nexclusive Copyright and Related Rights (defined below) upon the creator\nand subsequent owner(s) (each and all, an \"owner\") of an original work of\nauthorship and/or a database (each, a \"Work\").\n\nCertain owners wish to permanently relinquish those rights to a Work for\nthe purpose of contributing to a commons of creative, cultural and\nscientific works (\"Commons\") that the public can reliably and without fear\nof later claims of infringement build upon, modify, incorporate in other\nworks, reuse and redistribute as freely as possible in any form whatsoever\nand for any purposes, including without limitation commercial purposes.\nThese owners may contribute to the Commons to promote the ideal of a free\nculture and the further production of creative, cultural and scientific\nworks, or to gain reputation or greater distribution for their Work in\npart through the use and efforts of others.\n\nFor these and/or other purposes and motivations, and without any\nexpectation of additional consideration or compensation, the person\nassociating CC0 with a Work (the \"Affirmer\"), to the extent that he or she\nis an owner of Copyright and Related Rights in the Work, voluntarily\nelects to apply CC0 to the Work and publicly distribute the Work under its\nterms, with knowledge of his or her Copyright and Related Rights in the\nWork and the meaning and intended legal effect of CC0 on those rights.\n\n1. Copyright and Related Rights. A Work made available under CC0 may be\nprotected by copyright and related or neighboring rights (\"Copyright and\nRelated Rights\"). Copyright and Related Rights include, but are not\nlimited to, the following:\n\n  i. the right to reproduce, adapt, distribute, perform, display,\n\t communicate, and translate a Work;\n ii. moral rights retained by the original author(s) and/or performer(s);\niii. publicity and privacy rights pertaining to a person's image or\n\t likeness depicted in a Work;\n iv. rights protecting against unfair competition in regards to a Work,\n\t subject to the limitations in paragraph 4(a), below;\n  v. rights protecting the extraction, dissemination, use and reuse of data\n\t in a Work;\n vi. database rights (such as those arising under Directive 96/9/EC of the\n\t European Parliament and of the Council of 11 March 1996 on the legal\n\t protection of databases, and under any national implementation\n\t thereof, including any amended or successor version of such\n\t directive); and\nvii. other similar, equivalent or corresponding rights throughout the\n\t world based on applicable law or treaty, and any national\n\t implementations thereof.\n\n2. Waiver. To the greatest extent permitted by, but not in contravention\nof, applicable law, Affirmer hereby overtly, fully, permanently,\nirrevocably and unconditionally waives, abandons, and surrenders all of\nAffirmer's Copyright and Related Rights and associated claims and causes\nof action, whether now known or unknown (including existing as well as\nfuture claims and causes of action), in the Work (i) in all territories\nworldwide, (ii) for the maximum duration provided by applicable law or\ntreaty (including future time extensions), (iii) in any current or future\nmedium and for any number of copies, and (iv) for any purpose whatsoever,\nincluding without limitation commercial, advertising or promotional\npurposes (the \"Waiver\"). Affirmer makes the Waiver for the benefit of each\nmember of the public at large and to the detriment of Affirmer's heirs and\nsuccessors, fully intending that such Waiver shall not be subject to\nrevocation, rescission, cancellation, termination, or any other legal or\nequitable action to disrupt the quiet enjoyment of the Work by the public\nas contemplated by Affirmer's express Statement of Purpose.\n\n3. Public License Fallback. Should any part of the Waiver for any reason\nbe judged legally invalid or ineffective under applicable law, then the\nWaiver shall be preserved to the maximum extent permitted taking into\naccount Affirmer's express Statement of Purpose. In addition, to the\nextent the Waiver is so judged Affirmer hereby grants to each affected\nperson a royalty-free, non transferable, non sublicensable, non exclusive,\nirrevocable and unconditional license to exercise Affirmer's Copyright and\nRelated Rights in the Work (i) in all territories worldwide, (ii) for the\nmaximum duration provided by applicable law or treaty (including future\ntime extensions), (iii) in any current or future medium and for any number\nof copies, and (iv) for any purpose whatsoever, including without\nlimitation commercial, advertising or promotional purposes (the\n\"License\"). The License shall be deemed effective as of the date CC0 was\napplied by Affirmer to the Work. Should any part of the License for any\nreason be judged legally invalid or ineffective under applicable law, such\npartial invalidity or ineffectiveness shall not invalidate the remainder\nof the License, and in such case Affirmer hereby affirms that he or she\nwill not (i) exercise any of his or her remaining Copyright and Related\nRights in the Work or (ii) assert any associated claims and causes of\naction with respect to the Work, in either case contrary to Affirmer's\nexpress Statement of Purpose.\n\n4. Limitations and Disclaimers.\n\n a. No trademark or patent rights held by Affirmer are waived, abandoned,\n\tsurrendered, licensed or otherwise affected by this document.\n b. Affirmer offers the Work as-is and makes no representations or\n\twarranties of any kind concerning the Work, express, implied,\n\tstatutory or otherwise, including without limitation warranties of\n\ttitle, merchantability, fitness for a particular purpose, non\n\tinfringement, or the absence of latent or other defects, accuracy, or\n\tthe present or absence of errors, whether or not discoverable, all to\n\tthe greatest extent permissible under applicable law.\n c. Affirmer disclaims responsibility for clearing rights of other persons\n\tthat may apply to the Work or any use thereof, including without\n\tlimitation any person's Copyright and Related Rights in the Work.\n\tFurther, Affirmer disclaims responsibility for obtaining any necessary\n\tconsents, permissions or other rights required for any use of the\n\tWork.\n d. Affirmer understands and acknowledges that Creative Commons is not a\n\tparty to this document and has no duty or obligation with respect to\n\tthis CC0 or use of the Work.\n"
  },
  {
    "path": "README.md",
    "content": "Mouseomate V0.8, Now with Color!\n\nOriginal Code by Nekose\n\nColor Implementation and GUI by Quadrum1\n\nformating contributions by Logistic-bot\n\n\nTo use, run main.py. The image you would like to draw must be inside the 'images' folder. \n\nTo switch between color or BW, change the mode variable near the top of main. If using color, specify the program you would like to draw with to specify color controls. (currently only supports MS Paint)\n\nIf running in black and white, images should ideally be vector-like, with limited shading or colorpallet (Although the program will attempt to monochrome any image given).\n\n***\nExample Of Use:\n\n* After running, a prompt will ask which file to open. Once open a dialog box will appear asking for the following:\n\nWhat is the approximate pixel size you would like to output?> 500\nWhat is the approximate brush size in pixels? (Use 1 for one to one drawing)>? 1\n\n* Once the parameters have been provided, the following message will be displayed:\n\nPreview image loaded. Enter to begin 3 second countdown to start, N to abort. Once image has started, pulling mouse to the upper left corner will abort the program.\n\n* Hitting enter will start a 3 second countdown, afterwhich the program will take control of the mouse, using the current position as the upper left corner of the image.\n\n***\n\nKnown issues:\n* Output speed appears to be limited by the windows input buffer. You may need to wait till the program finishes running before the image apppears. If you have CPU speed issues, you can try increasing \"lsleep\" and \"rsleep\" values at the top of main.py.\n\nTo Do:\n* investigate better drawing algorithms (Line tracing with cv2.HoughLinesP()?)\n"
  },
  {
    "path": "images/__init__.py",
    "content": ""
  },
  {
    "path": "main.py",
    "content": "import time\nimport sys\nimport os\nfrom easygui import multenterbox\n\ncwd = os.getcwd()\nsys.path.append(cwd+'/src')\n\nfrom image_handler import Image_handler\nfrom mouse_automate_black import Mouseomate as Mouseomate_black\nfrom mouse_automate_color import Mouseomate as Mouseomate_color\n\nmode = \"black\" # \"color\", \"black\"\napp = \"paint\" # What application are you drawing with?\n\nos.chdir(\"images\")\n\n\nlsleep = 0.002 #adujust this to change pause time at end of line (recommend .002)\nrsleep = 0.025 #adujust this to change pause time at end of row (recommend .025)\nimagename = Image_handler.get_image()\nhandler = Image_handler(imagename)\nmessage = \"Resizevalue: What is the approximate pixel size you would like to output?\\nOffset: What is the approximate brush size in pixels? (1 for one to one drawing)\"\nresizevalue, offset = multenterbox(message,\"Mouseomate\", [\"Resizevalue\",\"Offset\"])\nresizevalue = int(resizevalue) if resizevalue else 100\noffset = int(offset) if offset else 1\nresizevalue = resizevalue / offset\nhandler.convert_bandw(mode)\nhandler.resize(resizevalue)\n\t\nhandler.im.show()\nreturnkey = None\nwhile returnkey == None:\n\tprint(\"Preview image loaded. Enter to begin 3 second countdown to start, N to abort. Once image has started, pulling mouse to any corner will abort the program.\")\n\treturnkey = input()\n\treturnkey = returnkey.lower()\n\tif returnkey == 'n':\n\t\texit()\n\tif returnkey == 'i':\n\t\thandler.invert(imagename)\n\t\thandler.convert_bandw(mode)\n\t\tresizevalue = resizevalue / offset\n\t\thandler.resize(resizevalue)\n\t\thandler.im.show()\n\t\treturnkey = None\n\ntime.sleep(3)\narray = handler.update_array()\nif mode == \"color\":\n\tMouseomate_color.image_to_lines(array, offset, rsleep, lsleep, app)\nelif mode == \"black\":\n\tMouseomate_black.image_to_lines(array, offset, rsleep, lsleep)\n\t\t\nrepeat = 'y'\nwhile repeat == 'y':\n\trepeat = input(\"Y to redraw after 3 sec pause, or enter to exit\")\n\trepeat = repeat.lower()\n\tif repeat == 'y':\n\t\ttime.sleep(3)\n\t\tif mode == \"color\":\n\t\t\tMouseomate_color.image_to_lines(array, offset, rsleep, lsleep, app)\n\t\telif mode == \"black\":\n\t\t\tMouseomate_black.image_to_lines(array, offset, rsleep, lsleep)\n\telse:\n\t\texit()\n\n"
  },
  {
    "path": "requirements.txt",
    "content": "MouseInfo==0.1.3\nnumpy==1.22.0\npandas==1.0.3\nPillow==9.0.1\nPyAutoGUI==0.9.50\nPyGetWindow==0.0.8\nPyMsgBox==1.0.7\npyperclip==1.8.0\nPyRect==0.1.4\nPyScreeze==0.1.26\npython-dateutil==2.8.1\nPyTweening==1.0.3\npytz==2020.1\nsix==1.14.0\neasygui==0.98.1\n"
  },
  {
    "path": "src/image_handler.py",
    "content": "from PIL import Image, ImageFilter, ImageOps\nimport numpy as np\nfrom easygui import fileopenbox\n\nclass Image_handler(object):\n\tdef __init__(self,image):\n\t\tself.im = Image.open(image)\n\n\t@staticmethod\n\tdef get_image() -> str:\n\t\t\"\"\"\n\t\tAsk's users the name of the file to be used\n\t\t:return:\n\t\ta string of the file name\n\t\t\"\"\"\n\t\tpath = fileopenbox()\n\t\treturn path\n\n\tdef convert_bandw(self,mode) -> None:\n\t\t\"\"\"\n\t\tconverts image to a black and white bit per pixel image\n\t\t:return:\n\t\t\"\"\"\n\t\tif mode == \"color\":\n\t\t\tself.im = self.im.convert(mode='RGB',dither=None)\n\t\telif mode == \"black\":\n\t\t\tself.im = self.im.convert(mode='1',dither=None)\n\n\tdef invert(self,image) -> None:\n\t\t\"\"\"\n\t\tReturns a color inverted image file\n\t\t:return:\n\t\t\"\"\"\n\t\tself.im = ImageOps.invert(Image.open(image))\n\n\tdef resize(self,value:int) -> None:\n\t\t\"\"\"\n\t\tresizes image to fit withing an X by X square\n\t\t:param value:\n\t\tSize of the square input field\n\t\t:return:\n\t\t\"\"\"\n\t\thorizontalsize, verticalsize = self.im.size\n\t\tif horizontalsize > verticalsize:\n\t\t\tconversion = horizontalsize / value\n\t\t\tself.im = self.im.resize((int(horizontalsize / conversion), int(verticalsize / conversion)))\n\t\telse:\n\t\t\tconversion = verticalsize / value\n\t\t\tself.im = self.im.resize((int(horizontalsize / conversion), int(verticalsize / conversion)))\n\n\tdef update_array(self) -> np.array:\n\t\t\"\"\"\n\t\tConverts image into a numpy array of bools\n\t\t:return:\n\t\t\"\"\"\n\t\tarray = np.array(self.im)\n\t\treturn array\n\n\n\n\n"
  },
  {
    "path": "src/mouse_automate_black.py",
    "content": "import numpy\nimport pyautogui\nimport time\t  \nclass Mouseomate(object):\n\tpyautogui.PAUSE = 0.00 #useful\n\tpyautogui.FAILSAFE = True\n\n\t@staticmethod\n\tdef image_to_lines(image_array: numpy.array, offset:int, rsleep:int, lsleep:int) -> None:\n\t\t\"\"\"\n\t\tConverts an image array to mouseclicks.\n\t\t:param image_array:\n\t\tA numpy array of bools, where False represents a click, and True represents no click.\n\t\t:param offset:\n\t\tAn int which provides spacing between each pixel in image_array. Usefull to adjust for brush size used in whatever this will be outputting for.\n\t\t:param rlseep:\n\t\tint which designates how long in second the mouse will take drawing a line\n\t\t:param rsleep:\n\t\tint which designates how long in seconds to pause at end of row\n\t\t:return:\n\t\t\"\"\"\n\t\tstartpositionx,startpositiony = pyautogui.position()\n\t\tfor row in image_array:\n\t\t\txoffset = 0\n\t\t\talreadydrawing = False\n\t\t\tfor value in row:\n\t\t\t\tif not value.all(): #Need to draw\n\t\t\t\t\tif alreadydrawing == True:\n\t\t\t\t\t\txoffset += offset\n\t\t\t\t\telse:\n\t\t\t\t\t\tstartline = startpositionx + xoffset\n\t\t\t\t\t\talreadydrawing = True\n\t\t\t\t\t\txoffset += offset\n\t\t\t\tif value.all(): #End of line aka. white begins\n\t\t\t\t\tif alreadydrawing == False:\n\t\t\t\t\t\txoffset += offset\n\t\t\t\t\telse:\n\t\t\t\t\t\tpyautogui.moveTo(startline,startpositiony)\n\t\t\t\t\t\tpyautogui.dragTo(startpositionx + xoffset, startpositiony,duration=lsleep, button = 'left')\n\t\t\t\t\t\ttime.sleep(lsleep)\n\t\t\t\t\t\talreadydrawing = False\n\t\t\t\t\t\txoffset += offset\n\t\t\tif not value.all():\n\t\t\t\tif alreadydrawing == True:\n\t\t\t\t\tpyautogui.moveTo(startline, startpositiony)\n\t\t\t\t\tpyautogui.dragTo(startpositionx + xoffset, startpositiony, duration=lsleep, button ='left')\n\t\t\t\t\ttime.sleep(lsleep)\n\t\t\t\t\txoffset += offset\n\t\t\tstartpositiony += offset\n\t\t\ttime.sleep(rsleep)\n\t\t\t"
  },
  {
    "path": "src/mouse_automate_color.py",
    "content": "import numpy\nimport pyautogui\nimport time\n\ndef closest_color(color, palette):\n\n\tr1, g1, b1 = color\n\tif r1 == 255 and g1 == 105 and b1 == 180:#Failsafe for last color drawn\n\t\tcc = r1, g1, b1\n\t\treturn cc # (255, 105, 180)\n\tclosest_dis = 10000\n\tcc = 0, 0, 0\n\tfor r2, g2, b2 in palette:\n\t\tdis = ((r1 - r2) ** 2 + (g1 - g2) ** 2 + (b1 - b2) ** 2) ** 0.5\n\t\tif dis < closest_dis:\n\t\t\tclosest_dis = dis\n\t\t\tcc = r2, g2, b2\n\treturn cc\n\t\n\ndef change_color(color,app):\n\tif color == (255, 105, 180): #Failsafe, needs to be reworked, this should only be temporary\n\t\ti = 0\n\telse:\n\t\ti = palette[app][0].index(color)\n\t\t\n\tif app == \"paint\": \n\t\t\"\"\"\n\t\tThis system to change colors is suboptimal, as different screens have the buttons at different locations! \n\t\tUsing json data storage to store these would be better as different subroutines could access them, for example a color mapper.\n\t\t\"\"\"\n\t\tif i <= 9:\n\t\t\tx = i*22 + 878\t  # Top row\n\t\t\ty = 58\n\t\telse:\n\t\t\tx = (i-10)*22 + 878\t  # Bottom row\n\t\t\ty = 82\n\telse:\n\t\traise ValueError(\"No color data found for application {}!\".format(app))\n\tpyautogui.mouseUp()\n\tpyautogui.click(x=x, y=y)\n\n# All color buttons for paint from left to right, top to bottom.\npaints = ((0, 0, 0),(127,127,127),(136,0,21),(237,28,36),(255,127,39),(255,242,0),(34,177,76),(0,162,232),(63,72,204),(163,73,164),\n\t\t  (255, 255, 255),(195,195,195),(185,122,87),(255,174,201),(255,201,14),(239,228,176),(181,230,29),(153,217,234),(112,146,190),(200,191,231))\t\n\t\t\npalette = {\"paint\": [paints,paints[10]]}\t# Key is the application name which is specified in main.py\n\t\t  \nclass Mouseomate(object):\n\tpyautogui.PAUSE = 0.00 #useful\n\tpyautogui.FAILSAFE = True\n\n\t@staticmethod\n\tdef image_to_lines(image_array: numpy.array, offset:int, rsleep:int, lsleep:int, app:str) -> None:\n\t\t\"\"\"\n\t\tConverts an image array to mouseclicks.\n\t\t:param image_array:\n\t\tA numpy array of bools, where False represents a click, and True represents no click.\n\t\t:param offset:\n\t\tAn int which provides spacing between each pixel in image_array. Usefull to adjust for brush size used in whatever this will be outputting for.\n\t\t:param rlseep:\n\t\tint which designates how long in second the mouse will take drawing a line\n\t\t:param rsleep:\n\t\tint which designates how long in seconds to pause at end of row\n\t\t:return:\n\t\t\"\"\"\n\t\tstartpositionx,startpositiony = pyautogui.position()\n\t\tfor row in image_array:\n\t\t\txoffset = 0\n\t\t\twhite = palette[app][1]\n\t\t\talreadydrawing = [white,0,0] # Color, starting xoffset, offsets in that line\n\t\t\trow[-1] = [255,105,180] #Failsafe for last color drawn\n\t\t\t# Without it, the last color in a row would not be drawn as the script would skip it, needs fixing!\n\t\t\tfor value in row:\t\n\t\t\t\tclosest = closest_color(value,palette[app][0])\n\t\t\t\tif closest == white:\n\t\t\t\t\talreadydrawing[0] = closest\n\t\t\t\t\txoffset += offset\n\t\t\t\t\tcontinue\n\t\t\t\t\t\n\t\t\t\tif alreadydrawing[0] == closest: # Is the current color the same color as the last one checked?\n\t\t\t\t\talreadydrawing[2] += offset \n\t\t\t\t\txoffset += offset\n\t\t\t\t\tcontinue\n\t\t\t\n\t\t\t\talreadydrawing[0] = closest # Define new color\n\n\t\t\t\t# Draw line with old color \n\t\t\t\tpyautogui.mouseUp()\n\t\t\t\tpyautogui.moveTo(startpositionx + alreadydrawing[1], startpositiony) #Draw the full line of the last color\n\t\t\t\tpyautogui.mouseDown()\n\t\t\t\tpyautogui.dragTo(startpositionx + alreadydrawing[1] + alreadydrawing[2], startpositiony, duration=lsleep, button = 'left')\n\t\t\t\tpyautogui.mouseUp()\n\t\t\t\t\n\t\t\t\t# Define new values for next line\n\t\t\t\talreadydrawing[1] = xoffset\n\t\t\t\talreadydrawing[2] = 0\n\t\t\t\t\n\t\t\t\t# Change the color to the new color\n\t\t\t\tchange_color(closest,app)\n\t\t\t\t\t\n\t\t\t\ttime.sleep(lsleep)\n\t\t\t\txoffset += offset\n\n\t\t\tpyautogui.mouseUp()\n\t\t\tchange_color(white,app)\n\t\t\tstartpositiony += offset\n\t\t\tpyautogui.mouseUp()\n\t\t\tpyautogui.moveTo(startpositionx, startpositiony)\n\t\t\ttime.sleep(rsleep)\n\t\t\t# Might have overdone is with mouseUp(), but paint had some problems with recognizing the mouse and handeled it as if it were still drawing, creating some... interesting replications\n\n\n\n\n"
  }
]