Ejemplo n.º 1
0
def drawPolygon(x = 0, y = 0, radius = 50, numberOfSides = 3):
    angle = 2 * math.pi / numberOfSides

    # Connect points for the polygon
    for i in range(numberOfSides + 1):  
        for j in range(numberOfSides + 1):  
             drawLine(x + radius * math.cos(i * angle),
                y - radius * math.sin(i * angle),     
                x + radius * math.cos(j * angle),
                y - radius * math.sin(j * angle))     
Ejemplo n.º 2
0
def drawPolygon(x=0, y=0, radius=50, numberOfSides=3):
    angle = 2 * math.pi / numberOfSides

    # Connect points for the polygon
    for i in range(numberOfSides + 1):
        for j in range(numberOfSides + 1):
            drawLine(x + radius * math.cos(i * angle),
                     y - radius * math.sin(i * angle),
                     x + radius * math.cos(j * angle),
                     y - radius * math.sin(j * angle))
Ejemplo n.º 3
0
def paintBranch(depth, x1, y1, length, angle):
    if depth >= 0:
       x2 = x1 + math.cos(angle) * length
       y2 = y1 + math.sin(angle) * length

       # Draw the line
       drawLine([x1, y1], [x2, y2])

       # Draw the left branch
       paintBranch(depth - 1, x2, y2, length * sizeFactor, angle + angleFactor)
       # Draw the right branch
       paintBranch(depth - 1, x2, y2, length * sizeFactor, angle - angleFactor)
Ejemplo n.º 4
0
def paintBranch(depth, x1, y1, length, angle):
    if depth >= 0:
        x2 = x1 + math.cos(angle) * length
        y2 = y1 + math.sin(angle) * length

        # Draw the line
        drawLine([x1, y1], [x2, y2])

        # Draw the left branch
        paintBranch(depth - 1, x2, y2, length * sizeFactor,
                    angle + angleFactor)
        # Draw the right branch
        paintBranch(depth - 1, x2, y2, length * sizeFactor,
                    angle - angleFactor)
Ejemplo n.º 5
0
def displayKochSnowFlake(order, p1, p2):
    if order == 0:
        # Draw a line
        drawLine(p1, p2)
    else:
        # Get points x, y, z on the edge 
        deltaX = p2[0] - p1[0]
        deltaY = p2[1] - p1[1]

        x = [p1[0] + deltaX / 3, p1[1] + deltaY / 3]
        y = [p1[0] + deltaX * 2 / 3, p1[1] + deltaY * 2 / 3]
        z = [((p1[0] + p2[0]) / 2 - math.cos(math.radians(30)) * (p1[1] - p2[1]) / 3),
          (int)((p1[1] + p2[1]) / 2 - math.cos(math.radians(30)) * (p2[0] - p1[0]) / 3)]

        # Recursively display snow flakes on lines
        displayKochSnowFlake(order - 1, p1, x)
        displayKochSnowFlake(order - 1, x, z)
        displayKochSnowFlake(order - 1, z, y)
        displayKochSnowFlake(order - 1, y, p2)
Ejemplo n.º 6
0
def displayKochSnowFlake(order, p1, p2):
    if order == 0:
        # Draw a line
        drawLine(p1, p2)
    else:
        # Get points x, y, z on the edge
        deltaX = p2[0] - p1[0]
        deltaY = p2[1] - p1[1]

        x = [p1[0] + deltaX / 3, p1[1] + deltaY / 3]
        y = [p1[0] + deltaX * 2 / 3, p1[1] + deltaY * 2 / 3]
        z = [((p1[0] + p2[0]) / 2 - math.cos(math.radians(30)) *
              (p1[1] - p2[1]) / 3),
             (int)((p1[1] + p2[1]) / 2 - math.cos(math.radians(30)) *
                   (p2[0] - p1[0]) / 3)]

        # Recursively display snow flakes on lines
        displayKochSnowFlake(order - 1, p1, x)
        displayKochSnowFlake(order - 1, x, z)
        displayKochSnowFlake(order - 1, z, y)
        displayKochSnowFlake(order - 1, y, p2)
