Пример #1
0
def piirraSuorakulmiot(suorakulmiot):
    t = turtle2.Turtle()
    t.speed("fastest")
    t.color("red")
    t.hideturtle()
    for rect in suorakulmiot:
        piirraSuorakulmio(t, rect[0], rect[1], rect[2], rect[3])
Пример #2
0
def drawRectangles(rectangles):
    t = turtle2.Turtle()
    t.speed("fastest")
    t.color("red")
    t.hideturtle()
    for rect in rectangles:
        drawRectangle(t, rect[0], rect[1], rect[2], rect[3])
Пример #3
0
def drawDots():
    joe = turtle2.Turtle()
    size = 4
    joe.penup()
    joe.color("blue")
    joe.goto(0, 50)
    joe.dot(size)
    joe.goto(0, 100)
    joe.dot(size)
    joe.goto(100, 0)
    joe.dot(size)
    joe.goto(100, 150)
    joe.dot(size)
    joe.goto(50, 75)
    joe.dot(size)
    joe.goto(-150, 20)
    joe.dot(size)
    joe.goto(-250, 35)
    joe.dot(size)
    joe.goto(-200, 50)
    joe.dot(size)
    joe.goto(-250, 75)
    joe.dot(size)
    joe.goto(-200, 125)
    joe.dot(size)
    joe.penup()
    joe.goto(600, 600)
Пример #4
0
def drawFinishLine(x1, x2, y):
    t = turtle2.Turtle()
    t.hideturtle()
    t.speed("fastest")
    t.color("blue")
    t.pensize(3)
    t.penup()
    t.goto(x1, y)
    t.pendown()
    t.goto(x2, y)
Пример #5
0
def piirraMaaliviiva(x1, x2, y):
    t = turtle2.Turtle()
    t.hideturtle()
    t.speed("fastest")
    t.color("blue")
    t.pensize(3)
    t.penup()
    t.goto(x1, y)
    t.pendown()
    t.goto(x2, y)
Пример #6
0
def prepareCoordinates():
    turtle2.pauseDrawing()
    t = turtle2.Turtle()
    t.color("#545454")
    t.hideturtle()
    t.speed(0)
    t.penup()
    drawAxis(t, -600, 0)
    t.right(270)
    drawAxis(t, 0, -600)
    drawTicksX(t, -600)
    t.right(270)
    drawTicksY(t, -600)
    drawXnumbers(t, -600)
    drawYnumbers(t, -600)
    turtle2.unpauseDrawing()
Пример #7
0
def generateObstacles(n):
    t = turtle2.Turtle()
    t.speed("fastest")
    t.color("red")

    rectangles = []
    for i in range(n):
        x = random.randint(-maxWidth, maxWidth)
        y = random.randint(-maxHeight, maxHeight)
        w = random.randint(10, 300)
        h = random.randint(10, 300)

        draw_block(t, x, y)
        rectangles.append((x, y, w, h))

    t.hideturtle()
    return rectangles
Пример #8
0
def luo_esteet(n):
    t = turtle2.Turtle()
    t.speed("fastest")
    t.color("red")

    esteLista = []
    for i in range(n):
        x = random.randint(-maxLeveys, maxLeveys)
        y = random.randint(-maxKorkeus, maxKorkeus)
        w = random.randint(10, 300)
        h = random.randint(10, 300)

        piirra_kuutio(t, x, y)
        esteLista.append((x, y, w, h))

    t.hideturtle()
    return esteLista
Пример #9
0
def draw_block(x, y, color=(255, 0, 0), size=30):
    turtle2.pauseDrawing()
    t = turtle2.Turtle()
    t.speed("fastest")
    t.hideturtle()
    t.penup()
    t.goto(x, y)
    t.setheading(90)
    t.pendown()

    # The right side
    t.fillcolor(blend_colors(color, (0, 0, 0)))
    t.begin_fill()
    t.forward(size)
    t.right(60)
    t.forward(size)
    t.right(120)
    t.forward(size)
    t.right(60)
    t.forward(size)
    t.end_fill()

    # The left side
    t.fillcolor(blend_colors(color, (0, 0, 0), weight1=3.0))
    t.begin_fill()
    t.right(60)
    t.forward(size)
    t.right(60)
    t.forward(size)
    t.right(120)
    t.forward(size)
    t.end_fill()

    # The top side
    t.fillcolor(color)
    t.begin_fill()
    t.right(180)
    t.forward(size)
    t.right(120)
    t.forward(size)
    t.right(60)
    t.forward(size)
    t.end_fill()

    turtle2.unpauseDrawing()
Пример #10
0
def piirra_kuutio(x, y, vari=(255, 0, 0), koko=30):
    turtle2.pauseDrawing()
    t = turtle2.Turtle()
    t.speed("fastest")
    t.hideturtle()
    t.penup()
    t.goto(x, y)
    t.setheading(90)
    t.pendown()

    # Oikea puoli
    t.fillcolor(sekoita_varit(vari, (0, 0, 0)))
    t.begin_fill()
    t.forward(koko)
    t.right(60)
    t.forward(koko)
    t.right(120)
    t.forward(koko)
    t.right(60)
    t.forward(koko)
    t.end_fill()

    # Vasen puoli
    t.fillcolor(sekoita_varit(vari, (0, 0, 0), paino1=3.0))
    t.begin_fill()
    t.right(60)
    t.forward(koko)
    t.right(60)
    t.forward(koko)
    t.right(120)
    t.forward(koko)
    t.end_fill()

    # Yläpuoli
    t.fillcolor(vari)
    t.begin_fill()
    t.right(180)
    t.forward(koko)
    t.right(120)
    t.forward(koko)
    t.right(60)
    t.forward(koko)
    t.end_fill()

    turtle2.unpauseDrawing()
Пример #11
0
# Turtle moving around cubes

##### INFO #####
import turtle2
import random

# Here we define a turtle and its speed
t = turtle2.Turtle()
t.speed("fastest")
t.color("black")

# Here we calculate the size of the screen
screen = turtle2.Screen()
screen.bgcolor("blue")
width = screen.window_width()
height = screen.window_height()
maxWidth = width / 2
minWidth = -maxWidth
maxHeight = height / 2
minHeight = -maxHeight


def blend_colors(color1, color2, weight1=1.0, weight2=1.0):
    u = weight1 / (weight1 + weight2)
    v = weight2 / (weight1 + weight2)
    return (u * color1[0] + v * color2[0], u * color1[1] + v * color2[1],
            u * color1[2] + v * color2[2])


def draw_block(t, x, y, color=(255, 0, 0), size=50):
    turtle2.pauseDrawing()
Пример #12
0
oikea = min(250, screen.window_width() / 2 - 5)
vasen = -oikea
yla = min(270, screen.window_height() / 2 - 5)
ala = -yla

esteet = (ulkoReunat(vasen, oikea, yla, ala) +
          luoEsteet(4, vasen, oikea, yla - 20, ala + 60))

# Piirrä esteet
turtle2.pauseDrawing()
piirraSuorakulmiot(esteet)
piirraMaaliviiva(vasen, oikea, yla)
turtle2.unpauseDrawing()

# Create the turtle
kilpppari = turtle2.Turtle()
kilpppari.speed("fastest")
kilpppari.penup()
kilpppari.goto((vasen + oikea) / 2, ala + 20)
kilpppari.setheading(90)
kilpppari.pendown()

# Tämä looppi liikuttaa kilpparia, kunnes se saavuttaa maaliviivan
aloitusaika = time.time()
while kilpppari.ycor() < yla:
    siirryAskel(kilpppari, esteet)
lopetusaika = time.time()

print "Kilppari saavutti maaliviivan %d sekunnissa!" % round(lopetusaika -
                                                             aloitusaika)