Skip to content

Instantly share code, notes, and snippets.

@epishkin
Last active December 14, 2016 19:00
Show Gist options
  • Save epishkin/2a6cbe6e3a90e2acb1d6939ddc9c0d66 to your computer and use it in GitHub Desktop.
Save epishkin/2a6cbe6e3a90e2acb1d6939ddc9c0d66 to your computer and use it in GitHub Desktop.
import turtle
t = turtle.Pen()

def line(count, size, alpha, beta):
	if count==0:
		return
	else:
	    t.forward(size)
	    t.right(180 - beta)
	    t.forward(size)
	    t.left(180 - (360 - alpha - (2*beta)))
	    line(count -1, size, alpha, beta)

t.reset()
line(5, 50, 108, 60)


def shape(count, size, beta):
    t.reset()
    alpha = 180*(count - 2)/count
    line(count, size, alpha, beta)

shape(5, 50, 60)

def shapes(count, size):
    if count==1:
        return
    else:
        shape(count, size, 60)
        shapes(count-1, size)

shapes(10, 50)
import turtle
t = turtle.Pen()
def kochLine(count, size, angle):
    if count == 1:
        t.forward(size)
    else:
        koch(count-1, size/3, angle)

def kochPart(count, size, angle):
    kochLine(count, size, angle)
    t.left(angle)
    kochLine(count, size, angle)

def koch(count, size, angle):
    kochPart(count, size, angle)
    t.right(180 - angle)
    kochPart(count, size, angle)

t.reset()
koch(3, 100, 60)
def kochShapeRecursive(sides, count, size, angle, beta):
    if sides == 0:
        return
    else:
        koch(count, size, angle)
        t.right(180 - beta)
        kochShapeRecursive(sides - 1, count, size, angle, beta)

def kochShape(sides, count, size, angle):
    beta = 180*(sides - 2)/sides
    kochShapeRecursive(sides, count, size, angle, beta)

t.reset()
kochShape(3, 3, 100, 60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment