Skip to content

Instantly share code, notes, and snippets.

@gferreira
Created June 23, 2015 13:28
Show Gist options
  • Save gferreira/77fc99aafcb708000ee0 to your computer and use it in GitHub Desktop.
Save gferreira/77fc99aafcb708000ee0 to your computer and use it in GitHub Desktop.
An Image object which supports horizontal/vertical flipping
# flip image
class Image(object):
flip_x = False
flip_y = False
alpha = 1.0
def __init__(self, image_path):
self.path = image_path
def draw(self, (x, y)):
w, h = imageSize(self.path)
if self.flip_x:
scale_x = -1
pos_x = - (x + w)
else:
scale_x = 1
pos_x = x
if self.flip_y:
scale_y = -1
pos_y = - (y + h)
else:
scale_y = 1
pos_y = y
save()
scale(scale_x, scale_y)
image(self.path, (pos_x, pos_y), self.alpha)
restore()
img_path = 'http://cdn.okcimg.com/php/load_okc_image.php/images/0x0/0x0/0/443667211249554632.jpeg___1_500_1_500_cb94de6a_.png'
x, y = 250, 332
I = Image(img_path)
I.flip_x = True
I.flip_y = False
I.alpha = 0.85
I.draw((x, y))
stroke(1, 0, 0)
line((x, 0), (x, height()))
line((0, y), (width(), y))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment