Last active
August 6, 2016 14:04
-
-
Save adusak/d7b5a5a8120a82aaf767 to your computer and use it in GitHub Desktop.
Effects
This file contains hidden or 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
| from math import cos, sin, tan | |
| import math | |
| from PIL import Image | |
| def waves(size=500, a=200): | |
| img = Image.new('RGB', (size, size)) | |
| start = - round(size / 2) | |
| end = - start | |
| move = round(size / 2) | |
| for x in range(start, end): | |
| for y in range(start, end): | |
| coef = abs(sin(((x / 5.) ** 2 + (y / 5.) ** 2) ** 0.5)) | |
| if abs(x) <= a / 2 and abs(y) < a / 2: | |
| coef = 1 - coef | |
| img.putpixel((x + move, y + move), tuple([int(255 * coef)] * 3)) | |
| img.save("waves_" + str(size) + ".png") | |
| def colour_grid(size=300): | |
| img = Image.new('RGB', (size, size)) | |
| for x in range(size): | |
| for y in range(size): | |
| r = round(255 * max(0, cos(x / 15))) | |
| b = round(150 * max(0, sin(y / 15))) | |
| g = round(255 * max(0, tan((x + y) / 15))) | |
| img.putpixel((x, y), (r, g, b)) | |
| img.save("grid_" + str(size) + ".png") | |
| WHITE = (0, 0, 0) | |
| BLACK = (255, 255, 255) | |
| def checkboard(size=500, circles=4, squares=10): | |
| img = Image.new('RGB', (size, size)) | |
| r = (math.sqrt(size * size + size * size) / 2) / circles | |
| a = round(size / squares) | |
| def circle_number(mx, my): | |
| distance = math.sqrt((size / 2 - mx) ** 2 + (size / 2 - my) ** 2) | |
| return math.ceil(distance / r) | |
| for x in range(size): | |
| for y in range(size): | |
| col = WHITE | |
| opposite = BLACK | |
| # Determines in what circle x and y are | |
| if circle_number(x, y) % 2 == 0: | |
| col = BLACK | |
| opposite = WHITE | |
| # Determines in what square x and y are | |
| if (math.ceil(x / a) + math.ceil(y / a)) % 2 == 0: | |
| img.putpixel((x, y), col) | |
| else: | |
| img.putpixel((x, y), opposite) | |
| img.save("checkboard" + str(size) + "_" + str(circles) + "_" + str(squares) + ".png") | |
| waves(1000) | |
| colour_grid(1000) | |
| checkboard(1000, 5, 10) | |
| checkboard(1000, 10, 5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment