Last active
August 29, 2015 14:17
-
-
Save adusak/cbcf52eccf222c1910aa to your computer and use it in GitHub Desktop.
Circle in bitmap graphics
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
| import math | |
| from PIL import Image | |
| def circle(r=20, fill=True): | |
| im = Image.new("RGB", (r * 2 + 1, r * 2 + 1), (255, 255, 255)) | |
| for a in range(360): | |
| x = int(r + r * math.cos(math.radians(a))) | |
| y = int(r + r * math.sin(math.radians(a))) | |
| im.putpixel((x, y), (0, 0, 0)) | |
| if fill: | |
| for x in range(r * 2): | |
| for y in range(r * 2): | |
| if round((x - r) ** 2 + (y - r) ** 2) <= round(r ** 2): | |
| im.putpixel((x, y), (0, 0, 0)) | |
| im.save("circle" + str(r) + "_" + ("fill" if fill else "nofill") + ".png") | |
| # circle(100, fill=False) # Obr. 1 | |
| # circle(100, fill=True) # Obr. 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment