Last active
August 29, 2015 14:19
-
-
Save adusak/35f43b811065dac62225 to your computer and use it in GitHub Desktop.
Relative and absolute drawing of pentagram using turle
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 sin, radians, cos | |
| from python.common.Turtle import Turtle | |
| from python.less2.combinatorics import combinations | |
| def pentagram_relative(size=100): | |
| t = Turtle() | |
| t.forward(size) | |
| for i in range(5): | |
| t.right(360 / 5) | |
| t.forward(size) | |
| t.left(180 / 5) | |
| lengh = 2 * sin(radians((180 - 360 / 5) / 2)) * size | |
| print(lengh) | |
| for i in range(5): | |
| t.right(180 - (180 / 5)) | |
| t.forward(lengh) | |
| t.export("pentagram_relative") | |
| def ngram_abs(n=5, size=100): | |
| t = Turtle() | |
| angle = radians((360 / n)) | |
| corner_points = [(cos(i * angle) * size, sin(i * angle) * size) | |
| for i in range(n)] | |
| first_p = corner_points[0] | |
| t.penup() | |
| t.goto(first_p) | |
| t.pendown() | |
| for p in combinations(corner_points, 2): | |
| t.goto(p[0]) | |
| t.goto(p[1]) | |
| t.export(str(n) + "-gram_abs") | |
| pentagram_relative(600) | |
| ngram_abs(7, 600) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment