コード例 #1
0
def main():
    global screen
    screen = Screen()
    screen.colormode(255)
    p = Turtle()
    p.ht()
    screen.tracer(75,0)
    u = doit1(6, Turtle(undobuffersize=1))
    s = doit2(7, Turtle(undobuffersize=1))
    t = doit3(5, Turtle(undobuffersize=1))
    v = doit4(6, Turtle(undobuffersize=1))
    w = doit5(5, Turtle(undobuffersize=1))
    a = clock()
    while True:
        done = 0
        for b in u,s,t,v,w:
            try:
                b.next()
            except:
                done += 1
        if done == 5:
            break

    screen.tracer(1,10)
    b = clock()
    return "done: %.2f sec." % (b-a)
コード例 #2
0
ファイル: main.py プロジェクト: serat1/31-days-of-code
def create_screen():
    screen = Screen()
    screen.setup(width=900, height=600)
    screen.title("NATO Phonetic Alphabet")
    screen.bgcolor('black')
    screen.colormode(255)
    return screen
コード例 #3
0
def dot_painting():
    t = Turtle()
    s = Screen()
    s.colormode(255)
    t.speed(10)
    t.hideturtle()
    t.penup()
    t.goto(-500, -300)
    k = -200
    color_rgb_list = [(232, 238, 246), (247, 239, 242), (239, 246, 243),
                      (131, 165, 205), (221, 149, 108), (30, 41, 62),
                      (202, 133, 145), (166, 58, 47), (141, 184, 161),
                      (236, 213, 93), (40, 104, 155), (152, 58, 66),
                      (217, 81, 70), (236, 164, 156), (51, 112, 91),
                      (171, 29, 33), (33, 61, 55), (52, 44, 49), (157, 33, 30),
                      (231, 161, 166), (170, 188, 221), (18, 96, 70),
                      (57, 51, 48), (189, 99, 109), (30, 60, 111),
                      (106, 126, 159), (175, 200, 188), (33, 151, 210),
                      (65, 66, 57)]
    for _ in range(7):
        for _ in range(20):
            t.dot(20, random.choice(color_rgb_list))
            t.penup()
            t.forward(50)
            t.pendown()
        t.penup()
        t.goto(-500, k)
        k += 100
    s.exitonclick()
コード例 #4
0
def main():
    global screen
    screen = Screen()
    screen.colormode(255)
    p = Turtle()
    p.ht()
    screen.tracer(75,0)
    u = doit1(6, Turtle(undobuffersize=1))
    s = doit2(7, Turtle(undobuffersize=1))
    t = doit3(5, Turtle(undobuffersize=1))
    v = doit4(6, Turtle(undobuffersize=1))
    w = doit5(5, Turtle(undobuffersize=1))
    a = clock()
    while True:
        done = 0
        for b in u,s,t,v,w:
            try:
                next(b)
            except:
                done += 1
        if done == 5:
            break

    screen.tracer(1,10)
    b = clock()
    return "runtime: {0:.2f} sec.".format(b-a)
コード例 #5
0
def main():
    screen = Screen()
    screen.setup(width=WINDOW_WIDTH, height=WINDOW_HEIGHT)
    screen.tracer(0)
    draw_safe_zones()
    new_player = Player()
    level = Scoreboard((-(WINDOW_WIDTH / 2 - 80), WINDOW_HEIGHT / 2 - 40))
    car_man = CarManager((WINDOW_WIDTH, WINDOW_HEIGHT))
    screen.onkey(new_player.move, "Up")
    screen.onkey(screen.bye, "Escape")
    screen.colormode(255)
    screen.bgcolor((99, 98, 99))

    game_is_on = True
    while game_is_on:
        screen.listen()
        screen.update()
        time.sleep(0.1)
        car_man.move(level.get_level())
        if new_player.safe():
            new_player.restart()
            level.update_score()

        if car_man.check_collision(new_player):
            level.game_over()
            game_is_on = False

        if randint(0, 3) == 2:
            car_man.add_car()

    screen.exitonclick()
コード例 #6
0
def pong():
    ball_speed = 5
    screen = Screen()
    screen.colormode(255)
    screen.setup(width=800, height=600)
    screen.bgcolor("#282846")
    screen.title("Awesome Pong Game")
    screen.tracer(0)

    player = Paddles(PADDLE_PLAYER_START)
    ajax = Paddles(PADDLE_AJAX_START)
    ball = Balls()

    scoreboard = Scoreboard()
    scoreboard.add_line()

    player_score = Scoreboard(cords=PCORDS)
    ajax_score = Scoreboard(cords=MCORDS)
    player_score.add_score()
    ajax_score.add_score()

    screen.listen()
    screen.onkey(player.go_up, key='w')
    screen.onkey(player.go_down, key='s')
    screen.onkey(ajax.go_up, key='Up')
    screen.onkey(ajax.go_down, key='Down')

    def point_and_restart():
        ball.goto(0, 0)
        player.goto(PADDLE_PLAYER_START)
        ajax.goto(PADDLE_AJAX_START)
        time.sleep(2)

    game_is_on = True
    while game_is_on:
        screen.update()
        ball.move(ball_speed)

        # Wall Bouncing
        if ball.ycor() > 280 or ball.ycor() < -280:
            ball.bounce()

        # Sum Point and restart the game
        if ball.xcor() > 390:
            player_score.update_score()
            point_and_restart()
            ball.setheading(randint(100, 230))
            ball_speed += 1
        elif ball.xcor() < -390:
            ajax_score.update_score()
            point_and_restart()
            ball.setheading(randint(0, 45))
            ball_speed += 0.5

        # Detect collision with the paddle
        if ball.distance(player) < 51 and ball.xcor() < -350 or ball.distance(ajax) < 51 and ball.xcor() > 350:
            ball.hit_bounce()


    screen.exitonclick()
コード例 #7
0
def create_new_screen(width, height, bgcolor):
    scr = Screen()
    scr.clear()
    scr.title('Turtle Race...!!')
    scr.setup(width=width, height=height)
    scr.colormode(255)
    scr.bgcolor(bgcolor)
    return scr
コード例 #8
0
ファイル: screen.py プロジェクト: SadSack963/day-20-Snake
class ScreenSetup:
    def __init__(self):
        self.s = Screen()
        self.s.colormode(255)
        self.s.bgcolor("black")
        self.s.setup(width=SCREEN_WIDTH, height=SCREEN_HEIGHT)
        self.s.title("Snake")
        self.s.tracer(0)  # Turn off screen animation
        self.s.listen()  # listen for keystrokes
コード例 #9
0
ファイル: main.py プロジェクト: sedje/100DaysOfPython
def main():
    timmy = Turtle()
    screen = Screen()
    screen.colormode(255)
    timmy.shape("turtle")
    timmy.color("green")
    timmy.speed(100)
    draw_circles(timmy)
    screen.exitonclick()
コード例 #10
0
def spirograph():
    screen = Screen()
    screen.title("Lets Draw Spirograph!")
    screen.colormode(255)
    line = Turtle()
    line.speed(0)
    for angle in range(0, 360, 5):
        draw_circle(line, angle)
    screen.exitonclick()
コード例 #11
0
 def new_screen(self):
     screen = Screen()
     screen.colormode(255)
     screen.setup(width=800, height=600)
     screen.bgcolor("#282846")
     screen.title("Awesome Pong Game")
     screen.tracer(0)
     draw_line()
     screen.exitonclick()
コード例 #12
0
def setup_screen(screen: turtle.Screen) -> None:
    screen.setup(SCREEN_WIDTH, SCREEN_HEIGHT)
    screen.colormode(255)
    screen.title("Blitz crossing")
    screen.onkeypress(lambda: player.sety(player.ycor() + 10), "Up")
    screen.onkeypress(lambda: player.sety(player.ycor() - 10), "Down")
    screen.onkeypress(lambda: player.setx(player.xcor() + 10), "Right")
    screen.onkeypress(lambda: player.setx(player.xcor() - 10), "Left")
    screen.tracer(0)
    screen.listen()
コード例 #13
0
def main():
    app = Screen()
    app.colormode(255)

    pen = create_pen('classic', 'black', 'fast')
    pen.hideturtle()

    draw_art(pen)

    app.mainloop()
コード例 #14
0
class Game():
    """Make the game loop into a class.
    Responsible for drawing and updating all our objects"""
    def __init__(self):
        # Set up the screen
        self.screen = Screen()
        self.screen.bgcolor("green")
        self.screen.setup(width=800, height=600)
        self.screen.title("Pong Game")
        # accelerate time program
        self.screen.tracer(0)
        self.screen.colormode(255)

        # initial objects
        self.paddle_left = Paddle(-350)
        self.paddle_right = Paddle(350)
        self.score = Score()
        self.ball = Ball(0.5, 0.5)

        # Create keyboard bindings
        self.screen.listen()
        self.screen.onkeypress(self.paddle_left.go_up, "w")
        self.screen.onkeypress(self.paddle_left.go_down, "s")
        self.screen.onkeypress(self.paddle_right.go_up, "Up")
        self.screen.onkeypress(self.paddle_right.go_down, "Down")

    def run(self):
        """Make the game loop a function."""

        while True:
            # move the ball
            self.ball.move()

            # checking the left border
            if self.ball.xcor() < -390:
                # add score for player A
                self.score.add_score(0, 1)

            # checking the right border
            if self.ball.xcor() > 390:
                # add score for player B
                self.score.add_score(1, 0)

            self.ball.check_collision()

            # checking collision between ball and left paddle
            if is_collision(self.paddle_left, self.ball):
                self.ball.bounce_off()

            # checking collision between ball and right paddle
            if is_collision(self.paddle_right, self.ball):
                self.ball.bounce_off()

            # Display the screen.
            self.screen.update()
コード例 #15
0
def main():
    t = Turtle()
    s = Screen()
    s.colormode(255)
    s.bgcolor((76, 237, 87))
    t.color((122, 59, 71))

    s.listen()
    s.onkey(lambda: left(t), 'Left')
    s.onkey(lambda: right(t), 'Right')
    s.onkeypress(lambda: up(t), 'Up')

    s.mainloop()
コード例 #16
0
def start():
    picture = input("Picture: ")
    screen = Screen()
    filename = picture
    screen.colormode(255)
    img = Image.open(filename)
    width, height = img.size
    rgb_img = img.convert('RGB')
    t.speed(0)

    offset_x = -(width/2)
    offset_y =(height/2)

    drawing(width, height, rgb_img, offset_x, offset_y)
コード例 #17
0
ファイル: polygons.py プロジェクト: charlesjhall/lectures
def main() -> int:
    yertle = Turtle()
    screen = Screen()
    yertle.speed(2000)
    screen.colormode(255)
    yertle.color("blue")
    yertle.up()
    square(yertle, 300)
    hexagon(yertle, 100)
    octagon(yertle, 80)
    triangle(yertle, 300)
    regular_polygon(yertle, 5, 100)
    yertle.down()
    radial_pattern(yertle, 299, 100, octagon)
    screen.exitonclick()
コード例 #18
0
 def blank_image(self, l=None, w=None, bg=None, mode=None):
     if l is None:
         l = self.length
     if w is None:
         w = self.width
     if bg is None:
         bg = self.bg
     if mode is None:
         mode = self.mode
     screen = Screen()
     screen.setup(width=l, height=w, startx=0, starty=0)
     screen.screensize(l, w)
     screen.bgcolor(*bg)
     screen.colormode(mode)
     screen.delay(0)
     return screen
コード例 #19
0
def main():
    screen = Screen()
    screen.setup(width=600, height=600)
    screen.colormode(255)
    screen.bgcolor("#282846")
    screen.title("Rapid and Furious Snake Game")
    screen.tracer(0)

    snake = Snake()
    food = Food()
    scoreboard = Scoreboard()

    screen.listen()
    screen.onkey(snake.up, key='Up')
    screen.onkey(snake.down, key='Down')
    screen.onkey(snake.right, key='Right')
    screen.onkey(snake.left, key='Left')
    # screen.onkey(main, key='Enter')

    game_is_on = True
    while game_is_on:
        screen.update()
        time.sleep(0.1)

        snake.snake_moves()

        # Detect the collision between the snake and food:
        if snake.head.distance(food) < 15:
            food.refresh()
            snake.extend()
            scoreboard.track_score()

        # Detect the collision with the wall
        if snake.head.xcor() > 297 or snake.head.xcor() < -297 \
                or snake.head.ycor() > 297 or snake.head.ycor() < -297:
            scoreboard.game_over()
            scoreboard.reset_scoreboard()
            snake.reset_snake()

        # Detect collision with the tail
        for segment in snake.squares[1:]:
            if snake.head.distance(segment) < 10:
                scoreboard.game_over()
                scoreboard.reset_scoreboard()
                snake.reset_snake()

    screen.exitonclick()
