Esempio n. 1
0
def test_single_layer():
    turtle.setundobuffer(None)
    turtle.bgcolor(tree.SKY_COLOR)
    turtle.up()
    turtle.left(90)
    turtle.backward(200)

    draw_layer(generate_random_layer(10), 1, 2000, 4)

    turtle.done()
Esempio n. 2
0
File: main.py Progetto: nreis11/tron
 def __init__(self, testing=False):
     turtle.setundobuffer(None)
     turtle.tracer(0)
     self.testing = testing
     self.window_width, self.window_height = (1.0, 1.0)
     self.screen_idx = 0
     self.screens = [main_screen, options_screen, controls_screen]
     self.screen = turtle.Screen()
     self.init_screen()
     self.audio = Sound()
     self.create_cursor()
     self.display_controller()
     self.humans = 1
     self.state = self.MENU
Esempio n. 3
0
def setup():
    # Save some memory
    turtle.setundobuffer(None)
    # Create the window
    turtle.setup(WINDOW_LENGTH, WINDOW_HEIGHT)
    # Hide the default turtle
    turtle.hideturtle()
    # Change the background color
    screen.bgcolor("white")
    # Set the window title
    screen.title("Fruit Catcher")
    # Turn on manuel draw mode for more control
    screen.tracer(False)
    # Remove the window borders
    canvas.config(borderwidth=0, highlightthickness=0)
Esempio n. 4
0
    def __init__(self, linesize=3, color=(0.2, 0.3, 0.5), canvas=None) -> None:
        self.default_linesize = linesize

        if canvas:  # if an existing tkinter canvas is provided, use it
            turtle.RawTurtle(canvas)

        turtle.pensize(linesize)
        turtle.pencolor(*color)
        turtle.title('TurtlePro')
        turtle.hideturtle()
        turtle.speed(0)  # fastest speed
        turtle.setundobuffer(None)  # disable undobuffer to improve performance

        self.max_dist_from_center = 0
        self.pan_and_zoomable()
 def __init__(self, width, height, title):
     self.width = width
     self.height = height
     self.title = title
     self.simulation_running = False
     self.tick = None  # function to call for each animation cycle
     self.delay = 1  # smallest delay is 1 millisecond
     turtle.title(title)  # title for the window
     turtle.setup(width, height)  # set window display
     turtle.hideturtle()  # prevent turtle appearance
     turtle.tracer(0, 0)  # prevent turtle animation
     turtle.listen()  # set window focus to the turtle window
     turtle.mode('logo')  # set 0 direction as straight up
     turtle.penup()  # don't draw anything
     turtle.setundobuffer(None)
     self.__animation_loop()
Esempio n. 6
0
    def __init__(self, plotter_enabled=False):
        self.set_canvas_size(100, 100)

        self.plot_size = 4
        self.plotter_enabled = plotter_enabled

        self.clipping = True
        self.cull_empty_at_edges = True

        self._reset_plot_state()
        self._real_pos = self.DEFAULT_POS

        self.ad = None
        self.options = dotdict()

        t.hideturtle()
        t.tracer(1000, 0)
        t.setundobuffer(None)
Esempio n. 7
0
def test_many_layers():
    turtle.setundobuffer(None)
    turtle.hideturtle()
    turtle.bgcolor(tree.SKY_COLOR)
    turtle.up()
    turtle.left(90)
    turtle.forward(200)

    # Draw five trees at five different distances
    for i in range(30, 101, 10):
        percent = i / 100
        detail = int(6 * percent) + 2

        draw_layer(generate_random_layer(200), percent**2, 1700, detail)
        turtle.goto(0, turtle.ycor() - (percent**2 * 200))

    print("Complete")
    turtle.done()
Esempio n. 8
0
def main():
    t.setundobuffer(10)
    # use number input method of turtle
    ch = t.numinput(
        "Number of players",
        "How many players will play Hangman - one or two. Please enter 1 or 2: ",
        1, 1, 2)
    print()
    if ch == 1:
        # use write method of turtle
        t.penup()
        t.setpos(x, y + 60)
        t.write(
            "OK. Here are the blanks for the letters of the word that the computer chose from dictionary.",
            True,
            align="left",
            font=("Arial", 10, "normal"))
        words = open("3000words.csv", "r")
        L = words.read()
        WL = list(L.split(","))
        words.close()
        onePlayer(WL)
    elif ch == 2:
        # use text input method of turtle
        Word = t.textinput("Word for the game",
                           "Player1 please enter the word for the game")
        twoPlayers(Word)
    else:
        # use write method of turtle
        t.penup()
        t.setpos(x, y + 20)
        t.pencolor("red")  # changing pen colors of turtle
        t.hideturtle()
        t.write("Invalid entry.",
                True,
                align="left",
                font=("Arial", 10, "normal"))
        time.sleep(1)
        t.undo()  # turtle function for undoing last action
        t.pencolor("black")  # changing pen colors of turtle
        choice()
Esempio n. 9
0
    def __init__(
                self,
                screen_width = 800,
                screen_height = 600,
                background_color = "black",
                title = "Simple Game Library by /u/wynand1004 AKA @TokyoEdTech",
                splash_time = 3):

        # Setup using Turtle module methods
        turtle.setup(width=screen_width, height=screen_height)
        turtle.bgcolor(background_color)
        turtle.title(title)
        turtle.tracer(0) # Stop automatic screen refresh
        turtle.listen() # Listen for keyboard input
        turtle.hideturtle() # Hides default turtle
        turtle.penup() # Puts pen up for defaut turtle
        turtle.setundobuffer(0) # Do not keep turtle history in memory
        turtle.onscreenclick(self.click)

        # Game Attributes
        self.FPS = 30.0 # Lower this on slower computers or with large number of sprites
        self.SCREEN_WIDTH = screen_width
        self.SCREEN_HEIGHT = screen_height
        self.DATAFILE = "game.dat"
        self.SPLASHFILE = "splash.gif" # Must be in the same folder as game file

        self.title = title
        self.gravity = 0
        self.state = "showsplash"
        self.splash_time = splash_time

        self.time = time.time()

        # Clear the terminal and print the game title
        self.clear_terminal_screen()
        print (self.title)

        # Show splash
        self.show_splash(self.splash_time)
Esempio n. 10
0
def face( marks=tick_lines ):
    """Draw the face of the clock.

    :param marks: A function to draw marks around
         the face.
    """
    turtle.setundobuffer( None )

    turtle.title("HamCalc logoclok")
    turtle.hideturtle()
    turtle.pensize(4)
    turtle.penup()
    turtle.goto( 0, -R )
    turtle.pendown()
    turtle.circle( R, steps=60 )
    turtle.pensize(1)

    marks()

    turtle.penup(); turtle.home()
    turtle.goto( 0, 100 ); turtle.write( "H A M C A L C", align="center", font=("Helvetica", 24, "normal") )

    # Create an empty undo buffer to simplify undrawing the hands.
    turtle.setundobuffer( 128 )
Esempio n. 11
0
#[email protected]
import os
import random
import turtle
import time
turtle.fd(0)
turtle.speed(0)
turtle.bgcolor("black")
turtle.ht()
turtle.setundobuffer(35)
turtle.tracer(35)


class Sprite(turtle.Turtle):
    def __init__(self, spriteshape, color, startx, starty):
        turtle.Turtle.__init__(self, shape=spriteshape)
        self.speed(0)
        self.penup()
        self.color(color)
        self.fd(0)
        self.goto(startx, starty)
        self.speed = 1

    def move(self):
        self.fd(self.speed)

        if self.xcor() > 290:
            self.setx(290)
            self.rt(60)
        if self.xcor() < -290:
            self.setx(-290)
Esempio n. 12
0
# Part 8: Multiple Enemies / Multiple Allies
import os
import random
import turtle

turtle.fd(0)
turtle.speed(0)
# set screen size and start location
turtle.setup(width=.99, height=.99, startx=0, starty=0)
turtle.bgcolor("black")
turtle.ht()
turtle.setundobuffer(1)
turtle.tracer(3)


class Sprite(turtle.Turtle):
    def __init__(self, spriteshape, color, startx, starty):
        turtle.Turtle.__init__(self, shape=spriteshape)
        self.speed(0)
        self.penup()
        self.color(color)
        self.fd(0)
        self.goto(startx, starty)
        self.speed = 1

    def move(self):
        self.fd(self.speed)

        # Boundary detection
        # check right side of border
        if self.xcor() > 290:
Esempio n. 13
0
import turtle
import random
import time

# set up screen

turtle.ht()
turtle.setup(950, 950)
turtle.title("Space Rescue")
turtle.bgcolor("black")

#This saves memory
turtle.setundobuffer(0)
#This speeds up drawing
turtle.tracer(0)


class Game():
    def __init__(
        self
    ):  # All class will have a method __init__ which provide instructions on what arguments is needed, example below
        self.pen = turtle.Turtle(
        )  # Has also invoked an turtle method (an additional attribute) to draw borders.

    def draw_border(self):  #Function that draw border
        self.pen.speed(0)
        self.pen.color("white")
        self.pen.pensize(3)
        self.pen.penup()
        self.pen.goto(-400, 400)
        self.pen.pendown()
Esempio n. 14
0
# cd /media/biplav/Biplav_2/CollegeStuff/Research/DrReed/AgeofInformation/demo/game/Space_Invaders/program/SpaceInvaders/State_Removed.py
import os
import random
import turtle
import settings

#latest
wn = turtle.Screen()
wn.bgpic("white_back.gif")
turtle.fd(0)
turtle.speed(0)
turtle.bgcolor("black")
turtle.ht()
turtle.setundobuffer(None)
turtle.delay(1)
# turtle.tracer(20,0)
turtle.register_shape("tank11.gif")
turtle.register_shape("drone11.gif")
turtle.register_shape("drone22.gif")
turtle.register_shape("antenna.gif")
turtle.register_shape("bullet1.gif")


class Game():
    def draw_border(self):
        #Draw border
        self.pen = turtle.Turtle()
        self.pen.speed(0)
        self.pen.color("white")
        self.pen.pensize(0)
        self.pen.penup()
Esempio n. 15
0
from math import *
import numpy as np
import turtle
import time

screen = turtle.Screen()
turtle.setup(750, 750)

screen.bgcolor("black")
screen.title("")
screen.tracer(0)

turtle.ht()  #hideturtle()
turtle.setundobuffer(1)  #limits the memory to undo.
''' 10 pxls = 1 m '''
''' 1 loop = 1 sec '''

global gravity
gravity = -9.807
gravity /= 10


def det(a, b):
    return a[0] * b[1] - a[1] * b[0]


class rigid_body(turtle.Turtle):
    def __init__(self,
                 color,
                 shape,
                 size,
Esempio n. 16
0
# SpaceWare by @TokyoEdTech
# Part III : Getting started
# Game Object / Broder / Boundary Checking
# Create enemy and collision
# Create a Missile
# Create an Ally
# Game Status/Score/sound

import os
import random
import turtle

turtle.speed(0)  # Set the animations sepeed to the maximum
turtle.bgcolor('black')  # Change the background color
turtle.hideturtle()  # hide the default turtle
turtle.setundobuffer(1)  # This saves memory
turtle.tracer(1)  # This speeds up drawing

turtle.register_shape('fishtank.gif')


class Sprite(turtle.Turtle):
    def __init__(self, spriteshape, color, startx, starty):
        turtle.Turtle.__init__(self, shape=spriteshape)
        #self.shape(spriteshape)
        self.speed(0)
        self.penup()
        self.color(color)
        self.goto(startx, starty)
        self.speed = 1
Esempio n. 17
0
def main():
    """The entry point of the program."""
    # parse command-line arguments
    parser = argparse.ArgumentParser()
    parser.add_argument("--no-export",
                        action="store_true",
                        help="Don't export an .eps file of the drawing")
    parser.add_argument(
        "--fast",
        action="store_true",
        help="Add triangles directly to the Tkinter canvas for speed")
    parser.add_argument("--birds-eye",
                        action="store_true",
                        help="Show a bird's eye view of the entire terrain")
    parser.add_argument("--random-terrain",
                        action="store_true",
                        help="Use a random seed for the terrain heightmap")
    parser.add_argument(
        "--random-color-offset",
        action="store_true",
        help="Use a random seed for the color offset heightmap")
    args = parser.parse_args()

    # set up turtle parameters
    print("Setting up...")
    turtle.setup(9999, 9999)
    win_scale = min(turtle.window_width() // 22, turtle.window_height() // 17)
    turtle.setup(win_scale * 22,
                 win_scale * 17)  # the largest 11x8.5 window possible
    turtle.title("Submission by Quinn Tucker")
    turtle.tracer(0, 0)
    turtle.setundobuffer(None)
    turtle.hideturtle()
    turtle.penup()

    # fill the background with the sky gradient
    print("Filling the sky...")
    fill_sky_gradient(256, 0.58)

    # set up the lights and camera
    lights = [
        #DirectionalLight(SUNLIGHT_DIRECTION, SUNLIGHT_COLOR, dot_clip=0.0),
        DirectionalLight(AMBIENT_LIGHT_DIRECTION,
                         AMBIENT_LIGHT_COLOR,
                         dot_clip=-0.0),
    ]
    if args.birds_eye:
        camera = Camera((0, 6.0, -2.4),
                        math.pi * 0.34,
                        0,
                        0,
                        zoom=3.4,
                        fog_factor=0,
                        lights=lights,
                        fast_draw=args.fast)
    else:
        camera = Camera((0, 0.07, -0.001),
                        0,
                        0,
                        0,
                        zoom=1.2,
                        fog_factor=FOG_FACTOR,
                        lights=lights,
                        fast_draw=args.fast)

    # generate and draw the terrain
    print("Generating terrain...")
    if args.random_color_offset:
        color_offset_seed = random.getrandbits(32)
        print(f"    Color offset seed = {color_offset_seed}")
    else:
        color_offset_seed = 3038607546
    random.seed(color_offset_seed)
    color_offset = Terrain(recursion_depth=9, noise_depth=4, scale=0.35)

    if args.random_terrain:
        terrain_seed = random.getrandbits(32)
        print(f"    Terrain seed = {terrain_seed}")
    else:
        terrain_seed = 129477298
    random.seed(terrain_seed)
    terrain = Terrain(recursion_depth=9,
                      noise_depth=7,
                      scale=0.10,
                      snow_height=0.025,
                      tree_height=-0.015,
                      color_offset_heightmap=color_offset)

    terrain.draw(camera)
    print("Updating the screen...")
    turtle.update()

    # export the drawing to a file
    if not args.no_export:
        OUTPUT_FILE = "output.eps"
        print(f"Exporting {OUTPUT_FILE}...")
        turtle.getcanvas().postscript(file=OUTPUT_FILE,
                                      colormode="color",
                                      pagewidth="11i")

    # wait for the user to close the window
    print("Done!")
    turtle.mainloop()
Esempio n. 18
0
def main():
    #set up the screen
    import turtle
    import math
    import random
    import time
    import tkinter.messagebox

    window = turtle.Screen()
    window.bgcolor("black")
    window.title("Pacman")
    window.setup(700, 700)
    turtle.setundobuffer(1)
    turtle.fd(0)
    turtle.tracer(50)

    class Game():
        def __init__(self):
            self.score = 0
            self.state = "splash"
            self.pen = turtle.Turtle()
            self.lives = 3

        def show_status(self):
            self.pen.clear()
            if game.lives > 0:
                msg = "Lives: %s Score: %s " % (self.lives, self.score)
            else:
                msg = "Game Over Score: %s" % (self.score)
            self.pen.penup()
            self.pen.goto(0, 300)
            self.pen.color("white")
            self.pen.write(msg, font=("Arial", 24, "normal"))
            self.pen.hideturtle()

    game = Game()
    game.show_status()

    #pictures
    turtle.register_shape("pacman_left.gif")
    turtle.register_shape("pacman_right.gif")

    #create pen
    class Pen(turtle.Turtle):
        def __init__(self):
            turtle.Turtle.__init__(self)
            self.shape("square")
            self.color("blue")
            self.penup()
            self.speed(0)

    #create player
    class PLayer(turtle.Turtle):
        def __init__(self):
            turtle.Turtle.__init__(self)
            self.shape("pacman_right.gif")
            self.color("yellow")
            self.penup()
            self.speed(0)

        def move_up(self):
            if (player.xcor(), player.ycor() + 24) not in walls:
                self.goto(self.xcor(), self.ycor() + 24)

        def move_down(self):
            if (player.xcor(), player.ycor() - 24) not in walls:
                self.goto(self.xcor(), self.ycor() - 24)

        def move_left(self):
            self.shape("pacman_left.gif")
            if (player.xcor() - 24, player.ycor()) not in walls:
                self.goto(self.xcor() - 24, self.ycor())

        def move_right(self):
            self.shape("pacman_right.gif")
            if (player.xcor() + 24, player.ycor()) not in walls:
                self.goto(self.xcor() + 24, self.ycor())

        def is_touching(self, other):
            a = self.xcor() - other.xcor()
            b = self.ycor() - other.ycor()
            distance = math.sqrt((a**2) + (b**2))

            if distance < 5:
                return True
            else:
                return False

    class Coin(turtle.Turtle):
        def __init__(self, x, y):
            turtle.Turtle.__init__(self)
            self.shape("circle")
            self.color("white")
            self.penup()
            self.shapesize(0.25, 0.25)
            self.speed(0)
            self.goto(x, y)

        def delete(self):
            self.goto(2000, 2000)
            self.hideturtle()

    class Enemy(turtle.Turtle):
        def __init__(self, x, y):
            turtle.Turtle.__init__(self)
            self.shape("turtle")
            self.color("red")
            self.penup()
            self.speed(0)
            self.goto(x, y)
            self.direction = random.choice(["up", "down", "left", "right"])

        def move(self):
            if self.direction == "up":
                dx = 0
                dy = 24
            elif self.direction == "down":
                dx = 0
                dy = -24
            elif self.direction == "left":
                dx = -24
                dy = 0
            elif self.direction == "right":
                dx = 24
                dy = 0
            else:
                dx = 0
                dy = 0

            if self.is_close(player):
                if player.xcor() < self.xcor():
                    self.direction = "left"
                elif player.xcor() > self.xcor():
                    self.direction = "right"
                elif player.ycor() < self.ycor():
                    self.direction = "down"
                elif player.ycor() > self.ycor():
                    self.direction = "up"

            move_to_x = self.xcor() + dx
            move_to_y = self.ycor() + dy

            if (move_to_x, move_to_y) not in walls:
                self.goto(move_to_x, move_to_y)
            else:
                self.direction = random.choice(["up", "down", "left", "right"])

            turtle.ontimer(self.move, t=random.randint(100, 300))

        def is_close(self, other):
            a = self.xcor() - other.xcor()
            b = self.ycor() - other.ycor()
            distance = math.sqrt((a**2) + (b**2))
            if distance < 75:
                return True
            else:
                return False

    #Create levels list
    levels = [""]

    #first level
    level_1 = [
        "xxxxxxxxxxxxxxxxxxxxxxxx", "xP CCCCCCCCCCCCCCCCCCCCx",
        "x xxxxxxxxCxxxxxCxxxxxCx", "xCCCCCCCCCCxCCCCCCCCCCCx",
        "xCxxxxxxxxCCCxxxCxxxxxCx", "xCx      xCxCCCxCx   xCx",
        "xCx      xCCCxCxCxxxxxCx", "xCx      xCxCxCxCCCCCxCx",
        "xCx      xCCCCCxCxCxCxCx", "xCxxxxxxxxCxCxxxxxCxCxCx",
        "xCxCCCCCCCCCCCCCCCCCCCCx", "xCxCxxCxxxxxCxxxx xxxx x",
        "xCxCCCCxCCCCCx e  xee  x", "xCxCxxCxCxxxCx    xee  x",
        "xCxCCCCxCxxxCxxxx xxxx x", "xCxCxxCxCCCCCCCCxCCCCxCx",
        "xCxCCCCxCxxxCxxCxCxxCxCx", "xCxCxxCxCCCCCCCCxCCCCxCx",
        "xCxCCCCxxxxxCxxxxCxxxxCx", "xCCCCxCCCCCCCCCCCCCCCCCx",
        "xCxxxCCCCCxxxCCCCCxxxCCx", "xCCCCCxxxCCCCCxxxCCCCCxx",
        "xCxxxCCCCCxxxCCCCCxxxCCx", "xxxxxxxxxxxxxxxxxxxxxxxx"
    ]

    #add a coin list
    coins = []

    enemies = []
    #add level to list
    levels.append(level_1)

    #create level setup
    def setup_maze(level):
        for y in range(len(level)):
            for x in range(len(level[y])):
                character = level[y][x]
                screen_x = -288 + (x * 24)
                screen_y = 288 - (y * 24)
                if character == "x":
                    pen.goto(screen_x, screen_y)
                    pen.stamp()
                    walls.append((screen_x, screen_y))
                if character == "P":
                    player.goto(screen_x, screen_y)
                if character == "C":
                    coins.append(Coin(screen_x, screen_y))
                if character == "e":
                    enemies.append(Enemy(screen_x, screen_y))

    pen = Pen()
    player = PLayer()
    walls = []
    setup_maze(levels[1])

    #keyboard movement
    turtle.listen()
    turtle.onkey(player.move_left, "a")
    turtle.onkey(player.move_right, "d")
    turtle.onkey(player.move_up, "w")
    turtle.onkey(player.move_down, "s")

    for enemy in enemies:
        turtle.ontimer(enemy.move, t=500)

    game.state = "playing"
    #Main Game Loop

    while True:
        window.update()

        if game.state == "restart":
            window.clear()
            main()

        if game.state == "playing":
            for coin in coins:
                if player.is_touching(coin):
                    game.score += 10
                    if game.score == 2500:
                        game.state = "winner"
                    window.delay(5)
                    game.show_status()
                    coin.delete()
                    coins.remove(coin)

            for enemy in enemies:
                if player.is_touching(enemy):
                    player.goto(-264, 264)
                    enemies[0].goto(192, 0)
                    enemies[1].goto(192, -24)
                    enemies[2].goto(168, 0)
                    enemies[3].goto(168, -24)
                    enemies[4].goto(96, 0)
                    game.lives -= 1
                    if game.lives < 1:
                        game.state = "gameover"
                    window.delay(5)
                    game.show_status()

        if game.state == "gameover":
            if tkinter.messagebox.askyesno("Game Over", "Play Again?") == True:
                game.state = "restart"
            else:
                exit()

        if game.state == "winner":
            if tkinter.messagebox.askyesno("You Win!", "Play Again?") == True:
                game.state = "restart"
            else:
                exit()

    delay = input("Press enter to finish.")
Esempio n. 19
0
import random
import turtle
import winsound
import time

turtle.fd(0)  #to show the window
turtle.speed(0)  #to set animation speed
turtle.bgcolor("black")  #change the background color
turtle.title("Space War")
turtle.bgpic("background3.gif")
turtle.ht()  #hide the default turtle
turtle.setundobuffer(1)  #save memory
turtle.tracer(0)  #speed up drawing


#Create class
class Sprite(turtle.Turtle):
    def __init__(self, spriteshape, color, startx, starty):
        turtle.Turtle.__init__(self, shape=spriteshape)
        self.speed(0)
        self.penup()
        self.color(color)
        self.fd(0)
        self.goto(startx, starty)
        self.speed = 1

    def move(self):
        self.fd(self.speed)
        # Boundary detection
        if self.xcor() > 290:
            self.setx(290)
Esempio n. 20
0
import random
import winsound
import turtle
import time

turtle.speed(0)  # controls the speed of animations. just draw ASAP.

turtle.ht()  # hides the default turtle
turtle.setundobuffer(1)  # stops using too much memory
turtle.tracer(0)
wn = turtle.Screen()
wn.bgcolor("black")
wn.title("SPACEWARS)")
wn.bgpic("bkground1.gif"
         )  # will change later. how oftne you want to update the screen

# sprite is a child class of turtle

# parent class


class Sprite(turtle.Turtle):  # sprites are characters on the screen
    def __init__(self, spriteshape, color, startx, starty):
        turtle.Turtle.__init__(self, shape=spriteshape)
        self.speed(0)  # speed of animation 0 is fastest
        self.penup()  # no drawing yet
        self.color(color)  # define later
        self.goto(startx, starty)  # define later
        self.speed = 1  # movement speed

    def move(self):