Ejemplo n.º 7
0
def displayHShape(order, center, length):
    if order >= 0:
        p1 = [center[0] - length / 2, center[1] + length / 2]
        p2 = [center[0] - length / 2, center[1] - length / 2]
        p3 = [center[0] + length / 2, center[1] + length / 2]
        p4 = [center[0] + length / 2, center[1] - length / 2]

        # Draw an H shape
        drawLine([center[0] - length / 2, center[1]],
                 [center[0] + length / 2, center[1]])
        drawLine(p1, p2)
        drawLine(p3, p4)

        # Recursively display three H shape of a smaller order
        displayHShape(order - 1, p1, length / 2)
        displayHShape(order - 1, p2, length / 2)
        displayHShape(order - 1, p3, length / 2)
        displayHShape(order - 1, p4, length / 2)
Ejemplo n.º 8
0
def displayHShape(order, center, length):
    if order >= 0:
        p1 = [center[0] - length / 2, center[1] + length / 2]
        p2 = [center[0] - length / 2, center[1] - length / 2]
        p3 = [center[0] + length / 2, center[1] + length / 2]
        p4 = [center[0] + length / 2, center[1] - length / 2]

        # Draw an H shape
        drawLine([center[0] - length / 2, center[1]], 
            [center[0] + length / 2, center[1]])
        drawLine(p1, p2)
        drawLine(p3, p4)
        
        # Recursively display three H shape of a smaller order
        displayHShape(order - 1, p1, length / 2)
        displayHShape(order - 1, p2, length / 2)
        displayHShape(order - 1, p3, length / 2)
        displayHShape(order - 1, p4, length / 2)
'''
@Date: 2019-11-26 20:31:42
@Author: ywyz
@LastModifiedBy: ywyz
@Github: https://github.com/ywyz
@LastEditors: ywyz
@LastEditTime: 2019-11-26 20:39:46
'''
from UsefulTurtleFunctions import drawLine
import turtle

drawLine(40, -69.28, -40, -69.28)
drawLine(-40, -69.28, -80, -9.8)
drawLine(-80, -9.8, -40, 69)
drawLine(-40, 69, 40, 69)
drawLine(40, 69, 80, 0)
drawLine(80, 0, 40, -69.28)
drawLine(40, -69.28, -80, -9.8)
drawLine(40, -69.28, -40, -69)
drawLine(40, -69.28, 40, 69)
drawLine(-40, -69.28, -40, 69)
drawLine(-40, -69.28, 40, 69)
drawLine(-40, -69.28, 80, 0)
drawLine(-80, -9.8, -40, 69)
drawLine(-80, -9.8, 40, 69)
drawLine(-80, -9.8, 80, 0)
drawLine(-40, 69, 80, 0)
turtle.done()
Ejemplo n.º 10
0
turtle.speed(0) # Fastest   

# Draw a square function
scaleFactor = 0.01
left = -100
right = 100
x = left
turtle.penup()
turtle.goto(x, scaleFactor * x * x)
turtle.pendown()
for  x in range(left, right + 1):
    turtle.goto(x, scaleFactor * x * x)

# Draw X-axis
drawLine(-160, 0, 160, 0)

# Draw Y-axis
drawLine(0, -80, 0, 80)

# Display X
writeText("Y", 0, 80)
            
# Display Y
writeText("X", 180, -15) 

# Draw arrows
turtle.degrees()
turtle.penup()
turtle.goto(160, 0)
turtle.pendown()
Ejemplo n.º 11
0
def drawPolygon(points):
    drawPolyline(points)
    drawLine(points[len(points) - 1], points[0])  # Close the polygon
Ejemplo n.º 12
0
def drawPolyline(points):
    for i in range(len(points) - 1):
        drawLine(points[i], points[i + 1])
Ejemplo n.º 13
0
def drawPolyline(points):
    for i in range(len(points) - 1):
        drawLine(points[i], points[i + 1])
Ejemplo n.º 14
0
def drawPolygon(points):
    drawPolyline(points)
    drawLine(points[len(points) - 1], points[0])  # Close the polygon
Ejemplo n.º 15
0
turtle.speed(0)  # Fastest

# Draw a square function
scaleFactor = 0.01
left = -100
right = 100
x = left
turtle.penup()
turtle.goto(x, scaleFactor * x * x)
turtle.pendown()
for x in range(left, right + 1):
    turtle.goto(x, scaleFactor * x * x)

# Draw X-axis
drawLine(-160, 0, 160, 0)

# Draw Y-axis
drawLine(0, -80, 0, 80)

# Display X
writeText("Y", 0, 80)

# Display Y
writeText("X", 180, -15)

# Draw arrows
turtle.degrees()
turtle.penup()
turtle.goto(160, 0)
turtle.pendown()
Ejemplo n.º 16
0
import turtle
import math
from UsefulTurtleFunctions import drawLine
from UsefulTurtleFunctions import writeText

turtle.speed(0)  # Fastest

# Draw X-axis
drawLine(-220, 0, 220, 0)

# Draw arrows
turtle.degrees()
turtle.setheading(150)
turtle.forward(20)

turtle.penup()
turtle.goto(220, 0)
turtle.pendown()
turtle.setheading(-150)
turtle.forward(20)

# Draw Y-axis
drawLine(0, -80, 0, 80)

turtle.penup()
turtle.goto(0, 80)
turtle.pendown()
turtle.setheading(240)
turtle.forward(20)

turtle.penup()
Ejemplo n.º 17
0
import turtle
import math
from UsefulTurtleFunctions import drawLine

radius = 100
x1 = radius * math.cos(math.pi / 10)
y1 = radius * math.sin(math.pi / 10)

x2 = radius * math.cos(2 * math.pi / 5 + math.pi / 10)
y2 = radius * math.sin(2 * math.pi / 5 + math.pi / 10)

x3 = radius * math.cos(4 * math.pi / 5 + math.pi / 10)
y3 = radius * math.sin(4 * math.pi / 5 + math.pi / 10)

x4 = radius * math.cos(6 * math.pi / 5 + math.pi / 10)
y4 = radius * math.sin(6 * math.pi / 5 + math.pi / 10)

x5 = radius * math.cos(8 * math.pi / 5 + math.pi / 10)
y5 = radius * math.sin(8 * math.pi / 5 + math.pi / 10)

drawLine(x1, y1, x3, y3)
drawLine(x1, y1, x4, y4)
drawLine(x2, y2, x4, y4)
drawLine(x2, y2, x5, y5)
drawLine(x3, y3, x5, y5)

turtle.hideturtle()

turtle.done()
Ejemplo n.º 18
0
'''
@Date: 2019-11-26 19:35:42
@Author: ywyz
@LastModifiedBy: ywyz
@Github: https://github.com/ywyz
@LastEditors: ywyz
@LastEditTime: 2019-11-26 19:49:33
'''
import turtle
from math import pi, sin

from UsefulTurtleFunctions import drawLine, writeText

drawLine(-200, 0, 200, 0)
drawLine(175, 15, 200, 0)
drawLine(200, 0, 175, -15)
drawLine(0, 200, 0, -200)
drawLine(-15, 175, 0, 200)
drawLine(0, 200, 15, 175)
turtle.penup()
for x in range(-175, 176):
    turtle.goto(x, 50 * sin((x / 100) * 2 * pi))
    turtle.pendown()

writeText("-2\u03c0", -100, -15)
writeText("2\u03c0", 100, -15)

turtle.done()
Ejemplo n.º 19
0
import turtle
import math
from UsefulTurtleFunctions import drawLine
from UsefulTurtleFunctions import writeText

turtle.speed(0) # Fastest   

# Draw X-axis
drawLine(-220, 0, 220, 0)

# Draw arrows
turtle.degrees()
turtle.setheading(150)
turtle.forward(20)

turtle.penup()
turtle.goto(220, 0)
turtle.pendown()
turtle.setheading(-150)
turtle.forward(20)

# Draw Y-axis
drawLine(0, -80, 0, 80)

turtle.penup()
turtle.goto(0, 80)
turtle.pendown()
turtle.setheading(240)
turtle.forward(20)

turtle.penup()