コード例 #20
0
ファイル: window.py プロジェクト: alexpdev/Games
class Window:
    def __init__(self, w=.9, h=.9, x=0, y=0):
        self.screen = Screen()
        self.screen.setup(w, h, x, y)
        self.screen.bgcolor("wheat")
        self.screen.colormode(255)
        self.screen_width = (((self.screen.window_width()) * .98) // 12) * 12
        self.screen_height = (((self.screen.window_height()) * .95) // 12) * 12
        self.width = self.screen_width / 2
        self.height = self.screen_height / 2

    def pen(self):
        turt = RawTurtle(self.screen)
        turt.ht()
        turt.speed(0)
        turt.up()
        turt.goto(-self.width, self.height)
        turt.down()
        return turt
コード例 #21
0
def turtles():
    timmy = Turtle()
    screen = Screen()
    screen.colormode(255)
    timmy.shape("turtle")
    timmy.color("green")
    timmy.speed(100)
    new_position(timmy, -200, 200)
    dotted_line(timmy, 15)
    new_position(timmy, -200, 180)
    draw_shape(timmy, 4)
    new_position(timmy, -90, 180)
    draw_spiro(timmy)
    new_position(timmy, 50, 50)
    draw_multiple(timmy)
    # random_walk(timmy, 200)
    new_position(timmy, -250, -150)
    draw_full_spiro(timmy, 20)
    screen.exitonclick()
コード例 #22
0
def main():
    screen = Screen()
    screen.setup(width=600, height=600)
    screen.bgcolor('black')
    screen.tracer(0)
    screen.title('Turtle Crossing')
    screen.colormode(255)

    scoreboard = Scoreboard()

    player = Player()
    car_manager = CarManager()

    screen.listen()
    screen.onkey(player.move_up, 'Up')
    screen.onkey(player.move_down, 'Down')
    screen.onkey(player.move_left, 'Left')
    screen.onkey(player.move_right, 'Right')

    game_is_on = True
    while game_is_on:
        time.sleep(0.1)
        screen.update()
        car_manager.create_car()
        car_manager.move_cars()
        for car in car_manager.all_cars:
            if car.distance(player) < 25:
                game_is_on = False
                scoreboard.game_over()
                play_again = screen.textinput(
                    title="You lost bitch",
                    prompt='Would you like to play again?').lower()
                if play_again[0] == 'y':
                    screen.clear()
                    main()
                else:
                    screen.bye()
        if player.ycor() > 280:
            scoreboard.increase_level()
            player.player_reset()

    screen.exitonclick()
コード例 #23
0
def game(lvl):
    # Screen Setup
    screen = Screen()
    screen.setup(width=600, height=600)
    screen.tracer(0)
    screen.colormode(255)

    # Turtle Setup
    player = Player()

    # Scoreboard Setup
    scoreboard = Scoreboard(lvl)

    # Car Manager Setup
    car_manager = CarManager(lvl)

    # Control listeners
    screen.listen()
    screen.onkeypress(fun=player.move_up, key="Up")
    screen.onkeypress(fun=player.move_down, key="Down")
    screen.onkeypress(fun=player.move_left, key="Left")
    screen.onkeypress(fun=player.move_right, key="Right")

    # Main Game Loop
    is_game = True
    while is_game:
        screen.update()
        time.sleep(0.1)
        car_manager.move_cars()

        if player.ycor() > 290:
            screen.clear()
            lvl += 2
            game(lvl)

        for car in car_manager.cars_list:
            if player.distance(car) < 20:
                scoreboard.game_over()
                is_game = False

    screen.exitonclick()
コード例 #24
0
ファイル: TSP.py プロジェクト: elespantosoterry/IA-2020-I
def graficar(poblacion):
    pantalla = Screen()
    tortuga = Turtle()
    pantalla.setup(600,600)
    tortuga.penup()
    pantalla.colormode(1)
    for i in range(0, len(poblacion),20):
        pantalla.tracer(0)
        ciudades = poblacion[i].getCiudades()    
        tortuga.pencolor((random(), random(), random()))
        for cdd in ciudades:
            x = cdd.getX()
            y = cdd.getY()
            tortuga.goto(x,y)
            tortuga.pendown()
            tortuga.dot(5)
        tortuga.goto(ciudades[0].getX(), ciudades[0].getY())
        tortuga.penup()    
        pantalla.update()
        sleep(.500)

    ciudades = poblacion[0].getCiudades()
    tortuga.pensize(2)
    tortuga.color("black")
    tortuga.pendown()
    for cdd in ciudades:
        x = cdd.getX()
        y = cdd.getY()
        tortuga.goto(x,y)
        tortuga.pendown()
        tortuga.color("black")
        tortuga.dot(5)
        tortuga.color("black")
    pantalla.update()
    sleep(.500)
   
    
    pantalla.exitonclick()
コード例 #25
0
def draw_graph(gr, screen):
    screen = Screen()
    screen.bgcolor("black")
    screen.delay(0)
    screen.colormode(255)
    topological_ordered = list(
        reversed(list(nx.algorithms.topological_sort(gr))))
    for node in topological_ordered:
        data = node.data
        try:
            color = node.attrs['color']
        except KeyError:
            color = (255, 0, 0)
        pen = Turtle()
        pen.hideturtle()
        pen.penup()
        pen.pencolor(*color)
        points = to_tups(data)
        pen.goto(*(points[0]))
        pen.pendown()
        for point in points[::-1]:
            pen.goto(*point)
            # print(color,point)
    screen.mainloop()
コード例 #26
0
import colorgram
import random
from turtle import Turtle, Screen
from colorgram import colorgram
timmy = Turtle()
sc = Screen()
# col=colorgram.extract("paint.jpg",30)
# rgb=[]
# for i in col:
#     r=i.rgb.r
#     g=i.rgb.g
#     b=i.rgb.b
#     rgb.append((r,g,b))
sc.colormode(255)
timmy.speed(20)
col = [(132, 166, 205), (221, 148, 106), (32, 42, 61), (199, 135, 148),
       (166, 58, 48), (141, 184, 162), (39, 105, 157), (237, 212, 90),
       (150, 59, 66), (216, 82, 71), (168, 29, 33), (235, 165, 157),
       (51, 111, 90), (35, 61, 55), (156, 33, 31), (17, 97, 71), (52, 44, 49),
       (230, 161, 166), (170, 188, 221), (57, 51, 48), (184, 103, 113),
       (32, 60, 109), (105, 126, 159), (175, 200, 188), (34, 151, 210),
       (65, 66, 56)]
timmy.setheading(225)
timmy.up()
timmy.hideturtle()
timmy.forward(300)
timmy.setheading(0)
for i in range(1, 11):
    j = 1

    while (j <= 10):
コード例 #27
0
STARTING_LENGTH = 100
LENGTH_INCREMENT = 5

N = 6


def draw_polygon(turtle, size):
    angle = 360 / N
    for _ in range(N):
        turtle.forward(size)
        turtle.left(angle)


screen = Screen()
screen.colormode(255)

mega = Turtle()
mega.speed('fastest')

length = STARTING_LENGTH

for r in range(COUNT):

    red = round(r * ((MAX_COLOR - MIN_COLOR) / (COUNT - 1))) + MIN_COLOR

    color = (red, 0, 0)

    mega.fillcolor(color)
    mega.begin_fill()
    draw_polygon(mega, length)
コード例 #28
0
CAOS = 1
RELACION = 1.3

DISTANCE = 150
ANGLE_ALPHA = 24
ANGLE_BETHA = 24

#CONDICIONES INICIALES

pen = Turtle()  #Le ponemos nombre a nuestra tortuga
screen = Screen(
)  #Esta condicion es necesaria para la grama cromatica en las hojas
random.seed()  #Inicializamos el generador de numeros aleatorios

screen.colormode(
    255
)  #Esta condicion es necesaria para poder pasarle a la gama cromatica los colores RGB

#Posicion inicial
pen.penup()
pen.goto(0, -375)
pen.pendown()
pen.left(90)
pen.speed(10)

#Color inicial
#random.uniform(a, b) nos devuelve un valor entre a y b
#pen.pencolor recibe 3 parametros de los tres intervalos. Este conjunto de intervalos dos cambia a una gama cromatica marron
#pen.pencolor(int(random.uniform(60, 80)), int(random.uniform(30, 50)),int(random.uniform(10, 30)))
pen.pencolor(int(random.uniform(50, 80)), int(random.uniform(20, 50)),
             int(random.uniform(20, 50)))
コード例 #29
0
from turtle import Turtle, Screen

rabbit = Turtle()

print(rabbit)

rabbit.shape("turtle")
my_screen = Screen()
my_screen.colormode()

rabbit.color(0, 0.5, 0)

print(my_screen.canvheight)
my_screen.exitonclick()
コード例 #30
0
ファイル: pretty_circles.py プロジェクト: minedetector/geeks
from turtle import Turtle, Screen
t = Turtle()
s = Screen()
n = 200
s.colormode(255)
t.speed(0)
s.delay(0)

for i in range(0, 256):
    t.color(i, 0, 0)
    t.circle(n)
    t.right(90)

    n -= 1

s.exitonclick()
コード例 #31
0
from turtle import Turtle, Screen
import random

screen = Screen()
screen.setup(width=500, height=400)
screen.colormode(1)

is_racing = False

user_bet = screen.textinput(
    title="Make Your Bets!",
    prompt="Which turtle will win the race? Enter a color: ")

colors = ["red", "orange", "yellow", "green", "blue", "purple"]
y_pos = [-75, -45, -15, 15, 45, 75]
turtles = []

for i in range(6):
    turtle = Turtle(shape="turtle")
    turtle.color(colors[i])
    turtle.pu()
    turtle.goto(x=-230, y=y_pos[i])
    turtles.append(turtle)

if user_bet:
    is_racing = True

while is_racing:
    for turtle in turtles:
        if turtle.xcor() > 230:
            winner = turtle.pencolor()