#!/bin/python3
import terrain
from landerClass import landerClass
from turtle import Screen
from math import sin, cos, radians
lander = landerClass()
Screen().onkey(lander.left, "Left")
Screen().onkey(lander.right, "Right")
Screen().onkey(lander.toggleThrust, "Space")
Screen().listen()
while True:
    lander.yVel += lander.ACCELERATION
    lander.sety(lander.ycor() - lander.yVel)
    lander.setx(lander.xcor() + lander.xVel)
    if lander.thrusters:
        heading = radians(lander.heading())
        lander.yVel -= lander.THRUST * sin(heading)
        lander.xVel += lander.THRUST * cos(heading)
if terrain.onPad(lander.xcor()) and lander.yVel < 2:
    lander.landed()
else:
    lander.crash()
Ejemplo n.º 2
0
#Throw rocks in a ocean

from turtle import Turtle, Screen

print("Creating an Ocean")
ocean = Screen()
ocean.title("Let's find Splash")

print("Creating a drawing turtle")
bob = Turtle()
bob.color('purple')
bob.speed(0)

def splash(x, y):
    print("splash at", x, y)
    bob.color('purple')
    bob.up()
    bob.goto(x, y)
    bob.down()
    bob.circle(20)
    
ocean.onclick(splash)

bob.ondrag(drag, btn=2)

ocean.listen()

Ejemplo n.º 3
0
from turtle import Turtle, Screen
import datetime

# get the current time and convert to the hand's angles
wn = Screen()
wn.title("Clock")
wn.bgcolor("saddlebrown")
wn.setup(width=1000, height=800)
currentDT = datetime.datetime.now()

# output current time
currentHour = currentDT.hour
if currentHour > 12:
    currentHour = currentHour - 12
currentMinute = currentDT.minute
if currentMinute < 10:
    print("Time logged in at - " + str(currentHour) + ":0" +
          str(currentMinute))
else:
    print("Time logged in at - " + str(currentHour) + ":" + str(currentMinute))

# outside circle
circle = Turtle()
circle.penup()
circle.pencolor("black")
circle.speed(0)
circle.hideturtle()
circle.goto(0, -370)
circle.pendown()
circle.fillcolor("gold")
circle.begin_fill()
Ejemplo n.º 4
0
def week__3(myChar):

    import turtle , random
    from turtle import Turtle, Screen

    print(''' Django 볼을 획득하라!
    노란색 Django볼을 획득하면 Mission clear 됩니다.''')
    screen = Screen()
    screen.setup(1200, 500)
    Django = Turtle()
    Django.shape('circle')
    Django.color('yellow')
    Django.up()
    point_x = random.randint(-500,500)
    point_y = random.randint(-250,250) 
    Django.goto(point_x,point_y)
    player = Turtle()
    player.speed('fastest')
    PlayerY = 0
    PlayerX = 0
    
    def play():
        if player.distance(Django) < 25:
            turtle.clear()
            turtle.write("Mission Clear",False,"center",font=("Arial",50,"normal"))
            myChar.controlPiro(5)
            myChar.controlCoding(10)

        
        if player.distance(Django) > 25:
            turtle.clear()
            turtle.write("Game Over",False,"center",font=("Arial",50,"normal"))
            myChar.controlPiro(5)
            myChar.controlMoney(-2)

    def moveX():
        nonlocal PlayerX
        screen.onkeypress(None, "Right") 
        player.clear()
        player.penup()
        player.goto(PlayerX, PlayerY)
        player.pendown()
        player.shape('turtle')
        player.color('blue')
        PlayerX += 10
        screen.onkeypress(moveX, "Right") 
        
    def moveY():
        nonlocal PlayerY
        screen.onkeypress(None, "Up") 
        player.clear()
        player.penup()
        player.goto(PlayerX, PlayerY)
        player.pendown()
        player.shape('turtle')
        player.color('blue')
        PlayerY += 10
        screen.onkeypress(moveY, "Up")

    def move_X():
        nonlocal PlayerX
        screen.onkeypress(None, "Left") 
        player.clear()
        player.penup()
        player.goto(PlayerX, PlayerY)
        player.pendown()
        player.shape('turtle')
        player.color('blue')
        PlayerX -= 10
        screen.onkeypress(move_X, "Left")

    def move_Y():
        nonlocal PlayerY
        screen.onkeypress(None, "Down") 
        player.clear()
        player.penup()
        player.goto(PlayerX, PlayerY)
        player.pendown()
        player.shape('turtle')
        player.color('blue')
        PlayerY -= 10
        screen.onkeypress(move_Y, "Down")

    screen.listen()
    turtle.ontimer(play, 9000)
    moveY()
    moveX()
    move_X()
    move_Y()

    screen.mainloop()
Ejemplo n.º 5
0
from turtle import Screen
from snake import Snake
import time
from apple import Apple
from scoreboard import Scoreboard

scr = Screen()
scr.setup(width=600, height=600)
scr.bgcolor("black")
scr.title("SNAKE")
scr.tracer(0)

snake = Snake()
apple = Apple()
scoreboard = Scoreboard()

scr.listen()
scr.onkey(snake.up, "Up")
scr.onkey(snake.down, "Down")
scr.onkey(snake.left, "Left")
scr.onkey(snake.right, "Right")


end = False
while not end:
    scr.update()
    time.sleep(0.1)
    snake.move()

    # Eat apple
    for segment in snake.segments:
Ejemplo n.º 6
0
    def ejercicio141():
        # CONFIGURACIÓN INICIAL DE LA VENTANA EMERGENTE CON SUS RESPECTIVAS PROPIEDADES
        pantalla = Screen()
        pantalla.setup(1020, 1025)
        pantalla.screensize(1000, 1000)
        pantalla.setworldcoordinates(-500, -500, 500, 500)
        pantalla.delay(0)

        # VALORES NECESARIOS PARA CADA UNO DE LOS CUERPOS
        x1 = -200
        y1 = -200
        velocidad_x1 = -0.1
        velocidad_y1 = 0
        m1 = 20

        # VALORES NECESARIOS PARA EL SEGUNDO CUERPO
        x2 = 200
        y2 = 200
        velocidad_x2 = -0.1
        velocidad_y2 = 0
        m2 = 20

        # CARACTERÍSTICAS RESPECTIVAS PARA EL PRIMER CUERPO
        cuerpo1 = Turtle('circle')
        cuerpo1.color('red')
        cuerpo1.speed(0)
        cuerpo1.penup()
        cuerpo1.goto(x1, y1)
        cuerpo1.pendown()

        # CARACTERÍSTICAS RESPECTIVAS PARA EL SEGUNDO CUERPO
        cuerpo2 = Turtle('circle')
        cuerpo2.color('blue')
        cuerpo2.speed(0)
        cuerpo2.penup()
        cuerpo2.goto(x2, y2)
        cuerpo2.pendown()

        # CICLO QUE PERMITE LA EJECUCIÓN DE LAS PROPIEDADES EN LA VENTANA EMERGENTE
        for t in range(10000):
            # PROPIEDAD PARA EL RADIO
            r = sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)

            # PROPIEDADES PARA SU RESPECTIVCA ACELERACIÓN
            aceleracion_x1 = m2 * (x2 - x1) / r ** 3
            aceleracion_y1 = m2 * (y2 - y1) / r ** 3
            aceleracion_x2 = m1 * (x1 - x2) / r ** 3
            aceleracion_y2 = m1 * (y1 - y2) / r ** 3

            # PROPIEDAD PARA SU RESPECTIVA VELOCIDAD
            velocidad_x1 += aceleracion_x1
            velocidad_y1 += aceleracion_y1
            velocidad_x2 += aceleracion_x2
            velocidad_y2 += aceleracion_y2

            # PROPIEDAD PARA LAS COORDENADAS
            x1 = velocidad_x1
            y1 = velocidad_y1
            x2 = velocidad_x2
            y2 = velocidad_y2

            # PROPIEDAD PARA LOS CUERPOS.
            cuerpo1.goto(x1, y1)
            cuerpo2.goto(x2, y2)
Ejemplo n.º 7
0
from turtle import Screen
from snake import Snake
from food import Food
from scoreboard import Scoreboard
import time

theScreen = Screen()
theScreen.setup(width=600, height=600)
theScreen.bgcolor("black")
theScreen.title("The Snake Game")
theScreen.tracer(0)

theSnake = Snake()
theFood = Food()
theScore = Scoreboard()

theScreen.listen()
theScreen.onkeypress(theSnake.up, "Up")
theScreen.onkeypress(theSnake.down, "Down")
theScreen.onkeypress(theSnake.left, "Left")
theScreen.onkeypress(theSnake.right, "Right")

keepPlaying = True

while keepPlaying:
    theScreen.update()
    time.sleep(0.1)

    theSnake.move()
    theScore.showScore()
Ejemplo n.º 8
0
class Time:
    # screen and turtle
    turtle = Turtle()
    turtle.fillcolor('gray')
    turtle.hideturtle()
    turtle.speed(0)
    turtle._delay(0)
    screen = Screen()
    screen.setup(width=600, height=400)
    screen.bgcolor('black')
    n = numbers.Numbers()
    d = digit.digit()

    # other turtles

    t1 = Turtle()
    t1.hideturtle()
    t1.speed(0)
    t1._delay(0)
    t1.fillcolor('white')

    t2 = Turtle()
    t2.hideturtle()
    t2.speed(0)
    t2._delay(0)
    t2.fillcolor('white')

    t3 = Turtle()
    t3.hideturtle()
    t3.speed(0)
    t3._delay(0)
    t3.fillcolor('white')

    t4 = Turtle()
    t4.hideturtle()
    t4.speed(0)
    t4._delay(0)
    t4.fillcolor('white')

    t5 = Turtle()
    t5.hideturtle()
    t5.speed(0)
    t5._delay(0)
    t5.fillcolor('white')

    # now

    def h1(self):
        now = datetime.now()
        h1 = str(now.strftime("%H")[0:1])
        h1 = int(h1)
        return h1

    def h2(self):
        now = datetime.now()
        h2 = str(now.strftime("%H")[1:2])
        h2 = int(h2)
        return h2

    def m1(self):
        now = datetime.now()
        m1 = str(now.strftime("%M")[0:1])
        m1 = int(m1)
        return m1

    def m2(self):
        now = datetime.now()
        m2 = str(now.strftime("%M")[1:2])
        m2 = int(m2)
        return m2

    # keret

    def keret(self, x, width):
        self.turtle.penup()
        self.turtle.begin_fill()
        self.turtle.setheading(90)
        self.turtle.goto(x, -100)
        self.turtle.pendown()
        for i in range(2):
            self.turtle.forward(220)
            self.turtle.left(90)
            self.turtle.forward(width)
            self.turtle.left(90)
        self.turtle.end_fill()

    def fullkeret(self):
        self.keret(-145, width=120)
        self.keret(-25, width=120)
        self.keret(25, width=50)
        self.keret(145, width=120)
        self.keret(265, width=120)

    # numbers selector

    def selector(self, number, size, turtle, x, y):
        if number == 0:
            self.n.number0(size=size, turtle=turtle, x=x, y=y)
        if number == 1:
            self.n.number1(size=size, turtle=turtle, x=x, y=y)
        if number == 2:
            self.n.number2(size=size, turtle=turtle, x=x, y=y)
        if number == 3:
            self.n.number3(size=size, turtle=turtle, x=x, y=y)
        if number == 4:
            self.n.number4(size=size, turtle=turtle, x=x, y=y)
        if number == 5:
            self.n.number5(size=size, turtle=turtle, x=x, y=y)
        if number == 6:
            self.n.number6(size=size, turtle=turtle, x=x, y=y)
        if number == 7:
            self.n.number7(size=size, turtle=turtle, x=x, y=y)
        if number == 8:
            self.n.number8(size=size, turtle=turtle, x=x, y=y)
        if number == 9:
            self.n.number9(size=size, turtle=turtle, x=x, y=y)

    def digit_selector(self, number, size, turtle, x, y):
        if number == 0:
            self.d.num0(size=size, turtle=turtle, x=x, y=y)
        if number == 1:
            self.d.num1(size=size, turtle=turtle, x=x, y=y)
        if number == 2:
            self.d.num2(size=size, turtle=turtle, x=x, y=y)
        if number == 3:
            self.d.num3(size=size, turtle=turtle, x=x, y=y)
        if number == 4:
            self.d.num4(size=size, turtle=turtle, x=x, y=y)
        if number == 5:
            self.d.num5(size=size, turtle=turtle, x=x, y=y)
        if number == 6:
            self.d.num6(size=size, turtle=turtle, x=x, y=y)
        if number == 7:
            self.d.num7(size=size, turtle=turtle, x=x, y=y)
        if number == 8:
            self.d.num8(size=size, turtle=turtle, x=x, y=y)
        if number == 9:
            self.d.num9(size=size, turtle=turtle, x=x, y=y)

    # base event + variables

    oldh1 = 10
    oldh2 = 10
    oldm1 = 10
    oldm2 = 10
    oldsec = 10
    valtozo = 1

    def base_event(self):
        m2 = self.m2()
        if m2 != self.oldm2:
            self.minute2(ido=m2)
            print('minute2 changed')
            self.oldm2 = m2
        m1 = self.m1()
        if m1 != self.oldm1:
            self.minute1(ido=m1)
            print('minute1 changed')
            self.oldm1 = m1
        h1 = self.h1()
        if h1 != self.oldh1:
            self.hour1(ido=h1)
            print('hour1 changed')
            self.oldh1 = h1
        h2 = self.h2()
        if h2 != self.oldh2:
            self.hour2(ido=h2)
            print('hour2 changed')
            self.oldh2 = h2
        self.screen.ontimer(fun=self.base_event, t=100)

    # second

    def second(self):
        now = datetime.now()
        second = str(now.strftime("%S")[1:2])
        second = int(second)
        if second != self.oldsec:
            if self.valtozo == 1:
                self.d.pont(turtle=self.t5, x=25, y=-100)
                self.valtozo = self.valtozo - 1
            else:
                self.t5.clear()
                self.valtozo = self.valtozo + 1
            self.oldsec = second
        self.screen.ontimer(fun=self.second, t=100)

    # writing

    def hour1(self, ido):
        self.t1.clear()
        """self.selector(number=ido, size=100, turtle=self.t1, x=-145, y=-100)"""
        self.digit_selector(number=ido,
                            size=80,
                            turtle=self.t1,
                            x=-145,
                            y=-100)

    def hour2(self, ido):
        self.t2.clear()
        """self.selector(number=ido, size=100, turtle=self.t2, x=-25, y=-100)"""
        self.digit_selector(number=ido, size=80, turtle=self.t2, x=-25, y=-100)

    def minute1(self, ido):
        self.t3.clear()
        """self.selector(number=ido, size=100, turtle=self.t3, x=145, y=-100)"""
        self.digit_selector(number=ido, size=80, turtle=self.t3, x=145, y=-100)

    def minute2(self, ido):
        self.t4.clear()
        """self.selector(number=ido, size=100, turtle=self.t4, x=265, y=-100)"""
        self.digit_selector(number=ido, size=80, turtle=self.t4, x=265, y=-100)

    # init

    def __init__(self):
        self.fullkeret()
        self.base_event()
        self.second()
        self.screen.mainloop()
Ejemplo n.º 9
0
from random_walk_class import RandomWalk
from polygon_class import Polygon
import turtle
from turtle import Screen
from datetime import datetime

colors = ['#FA9579', '#654062', '#65D6CE', '#FFE9D6']
wn = Screen().setup(300, 300)

for i in range(8):
    for col in colors:
        turtle.color(col)
        random_walk = RandomWalk(turtle, 50, 300, 300)
        random_walk.draw_random_walk()

#for x in range(3, 100):
#    turtle.speed(100)
#    if x%2 == 0:
#        shape = Polygon(10,x)
#        shape.draw()
#    else:
#        shape = Polygon(10,x, 'left')
#        shape.draw()
now = datetime.today().strftime('%Y-%m-%d-%H:%M:%S')

turtle.getcanvas().postscript(
        file=f"step_4_18_300_300_pen_up_0/random_walk_{now}.eps")

random_walk.destroy()
Ejemplo n.º 10
0
import turtle
from turtle import Screen

tl = turtle.Turtle()
Screen().setup(height=1.0, width=1.0)


def arbre(n, l):
    if n == 0:
        return
    elif n != 0:
        tl.forward(l)
        tl.left(30)
        arbre(n - 1, l / 1.5)
        tl.right(60)
        arbre(n - 1, l / 1.5)
        tl.left(30)
        tl.backward(l)


arbre(10, 100)
turtle.mainloop()
 def __init_drawing_window(cls):
     if cls.__screen is None:
         cls.__screen = Screen()
         cls.__screen.bgcolor("black")
         cls.__screen.setup(400, 300)
Ejemplo n.º 12
0
    t.forward(peso)
    t.left(90)
    t.end_fill()            

A = list() # Cria uma lista vazia
for c in range(7):
    try:
        A.append(int(input('Digite um valor: ')))
    except:
        print('Erro encotrado. Só números inteiros podem ser inseridos.')

cor = list()        # Cria uma lista vazia
cor.append(str(input('Digite a cor da borda: '))) # Cria um elemento para a 1ª posição da lista
cor.append(str(input('Digite a cor do prenchimento: '))) # Cria um elemento para a 2ª posição da lista

tela = Screen()     # Mostra a janela e seus atributos
tela.bgcolor("lightgreen")

touche = Turtle()   # Cria a tartaruga 
touche.pensize(3)
touche.penup()
touche.backward(120)
touche.pendown()

try:
    touche.color(cor[0], cor[1])
except:
    print('Erro encontrado. Você não inseriu uma cor válida.')

for a in A:
    histograma(touche, a)
Ejemplo n.º 13
0
import turtle
from turtle import Turtle, Screen

my_turtle = Turtle()
my_win = Screen()


def draw_spiral(my_turtle, line_len):
    if line_len > 0:
        my_turtle.forward(line_len)
        my_turtle.right(90)
        draw_spiral(my_turtle, line_len - 5)


draw_spiral(my_turtle, line_len=100)
my_win.exitonclick()
Ejemplo n.º 14
0
 def start(self):
     for i in range(50000):
         for p in self.planets:
             p.step()
         if i % 10 == 0:
             Screen().update()
Ejemplo n.º 15
0
def main():
    """Main loop where all the game logic is handled.

        Args: None.

        Returns: None.
    """

    game_window = Screen()
    game_window.bgcolor("black")
    game_window.title("The Bouncy Space Ship Game")
    game_window.bgpic("background.gif")

    border = Border()
    game = Game()
    player1_score = Score(-290, 310, 1)
    player2_score = Score(190, 310, 2)

    border.draw_border()

    player1 = Player("blue")
    player2 = Player("purple")

    the_food = []  #List of Food objects.

    for _ in range(Food.amount):
        the_food.append(
            Food()
        )  #Spawning the food onto the screen and adding them to the food list.

    the_traps = []  #List of Trap objects.

    for _ in range(Traps.amount):
        the_traps.append(
            Traps()
        )  #Spawning the traps onto the screen and adding them to the food list.

    game_window.tracer(0)  #Turn automatic scren updates off for preformance.

    player1_score.change_score(0)  #Start the score at 0.
    player2_score.change_score(0)

    game_active1 = True
    game_active2 = True

    game_window.listen()
    game_window.onkey(
        player1.turnleft, "Left"
    )  #Turn the player's avatar left when the left button is pressed.
    game_window.onkey(player1.turnright, "Right")
    game_window.onkey(
        player1.increasespeed, "Up"
    )  #Increase the speed of the player's avatar when the up button is pressed.
    game_window.onkey(player1.decreasespeed, "Down")
    game_window.listen()
    game_window.onkey(player2.turnleft, "A")
    game_window.onkey(player2.turnright, "D")
    game_window.onkey(player2.increasespeed, "W")
    game_window.onkey(player2.decreasespeed, "S")
    game_window.onkey(player2.turnleft, "a")
    game_window.onkey(player2.turnright, "d")
    game_window.onkey(player2.increasespeed, "w")
    game_window.onkey(player2.decreasespeed, "s")

    while game_active1 or game_active2:

        game_window.update()  #Update the game window every loop.

        for food in the_food:
            food.move()  #Move the food.
            if player1 is not None and game.touch_checker(
                    player1, food
            ):  #If the player touches a food reset the food's position, play the eating sound, and update the score.
                food.regenerate()
                game.play_eating_sound()
                player1_score.change_score(10)
            if player2 is not None and game.touch_checker(player2, food):
                food.regenerate()
                game.play_eating_sound()
                player2_score.change_score(10)

        for trap in the_traps:
            trap.move()  #Move the trap.
            if player1 is not None and game.game_over(
                    player1, trap
            ):  #If a player's avatar hits a trap take it out of the game.
                game.play_game_over_sound()
                game_active1 = False
                player1.hideturtle()
                del player1
                player1 = None
            if player2 is not None and game.game_over(player2, trap):
                game.play_game_over_sound()
                game_active2 = False
                player2.hideturtle()
                del player2
                player2 = None

        if game_active1:
            player1.move()  #Move the player's avatar.
        if game_active2:
            player2.move()

        if not game_active1:  #End the game if player 1's avatar has a lower score than player 1 and it gets hit by a trap.
            if player1_score.score < player2_score.score:
                game_active2 = False

        if not game_active2:  #End the game if player 2's avatar has a lower score than player 2 and it gets hit by a trap.
            if player2_score.score < player1_score.score:
                game_active1 = False

    game.update_game_status(player1_score.score,
                            player2_score.score)  #Display the winner/ a draw.
    sleep(2.5)
Ejemplo n.º 16
0
from turtle import Turtle, Screen
from random import seed, randint

seed()

DELAY = 100  # milliseconds

# setup the output window
picSize = (400, 600)
playGround = Screen()
playGround.screensize(*picSize)

# setup the turtles
bob = Turtle(shape='turtle', visible=False)
bob.penup()
bob.color('red')
bob.speed('slow')

jeff = Turtle(shape='turtle', visible=False)
jeff.penup()
jeff.color('blue')
jeff.speed('normal')

x_quadrant = -picSize[0] // 2, picSize[0] // 2
y_quadrant = -picSize[1] // 2, picSize[1] // 2

# find random positions for the turtles
jeff_xy = randint(*x_quadrant), randint(*y_quadrant)
bob_xy = randint(*x_quadrant), randint(*y_quadrant)

# find a point to move bob to and rotate towards its target location
Ejemplo n.º 17
0
                if media < 9:
                    print("Notable")
                else:
                    if media >= 9:
                        print("Sobresaliente!")


Examen(2, 9)

#//////////////////////////////////////////

import turtle

from turtle import Screen, Turtle

pantalla = Screen()
pantalla.setup(425, 225)
pantalla.screensize(400, 200)

dibuja = Turtle()
dibuja.forward(100)
dibuja.write("A \n\n")
dibuja.forward(130)
dibuja.write("B \n\n")
dibuja.forward(140)
dibuja.write("C \n\n")
dibuja.forward(140)
dibuja.write("D \n\n")
dibuja.forward(140)

pantalla.exitonclick()
Ejemplo n.º 18
0
def main():
    # TODO 1: Configure screen
    screen = Screen()
    screen.setup(width=SCREEN_WIDTH, height=SCREEN_HEIGHT)
    screen.bgcolor(SCREEN_BACKGROUND_COLOR)
    screen.tracer(0)

    # Add borders
    border = Border()
    border.createBorder()

    # TODO 2: Configure initial snake
    snake = Snake()
    food = Food()
    scoreboard = Scoreboard()

    # TODO 3: Move the snake
    screen.listen()
    screen.onkey(snake.up, "Up")
    screen.onkey(snake.down, "Down")
    screen.onkey(snake.left, "Left")
    screen.onkey(snake.right, "Right")

    #global paused

    #def unpause():
    #    global paused
    #    paused = not paused

    #screen.onkey(unpause, "p")

    game_is_on = True
    while game_is_on:
        #while paused:
        #    sleep(0.2)
        screen.update()
        sleep(SLEEP_TIME)
        snake.move()

        # TODO 4: Detect collision with food
        snake_food_collision_distance = (
            food.width() + snake.head.width()) / 2 - COLLISION_ERROR
        if snake.head.distance(food) < snake_food_collision_distance:
            scoreboard.score += 1
            snake.add_segment()
            food.refresh()
            for segment in snake.tail:
                while segment.position() == food.position():
                    food.clear()
                    food.refresh()
            scoreboard.refresh()

        # TODO 5: Detect collision with walls
        pass_x_wall = (
            snake.head.xcor() < -SCREEN_WIDTH / 2 + snake.head.width()
            or snake.head.xcor() > SCREEN_WIDTH / 2 - snake.head.width())
        pass_y_wall = (
            snake.head.ycor() < -SCREEN_HEIGHT / 2 + snake.head.width()
            or snake.head.ycor() > SCREEN_HEIGHT / 2 - snake.head.width())
        wall_collision = pass_x_wall or pass_y_wall
        if wall_collision:
            scoreboard.resetHighestScore()
            snake.resetSnake()

        # TODO 6: Detect collision with tail
        tail_head_collision_distance = snake.head.width() - COLLISION_ERROR
        for segment in snake.tail[1:]:
            if segment.distance(snake.head) < tail_head_collision_distance:
                scoreboard.resetHighestScore()
                snake.resetSnake()

    screen.exitonclick()
Ejemplo n.º 19
0
from turtle import Turtle, Screen

timmy = Turtle()

timmy.shape('turtle')
timmy.color('coral')
timmy.forward(25)

myScreen = Screen()
print(myScreen.canvheight)
myScreen.exitonclick()
Ejemplo n.º 20
0
def plot_temp_vs_day(t_list):
    # # t_list = [t_year, t_ave]
    t = Turtle()
    wn = Screen()
    wn.tracer(0)
    # t.speed(100)
    t.ht()
    
    # Setting grid coordinates
    x_max = len(t_list[1])
    x_min = 0
    y_max = int(max(t_list[1]))
    y_min = 0
    if min(t_list[1]) < 0: y_min = int(min(t_list[1]) - 10)
    
    # Grid Scales
    x_scl = 20
    y_scl = 20
    
    wn.setworldcoordinates(x_min - 20, y_min - 20, x_max + 20, y_max + 20)
    
    # Draw axis 
    axis = [[x_min, y_min],[x_max, y_min],[0.0, y_min],[0.0, y_max]]
    for i in range(0, 4, 2):
        t.up()
        t.goto(axis[i][0],axis[0][1]) # Origin x,y (0,2) 
        t.down()
        t.goto(axis[i + 1][0], axis[i + 1][1]) # highest point x,y (0,2)
        t.up()
        
    # Draw lines
    
    # x-lines
    t.up()
    t.goto(x_min, y_min) #goes to origin 
    for i in range(x_max//x_scl):
        t.up()
        t.forward(x_scl)
        t.left(90)
        t.forward(1)
        t.down()
        t.forward(-2)
        t.up()
        t.forward(-4)
        t.write(str(i * x_scl), font=("Arial", 14, "normal"))
        t.forward(5)
        t.right(90)
        
    # y-lines
    t.up()
    t.goto(x_min, y_min) #goes to origin 
    t.left(90)
    for i in range(y_max//y_scl):
        t.up()
        t.forward(y_scl)
        t.left(90)
        t.forward(1)
        t.forward(8)
        t.write(str(i * x_scl), font=("Arial", 14, "normal"))
        t.forward(-8)
        t.down()
        t.forward(-2)
        t.up()
        t.forward(1)
        t.right(90)    
    
    t.up()
    # Draw the graph 
    t.color('blue')
    t.goto(x_min, y_min)
    t.down()
    for i in range(len(t_list[1])):
        if t_list[1][i] != -99: 
            # t.up()
            t.goto(i, t_list[1][i])
            t.down()
            t.dot()

    t.up()
    # Draw the graph
    t.color('green')
    t.goto(x_min, y_min)
    t.down()
    for i in range(len(t_list[0])):
        if t_list[0][i] != -99:
            #t.up()
            t.goto(i * 2.8969, t_list[0][i])
            t.down()
            t.dot()
    wn.update()
    wn.exitonclick()
Ejemplo n.º 21
0
    "replacementRules": {
        "F": "FF+[+F-F-F]-[-F+F+F]"
    },
    "depth": 3,
    "step": 13.5,
    "angle": 180.0 / 8,
    "startpos": (90, -192),
    "startdir": 90,
}


def main():
    l1 = lindenmayer(LPen(), **herb)
    l2 = lindenmayer(LPen(), **bush)
    done = 0
    while done < 2:
        done = 0
        for l in l1, l2:
            try:
                next(l)
            except StopIteration:
                done += 1
    Screen().tracer(True)
    return "Done!"


if __name__ == '__main__':
    msg = main()
    print(msg)
    Screen().mainloop()
Ejemplo n.º 22
0
Archivo: main.py Proyecto: sjk39/pong
from turtle import Screen
from scoreboard import Scoreboard
from ball import Ball
from pitch import Pitch
from paddle import Paddle
import time

sc = Screen()
sc.setup(width=1000, height=600)
p = Pitch()
sc.bgcolor("black")
sc.title("Pong")
sc.listen()
paddle_one = Paddle()
paddle_one.position(1)
paddle_two = Paddle()
paddle_two.position(2)
ball = Ball()
scoreboard = Scoreboard()
sc.onkey(paddle_one.up, "Up")
sc.onkey(paddle_one.down, "Down")

game_on = True
while game_on:
    sc.update()
    #time.sleep(0.001)

    if ball.distance(paddle_one.pos()) < 40 or ball.distance(
            paddle_two.pos()) < 40:
        ball.move(1)
        #prevents ball getting 'stuck' to paddle
Ejemplo n.º 23
0
from turtle import Screen, Turtle
from yilan import Yilan
from yiyecek import Yiyecek
from skortahtasi import SkorTahtasi
import time

ekran = Screen()
ekran.setup(width=600, height=600)
ekran.bgcolor("black")

yilan = Yilan()

yemek = Yiyecek()
skorTahtasi = SkorTahtasi()

ekran.listen()
'''
ekran.onkey(yilan.sol, "Left")
ekran.onkey(yilan.sag, "Right")
ekran.onkey(yilan.yukari, "Up")
ekran.onkey(yilan.asagi, "Down")
'''
ekran.onkey(yilan.sol, "a")
ekran.onkey(yilan.sag, "d")
ekran.onkey(yilan.yukari, "w")
ekran.onkey(yilan.asagi, "s")

while True:
    yilan.hareket_et()
    time.sleep(0.1)
Ejemplo n.º 24
0
 def __init__(self):
     self.screen = Screen()
     self.screen.bgcolor('black')
     self.screen.tracer(0)
Ejemplo n.º 25
0
from turtle import Turtle, Screen, colormode
from random import choice, randint

kags = Turtle()
print(kags)
kags.shape("turtle")
kags.color("blue", "yellow")
kags.forward(100)
kags.right(90)
kags.forward(100)
kags.right(90)
kags.forward(100)
kags.right(90)
kags.forward(100)

my_screen = Screen()
print(my_screen.canvheight)
my_screen.exitonclick()

turtle = Turtle()
colormode(255)

colors = [
    "red", "SeaGreen", "wheat", "yellow", "black", "purple", "IndianRed",
    "DeepSkyBlue", "SlateGray"
]
directions = [0, 90, 180, 270]

for _ in range(200):
    turtle.shape("turtle")
    turtle.width(10)
Ejemplo n.º 26
0
# Module importieren
from turtle import Screen, Turtle
from time import sleep

# Bildschirm festlegen
bildschirm = Screen()

# Schildkröte festlegen
fred = Turtle()

# Dauerschleife
while True:
    # Nutzer nach der Farbe fragen
    farbe = input("Farbe: ")

    # Hintergrundfarbe verändern
    bildschirm.bgcolor(farbe)

    # 1 Sekunde warten
    sleep(1)
Ejemplo n.º 27
0

class SpaceShip(GameItem):
    "This class defines a Space Ship and its properties"

    # Constructor
    def __init__(self, param_color="White"):
        Turtle.__init__(self)
        #self.color(param_color)

    #pass
    #self.shape("Triangle")


### MAIN ###
window = Screen()
window.setup(0.5, 0.75, 0, 0)
window.screensize(WINSIZE_WIDTH, WINSIZE_HEIGHT, "White")
window.setworldcoordinates(0, 0, WINSIZE_WIDTH, WINSIZE_HEIGHT)
window.title("Chasers")

spaceShip = SpaceShip()

window.onkeypress(spaceShip.turnLeft, "Left")
window.onkeypress(spaceShip.turnRight, "Right")
window.onkeypress(spaceShip.increaseSpeed, "Up")
window.onkeypress(spaceShip.decreaseSpeed, "Down")
window.listen()

spaceShip.setpos(GAMEMARGIN_WIDTH, GAMESIZE_HEIGHT)
while True:
Ejemplo n.º 28
0
from turtle import Screen, Turtle
from random import randint, choice
import turtle
import time
s=Screen()
s.bgcolor("white")
track = Turtle()

# # track = turtle.Turtle()
track.speed('fastest')
track.penup()
track.goto(-100, 200)
for step in range(15):
    track.write(step, align='center')
    track.right(90)
    track.forward(10)
    track.pendown()
    track.forward(160)
    track.penup()
    track.backward(170)
    track.left(90)
    track.forward(20)


track.goto(200, 250)
track.write("Finish Line", align='center')
track.pendown()
track.right(90)
track.forward(300)

Ejemplo n.º 29
0
from turtle import Turtle, Screen

tim = Turtle()
screen = Screen()


def move_forward():
    tim.forward(10)


def turn_right():
    tim.right(5)


def turn_left():
    tim.right(5)


screen.listen()
screen.onkey(key="space", fun=move_forward)
screen.onkey(key="Right", fun=turn_right)
screen.onkey(key="Left", fun=turn_left)
screen.exitonclick()
Ejemplo n.º 30
0
from turtle import Turtle, Screen
from paddle import Paddle
from scoreboard import Scoreboard
import ball
import time

# TODO Background
BACKGROUND_WIDTH = 800
BACKGROUND_HEIGHT = 600
background = Screen()
background.title("My Pong Game")
background.setup(width=BACKGROUND_WIDTH, height=BACKGROUND_HEIGHT)
background.bgcolor("black")
background.tracer(0)

# TODO dashed-line in the middle
dashed_midline = Turtle()
dashed_midline.penup()
dashed_midline.color("white")
dashed_midline.speed("fastest")
dashed_midline.hideturtle()
dashed_midline.goto(0, -300)
dashed_midline.setheading(90)

number_of_dashes = 30
dash_length = 10
gap_length = 10
for _ in range(number_of_dashes):
    background.update()
    dashed_midline.pendown()
    dashed_midline.forward(dash_length)