Last active
February 12, 2019 16:23
-
-
Save yarikoptic/c2f9e1ebac9a12b2c35a5f64c68e60ee to your computer and use it in GitHub Desktop.
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
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