-
-
Save greysondn/d271f78abae880fdd03b83603407f9b8 to your computer and use it in GitHub Desktop.
Useless plotter code sample from April Fool's Day TAS
This file contains 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
class Plotter: | |
# ... lots of stuff here ... | |
# selected, pen is a single pixel at (9, 9) | |
# stamp, etc. | |
def mask(self, path): | |
# open image using PILLOW | |
im = Image.open(path) | |
# make sure it's RGB | |
im = im.convert("RGB") | |
# define black as the value of its RGB triple for comparison later | |
black = (0, 0, 0) | |
# get width and height | |
width = im.size[0] | |
height = im.size[1] | |
# prep pen | |
if (self.down): | |
# need to lift and wait so we know input will be read | |
self.penUp() | |
self.wait(10) | |
# we need to track where we just were | |
lastX = self.x | |
lastY = self.y | |
# and now the boring parts. | |
for y in range(height): | |
for x in range(width): | |
# so... do we draw here? | |
drawHere = (black == im.getpixel((x, y))) | |
if (drawHere): | |
if (self.down): | |
# determine adjacency | |
# defined here as "able to be drawn without lifting pen | |
adjacent = False | |
xDist = int(abs(x - lastX)) | |
yDist = int(abs(y - lastY)) | |
# adjacency rules | |
if ((xDist == 1) and (yDist == 0)): | |
# horizontal | |
adjacent = True | |
elif ((xDist == 0) and (yDist == 1)): | |
# vertical | |
adjacent = True | |
elif ((xDist == 1) and (yDist == 1)): | |
# diagonal | |
adjacent = True | |
else: | |
# not adjacent, is it? | |
adjacent = False | |
# NB: adjacency is a bad model. Because you can move the | |
# mouse with pen down without drawing for fixed | |
# distances, a better model would take this quirk of | |
# Mario Paint into account. | |
# anyway, if it's adjacent, we just move to it | |
if (adjacent): | |
self.plotAbsolute(x, y) | |
else: | |
# if it's not, what a pain. | |
self.penUp() | |
self.wait(1) | |
self.plotAbsolute(x, y) | |
self.penDown() | |
self.wait(8) | |
else: | |
# not self.down | |
# we'll assume the wait has already happened here | |
self.plotAbsolute(x, y) | |
self.penDown() | |
self.wait(8) | |
# and now we just set the last drawn coordinates | |
lastX = x | |
lastY = y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Seriously, this is awful and slow. There's a better one.
https://github.com/greysondn/mario-paint-plotter