Skip to content

Instantly share code, notes, and snippets.

@yarikoptic
Last active February 12, 2019 16:23
Show Gist options
  • Save yarikoptic/c2f9e1ebac9a12b2c35a5f64c68e60ee to your computer and use it in GitHub Desktop.
Save yarikoptic/c2f9e1ebac9a12b2c35a5f64c68e60ee to your computer and use it in GitHub Desktop.
import image
import math
angle = 10 # we humans think degrees
angle = angle*math.pi/180 # radians
img = image.Image("golden_gate.png")
height = img.getHeight()
width = img.getWidth()
win = image.ImageWin(width, height)
img2 = image.EmptyImage(width, height)
for y in range(height):
for x in range(width):
r = (x**2 + y**2)**0.5
cur_angle = math.atan(y/x) if x else math.pi/2
orig_angle = cur_angle + angle
orig_x = round(r*math.cos(orig_angle))
orig_y = round(r*math.sin(orig_angle))
if (0 <= orig_x < width) and (0 <= orig_y < height):
orig_pixel = img.getPixel(orig_x, orig_y)
img2.setPixel(x, y, orig_pixel)
img2.draw(win)
win.exitonclick()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment