Example #1
0
def draw_shape(t):
    # large circle
    circle(t, 100)

    # 4 triangles
    move(t, 0, 100)
    t.setheading(60)
    polygon(t, 3, 100)
    t.setheading(150)
    polygon(t, 3, 100)
    t.setheading(240)
    polygon(t, 3, 100)
    t.setheading(330)
    polygon(t, 3, 100)

    # 4 small circles
    moving_step = 50 * math.sqrt(3)
    small_radius = 50 * math.sqrt(3) / 3

    move(t, 0, 100 - moving_step)
    t.setheading(0)
    circle(t, small_radius)

    move(t, moving_step, 100)
    t.setheading(90)
    circle(t, small_radius)

    move(t, 0, 100 + moving_step)
    t.setheading(180)
    circle(t, small_radius)

    move(t, -moving_step, 100)
    t.setheading(270)
    circle(t, small_radius)
Example #2
0
def main():
    t = turtle.Turtle()
    t.speed(0)
    flower(t, 6, 60.0, 60.0)

    move(t, 0, -60)
    circle(t, 60)

    t.hideturtle()
    turtle.Screen().mainloop()
Example #3
0
def draw_two_circles(t):
    """
    Draws two circles. t is a turtle.
    """
    # large circle
    circle(t, 100)
    move(t, 100, 0)

    # another large circle
    circle(t, 100)
Example #4
0
def draw_stuff():
    """
    draws a square and a circle
    """
    leo = turtle.Turtle()

    # draw a square at the defaul origin position
    turtle_shape.square(leo, 100)

    # move pen to a new position (200px to eastward, 100px northward)
    turtle_shape.move(leo, 200, 100)

    # draw a circle at the new position
    turtle_shape.circle(leo, 50)

    turtle.mainloop()
Example #5
0
def circle_triangle(t, r):
    """
    Draws a pattern of circles within triangles within circle, 
    t is a turtle, r is the radius of the outter circle 
    """
    # draws the big circle
    circle(t, r)

    # draws the four triangles
    move(t, 0, r)
    t.lt(60)
    for _ in range(4):
        t.lt(90)
        polygon(t, r, 3)

    # calculations for small circles
    degree30 = math.radians(30)
    degree60 = math.radians(60)
    r_s = r / 2 / math.tan(degree60)
    height = r * math.cos(degree30)

    # draws the bottom small circle
    y1 = 100 - height
    move(t, 0, y1)
    t.rt(60)
    circle(t, r_s)

    # draws the top small circle
    y2 = 100 + height
    move(t, 0, y2)
    t.lt(180)
    circle(t, r_s)

    #draws the left small circle
    x1 = -height
    move(t, x1, r)
    t.lt(90)
    circle(t, r_s)

    # draws the right small circle
    x2 = height
    move(t, x2, r)
    t.lt(180)
    circle(t, r_s)
Example #6
0
def draw_two_circles(t):
    """
    draws two circles. t is a turtle
    """
    # large circle
    circle(t, 100)
    move(t, 100, 0)

    #another large circle
    circle(t, 100)

    def main():
        t = turtle.Turtle()
        t.speed(0)
        draw_two_circles(t)
        turtle.screen().mainloop()

    if __name__ == "__main__":
        main()
Example #7
0
def draw_yinyang(t):
    # large circle
    circle(t, 100)

    # two arcs
    move(t, 0, 100)
    t.setheading(180)
    arc(t, 50, 180)

    move(t, 0, 100)
    t.setheading(0)
    arc(t, 50, 180)

    # small circles
    move(t, 0, 50 + 100 / 6)
    circle(t, 100 / 6)

    move(t, 0, 150 + 100 / 6)
    circle(t, 100 / 6)
Example #8
0
def yinyang(t):
    """
    Draws a yinyang symbol, t is a turtle
    """
    # draws the outter circle
    circle(t, 100)

    # draws the two arcr
    for _ in range(2):
        move(t, 0, 100)
        arc(t, 50, 180)

    # draws the two small circle
    move(t, 0, 35)
    circle(t, 15)
    move(t, 0, 135)
    circle(t, 15)
Example #9
0
from turtle_shape import arc, circle, move, polygon
import turtle
import math

# 3.1.1

alex = turtle.Turtle()
alex.speed(0)

# large circle
circle(alex, 100)

# 4 triangles
move(alex, 0, 100)
alex.setheading(60)
polygon(alex, 3, 100)
alex.setheading(150)
polygon(alex, 3, 100)
alex.setheading(240)
polygon(alex, 3, 100)
alex.setheading(330)
polygon(alex, 3, 100)

# 4 small circles
moving_step = 50 * math.sqrt(3)
small_radius = 50 * math.sqrt(3) / 3

move(alex, 0, 100 - moving_step)
alex.setheading(0)
circle(alex, small_radius)
Example #10
0
import turtle
from turtle_shape import arc, circle, move, polygon

alex = turtle.Turtle()
alex.speed(0)

circle(alex, 100)


def petal(t, r, angle):
    for i in range(2):
        arc(t, r, angle)
        t.lt(180 - angle)


def flower(t, n, r, angle):
    for i in range(n):
        petal(t, r, angle)
        t.lt(360.0 / n)


bob = turtle.Turtle()

move(bob, 0, 100)
flower(bob, 7, 100.0, 60.0)

bob.hideturtle()
turtle.mainloop()
Example #11
0
from turtle_shape import arc, circle, move, polygon
import turtle
import math

# 3.1.1

jerry = turtle.Turtle()
jerry.speed(0)

# large circle
circle(jerry, 100)

