Created
November 22, 2017 20:14
-
-
Save timotta/7d6ba6ef3f78c7c943b33dd18c8f7d77 to your computer and use it in GitHub Desktop.
Circles and rays for jewelery measure
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 PIL import Image, ImageDraw | |
| import math | |
| increment = 10 | |
| margin = 0 | |
| size = 640*2 | |
| angle_increment = 5 | |
| image = Image.new('RGBA', (size, size)) | |
| draw = ImageDraw.Draw(image) | |
| def draw_circle(margin, draw): | |
| draw.ellipse((margin, margin, size-margin, size-margin), fill = 'white', outline ='pink') | |
| while margin * 2 < size: | |
| draw_circle(margin, draw) | |
| margin = margin + increment | |
| def ray(angle): | |
| x_middle, y_middle = (size/2, size/2) | |
| x, y = (size, size/2) | |
| hipotenusa = x - x_middle | |
| adjacente = math.cos(math.radians(angle)) * hipotenusa | |
| x_right = x_middle + adjacente | |
| x_left = x_middle - adjacente | |
| oposto = math.sin(math.radians(angle)) * hipotenusa | |
| y_up = y_middle - oposto | |
| y_down = y_middle + oposto | |
| draw.line( (x_middle, y_middle, x_right, y_up), fill = "pink") | |
| draw.line( (x_middle, y_middle, x_right, y_down), fill = "pink") | |
| draw.line( (x_middle, y_middle, x_left, y_up), fill = "pink") | |
| draw.line( (x_middle, y_middle, x_left, y_down), fill = "pink") | |
| angle = 0 | |
| while angle < 91: | |
| ray(angle) | |
| angle = angle + angle_increment | |
| draw_circle(margin-increment, draw) | |
| image.resize((size/2, size/2), Image.ANTIALIAS).save("teste.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment