96
loading...
This website collects cookies to deliver better user experience
By two types I mean degenerate (must lift pen) and non-degenerate/regular (no lift pen) but I don't know the true names of these star polygons types. But I hope I get the idea across
import turtle as t
t.shape('turtle')
t.color('#4F86F7')
t.pensize(2)
LENGTH=200
t.circle(LENGTH)
t.circle(LENGTH,steps=3)
t.circle(LENGTH,steps=4)
t.circle(LENGTH,steps=5)
steps
parameter. Here's what we get:steps
argument, we can use it twice from two different places on a circle to draw our starimport turtle as t
t.shape('turtle')
t.color('#4F86F7')
t.pensize(2)
LENGTH=200
def star_of_david():
"""Draws two overlapping triangles
"""
t.circle(LENGTH,steps=3)
t.penup()
t.circle(LENGTH, 180)
t.pendown()
t.circle(LENGTH,steps=3)
t.circle(LENGTH)
star_of_david()
t.circle(LENGTH, 180)
makes the turtle go to the top of the circle so that it can draw another triangle from there. Here's what we getimport turtle as t
t.shape('turtle')
t.color('#4F86F7')
t.pensize(2)
LENGTH=200
def degenerate_octagram():
t.circle(LENGTH,steps=4)
segments=8
t.circle(LENGTH,360/segments)
t.circle(LENGTH,steps=4)
t.circle(LENGTH)
degenerate_octagram()
360 / segments
. segments = 8
because an octagram has 8 equal segments.Remember that a n-gram star has n equal segments
import turtle as t
t.shape('turtle')
t.color('#4F86F7')
t.pensize(2)
LENGTH=200
def enneagram():
segments=9
t.circle(LENGTH, steps=3)
t.circle(LENGTH, 360/segments)
t.circle(LENGTH, steps=3)
t.circle(LENGTH, 360/segments)
t.circle(LENGTH, steps=3)
t.circle(LENGTH)
enneagram()
circle(LENGTH, steps=3
function 3 timesn
-gram with the order m
, the quotient of n/m is the number of sides of the polygon while the order m is the number of times we need to draw the polygonFor an n,m degenerate star draw m number of regular polygons
And the polygons drawn should have n/m sides
import turtle as t
t.shape('turtle')
t.color('#4F86F7')
t.pensize(2)
LENGTH=200
def degenerate(n,m):
segments = n
order = m
sides = int(n/m)
for _ in range(order):
t.circle(LENGTH, steps=sides)
t.circle(LENGTH, 360/segments)
t.circle(LENGTH)
degenerate(10,2)
(10,2) | (12,2) |
---|---|
![]() |
![]() |
(12,3) | (12,4) |
---|---|
![]() |
![]() |
(10,5) | (12,6) |
---|---|
![]() |
![]() |
import turtle as t
t.shape('turtle')
t.color('#4F86F7')
t.pensize(2)
LENGTH=150
def regular_star(n,m):
""" n = number of pointies
m = order of the star,
(number of skips + 1)
"""
angle = 360*m/n
for count in range(n):
t.forward(LENGTH)
t.right(angle)
regular_star(10,4)
n
is not divisible by m
and as such we cannot draw it with the degenerate
function we wrote earlier.step
parameter anymore. We need to draw a regular star then rotate it to draw another star. To do that we will first begin by modifying our regular_star function as followsdef regular_star(n,m):
""" n = number of pointies
m = order of the star,
(number of skips + 1)
"""
angle = 360*m/n
t.left(180-angle/2)
for count in range(n):
t.forward(LENGTH)
t.right(angle)
t.right(180-angle/2)
t.left(180-angle/2)
to place the regular star to the left side of the turtle. This is similar to how a circle command behaves![]() |
![]() |
import turtle as t
import math
t.shape('turtle')
t.color('#4F86F7')
t.pensize(2)
RADIUS=150
def regular_star(n,m):
""" n = number of pointies
m = order of the star,
(number of skips + 1)
"""
angle = 360*m/n
center_angle = 2*m*math.pi/n
t.left(180-angle/2)
length=2*RADIUS*math.sin(center_angle/2)
for count in range(n):
t.forward(length)
t.right(angle)
t.right(180-angle/2)
regular_star(7,2)
t.circle(RADIUS)
LENGTH
with RADIUS
. This is to allow us to draw the star of a defined radiusm
segments on the center of the circle. center_angle
is the representation of arch length in radianscenter_angle
and the RADIUS
to compute the length of the arms of the star(5,2) | (7,2) | (7,3) |
---|---|---|
![]() |
![]() |
![]() |
Star | Properties |
---|---|
(6,2) | 2 overlapping triangles |
(8,2) | 2 overlapping squares |
(9,3) | 3 overlapping triangles |
(10,4) | 2 overlapping pentagrams |
(14,4) | 2 (7,2) stars |
(14,6) | 2 (7,3) stars |
(15,6) | 3 overlapping pentagrams |
The above can be verified by trying them out on a piece of paper (or by just thinking way too hard)
n
and m
n
and m
by the gcd
to obtain a star (n/gcd,m/gcd)gcd
number of timesimport turtle as t
import math
t.shape('turtle')
t.color('#4F86F7')
t.pensize(2)
RADIUS=150
def regular_star(n,m):
""" n = number of pointies
m = order of the star,
(number of skips + 1)
"""
angle = 360*m/n
center_angle = 2*m*math.pi/n
t.left(180-angle/2)
length=2*RADIUS*math.sin(center_angle/2)
for count in range(n):
t.forward(length)
t.right(angle)
t.right(180-angle/2)
def star(n,m):
""" n = number of pointies
m = order of the star,
(number of skips + 1)
"""
gcd = math.gcd(n,m)
new_n = int(n/gcd)
new_m = int(m/gcd)
segment_angle = 360/n
for _ in range(gcd):
regular_star(new_n, new_m)
t.penup()
t.circle(RADIUS, segment_angle)
t.pendown()
star(10,4)
Name | Drawing |
---|---|
(10,1) | ![]() |
(10,2) | ![]() |
(10,3) | ![]() |
(10,4) | ![]() |
(10,5) | ![]() |
(14,4) | ![]() |
(14,6) | ![]() |
(15,6) | ![]() |
def all_stars(n):
for x in range(int(n/2)):
star(n,x+1)
all_stars(10)
t.hide()