# 4 triangles
move(jerry, 0, 100)
jerry.setheading(60)
polygon(jerry, 3, 100)
jerry.setheading(150)
polygon(jerry, 3, 100)
jerry.setheading(240)
polygon(jerry, 3, 100)
jerry.setheading(330)
polygon(jerry, 3, 100)

# 4 small circles
moving_step = 50 * math.sqrt(3)
small_radius = 50 * math.sqrt(3) / 3

move(jerry, 0, 100 - moving_step)
jerry.setheading(0)
circle(jerry, small_radius)
Example #12
0
import turtle
from turtle_shape import arc, circle, move, polygon

jerry = turtle.Turtle()
jerry.speed(0)

# large circle
circle(jerry, 100)

# two arcs
move(jerry, 0, 100)
jerry.setheading(180)
arc(jerry, 50, 180)

move(jerry, 0, 100)
jerry.setheading(0)
arc(jerry, 50, 180)

# small circles
move(jerry, 0, 50 + 100 / 6)
circle(jerry, 100 / 6)

move(jerry, 0, 150 + 100 / 6)
circle(jerry, 100 / 6)

turtle.mainloop()
Example #13
0
from turtle_shape import square, polygon, circle, move
import turtle

brian = turtle.Turtle()

move(brian, -100, 0)

square(brian, 100)

move(brian, 100, 0)

circle(brian, 100)

turtle.mainloop()
Example #14
0
        t.lt(180 - angle)


def flower(t, n, r, angle):
    """Draws a flower with n petals.

    t: Turtle
    n: number of petals
    r: radius of the arcs
    angle: angle (degrees) that subtends the arcs
    """
    for i in range(n):
        petal(t, r, angle)
        t.lt(360.0 / n)


t = turtle.Turtle()

# draw a sequence of three flowers, as shown in the book.
move(t, -100, 0)
flower(t, 7, 60.0, 60.0)

move(t, 0, 0)
flower(t, 10, 40.0, 80.0)

move(t, 100, 0)
flower(t, 20, 140.0, 20.0)

t.hideturtle()
turtle.mainloop()
Example #15
0
import turtle
from turtle_shape import arc, circle, move, polygon
import math

# 3.1.1

lucky = turtle.Turtle()
lucky.speed(0)

# large circle
circle(lucky, 100)

# 4 triangles here we are printing the four triangles in the assigned different angles
move(lucky, 0, 100)
lucky.setheading(60)
polygon(lucky, 3, 100)
lucky.setheading(150)
polygon(lucky, 3, 100)
lucky.setheading(240)
polygon(lucky, 3, 100)
lucky.setheading(330)
polygon(lucky, 3, 100)


# 4 small circles same thing except with the four different circles 
moving_step = 50 * math.sqrt(3)
small_radius = 50 * math.sqrt(3) / 3

move(lucky, 0, 100 - moving_step)
lucky.setheading(0)
circle(lucky, small_radius)
Example #16
0
import turtle
from turtle_shape import arc, circle, move, polygon

jack = turtle.Turtle()
jack.speed(0)

# large circle
circle(jack, 100)

# two arcs
move(jack, 0, 100)
jack.setheading(180)
arc(jack, 50, 180)

move(jack, 0, 100)
jack.setheading(0)
arc(jack, 50, 180)

# small circles
move(jack, 0, 50 + 100 / 6)
circle(jack, 100 / 6)

move(jack, 0, 150 + 100 / 6)
circle(jack, 100 / 6)

turtle.mainloop()
Example #17
0
import turtle
from turtle_shape import arc, circle, move, polygon


alex = turtle.Turtle()
alex.speed(0)

# large circle
circle(alex, 100)

# two arcs
move(alex, 0, 100)
alex.setheading(180)
arc(alex, 50, 180)

move(alex, 0, 100)
alex.setheading(0)
arc(alex, 50, 180)

# small circles
move(alex, 0, 50 + 100 / 6)
circle(alex, 100 / 6)

move(alex, 0, 150 + 100 / 6)
circle(alex, 100 / 6)

turtle.mainloop()
from turtle_shape import arc, circle, move, polygon
import turtle
import math

# 3.1.1

jack = turtle.Turtle()
jack.speed(0)

# large circle
circle(jack, 100)

# 4 triangles
move(jack, 0, 100)
jack.setheading(60)
polygon(jack, 3, 100)
jack.setheading(150)
polygon(jack, 3, 100)
jack.setheading(240)
polygon(jack, 3, 100)
jack.setheading(330)
polygon(jack, 3, 100)

# 4 small circles
moving_step = 50 * math.sqrt(3)
small_radius = 50 * math.sqrt(3) / 3

move(jack, 0, 100 - moving_step)
jack.setheading(0)
circle(jack, small_radius)
Example #19
0
from turtle_shape import square, polygon, circle, move
import turtle

jack = turtle.Turtle()

move(jack, -100, 0)

square(jack, 100)

move(jack, 100, 0)

circle(jack, 100)

turtle.mainloop()
Example #20
0
        t.lt(180 - angle)


def flower(t, n, r, angle):
    """Draws a flower with n petals.

    t: Turtle
    n: number of petals
    r: radius of the arcs
    angle: angle (degrees) that subtends the arcs
    """
    for i in range(n):
        petal(t, r, angle)
        t.lt(360.0 / n)


bob = turtle.Turtle()

# draw a sequence of three flowers, as shown in the book.
move(bob, -100, 0)
flower(bob, 7, 60.0, 60.0)

move(bob, 0, 0)
flower(bob, 10, 40.0, 80.0)

move(bob, 100, 0)
flower(bob, 20, 140.0, 20.0)

bob.hideturtle()
turtle.mainloop()