Esempio n. 1
1
def main():
    screen.mode("logo")
    t = Turtle(shape="triangle")
    t.penup(); t.back(280); t.pendown()
    t.pensize(3)
    itree(t, 250, 0.63,
          ["black", "brown", "red", "orange", "violet", "lightblue"])
 def __init__(self, lmbda, mu, queue, server, speed):
     """
     Arguments:
         lmbda: arrival rate (float)
         interarrivaltime: a randomly sampled interarrival time (negative exponential for now)
         mu: service rate (float)
         service: a randomly sampled service time (negative exponential for now)
         queue: a queue object
         shape: the shape of our turtle in the graphics (a circle)
         server: a server object
         served: a boolean that indicates whether or not this player has been served.
         speed: a speed (integer from 0 to 10) to modify the speed of the graphics
         balked: a boolean indicating whether or not this player has balked (not actually needed for the base Player class... maybe remove... but might be nice to keep here...)
     """
     Turtle.__init__(self)  # Initialise all base Turtle attributes
     self.interarrivaltime = randexp(lmbda)
     self.lmbda = lmbda
     self.mu = mu
     self.queue = queue
     self.served = False
     self.server = server
     self.servicetime = randexp(mu)
     self.shape('circle')
     self.speed(speed)
     self.balked = False
Esempio n. 3
0
def init_drawman():
    global t, x_current, y_current
    t=Turtle()
    t.penup()
    x_current = 0
    y_current = 0
    t.goto(x_current,y_current)
Esempio n. 4
0
 def __init__(self, distance, color, speed):
     Turtle.__init__(self)
     self.pencolor(color)
     self.speed = speed
     self.penup()
     self.forward(distance)
     self.pendown()
Esempio n. 5
0
 def __init__(self, bilddatei, game):
     Turtle.__init__(self, bilddatei)
     self.game = game
     self.penup()
     self.speed(0)
     self.onclick(self.hit)
     self.start()
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)
Esempio n. 7
0
    def __init__(self, start=(10,10), end=(160,160),
                 width=200, height=200):
        Turtle.__init__(self)
        self.hideturtle()
        self.screen.bgcolor("blue")
        self.screen.setworldcoordinates(-DISTANCE, -DISTANCE,
                                        DISTANCE+width,
                                        DISTANCE+height)

        self.screen.tracer(30,0)
        self.pensize(5)
        self.color("white", "black")
        lab = {start} 
        while True:
            new_points = set()
            for point in lab:
                x,y = map(add, point, choice(WAYS))
                if (0 <= x <= width and
                    0 <= y <= height and
                    (x,y) not in lab and
                    (x,y) not in new_points):
                    self.penup()
                    self.goto(*point)
                    self.pendown()
                    self.goto(x,y)
                    new_points.add((x,y))
            if new_points or end not in lab:
                lab |= new_points
            else:
                break
        self.mark_targets(start, end)
        self.maze_map = lab
        self.start = start
        self.end = end
        print("KONEC")
Esempio n. 8
0
def draw_figures(figures):
    for figure in figures:
        t = Turtle()
        t.speed('slow')
        figure.draw_figure(t)

    done()
Esempio n. 9
0
class LSystem(object):


    def __init__(self):
        self.turtle = Turtle()

    def reset(self):
        self.turtle.reset()

    def set_lsystem(self,lsystem):
        self.axiom,self.rules,self.angle = lsystem
        self.segment_length=5         


    def generate(self,generations_num): 
        def generate_help(start): 
             for e in start: 
                for r in self.rules.get(e,e):
                    yield r 
        if generations_num==0: return self.axiom
        return generate_help(self.generate(generations_num-1))     
                                                                
    def draw(self,generations,chunk_size):
        iterable = interpret(self.turtle,self.generate(generations),self.angle)
        l=[]
        for e in iterable:
            l.append(e)
            if len(l)==chunk_size:
                yield l
                l=[]
        if l: yield l
Esempio n. 10
0
def init_drawman():
    global t, x_current, y_current, _drawman_scale
    t=Turtle()
    t.penup()
    x_current = 0
    y_current = 0
    t.goto(x_current, y_current)
    drawman_scale(default_scale)
Esempio n. 11
0
def main():
    dimension = int(input('Enter dimension: '))

    t = Turtle()
    t.speed('fastest')
    t.pensize(3)

    draw_table(dimension, 50, t, -200, 300)
Esempio n. 12
0
 def __init__(self):
     Turtle.__init__(self)
     self.up()
     self.setheading(random.randrange(360))
     self.setpos(random.randrange(-200,200),random.randrange(-200,200))
     self.down()
     self.newHead = None
     Schooler.swarm.append(self)
Esempio n. 13
0
 def __init__(self, col, row):
     Turtle.__init__(self)
     self.speed(0)
     self.pu()
     self.shape("square")
     self.color("black", "")
     self.shapesize((BLOCKWIDTH-1)/20., (BLOCKWIDTH-1)/20., 1)
     self.goto(-COLUMNS*BLOCKWIDTH/2+14+col*BLOCKWIDTH, ROWS*BLOCKWIDTH/2 - 14 - row*BLOCKWIDTH)
Esempio n. 14
0
def init_drawman():
    global x_current, y_current, t, _drawman_scale
    t=Turtle()
    t.penup()
    x_current=0
    y_current=0
    t.goto(x_current,y_current)
    drawman_scale(default_scale) # функция задает масштаб по умолчанию
Esempio n. 15
0
    def test_segments_stored(self):
        """With branching, some points exist"""
        my_turtle = Turtle()
        my_turtle.speed(0)
        my_tree = Tree()
        my_tree.draw(my_turtle, max_depth=1)

        self.assertTrue(len(my_tree.segments) > 0, "Some segments should be stored")
Esempio n. 16
0
 def __init__(self, picfile, action):
     Turtle.__init__(self)
     self.getscreen().register_shape(picfile)
     self.shape(picfile)
     def _action(x,y):
         action()
     self.onclick(_action)
     self.pu()
     self.speed(0)
Esempio n. 17
0
    def test_points_stored(self):
        """After one iteration, as least a trunk segment should be stored"""
        my_turtle = Turtle()
        my_turtle.speed(0)
        my_tree = Tree()
        my_tree.draw(my_turtle, max_depth=1)
        # whitebox

        self.assertTrue(len(my_tree._points) > 0, "Some points should be stored")
Esempio n. 18
0
def init_drawman():
    """ Инициализация черепашки """
    global t, x_current, y_current, _drawman_scale
    t = Turtle()
    t.penup()
    x_current = 0
    y_current = 0
    t.goto(x_current, y_current)
    drawman_scale(default_scale)
Esempio n. 19
0
 def __init__(self, m, x, v, gravSys, shape):
     Turtle.__init__(self, shape=shape)
     self.penup()
     self.m = m
     self.setpos(x)
     self.v = v
     gravSys.planets.append(self)
     self.gravSys = gravSys
     self.resizemode("user")
     self.pendown()
Esempio n. 20
0
def init_drawman():
    global t, x_current, y_current, _drawman_scale, _step_grid, _count_point
    t = Turtle()
    t.penup()
    x_current = 0
    y_current = 0
    t.goto(x_current, y_current)
    _count_point = default_count_point
    _step_grid = default_step_grid
    drawman_scale(default_scale,default_step_grid)
Esempio n. 21
0
def init_drawman():
    global t, x_current, y_current, _drawman_scale, dx, dy
    t = Turtle()
    t.penup()
    x_current = 0
    y_current = 0
    dx = t.screen.window_width()/2
    dy = t.screen.window_height()/2
    t.goto(x_current, y_current)
    drawman_scale(default_scale)
Esempio n. 22
0
    def __init__(self, distance, color, speed, angle):
        Turtle.__init__(self)
        self.pencolor(color)
        self.speed = speed
        self.angle = angle

        self.penup()
        self.forward(distance)
        self.pendown()
        self.left(90)
Esempio n. 23
0
 def __init__(self, m, x, v, gravSys, shape):
     Turtle.__init__(self, shape)
     gravSys.planets.append(self)
     self.gravSys = gravSys
     self.dt = self.gravSys.dt
     self.penup()
     self.m = m
     self.setpos(x)
     self.vel = v
     self.pendown()
def init():
    global TTiles, STiles, designer
    screen.mode("logo")
    screen.tracer(False)
    designer = Turtle(visible=False)
    designer.pu()
    makerhomboidshapes()
    screen.bgcolor("gray10")
    STiles = [TStein(A/20., clickable=False),
              TStein(A/20., clickable=False),
              TStein(2*d/20., clickable=False),
              TStein(A/40., clickable=False),
              TStein(A/40., clickable=False),
              TStein(d/20., "square", clickable=False),
              TRhomboid(clickable=False)]
    TTiles = [TStein(A/20.),
              TStein(A/20.),
              TStein(2*d/20.),
              TStein(A/40.),
              TStein(A/40.),
              TStein(d/20., "square"),
              TRhomboid()]
    for s in STiles:
        s.color((1,1,0.9))
        s.turtlesize(s.size, s.size, 2)
        s.ht()
    screen.update()
    designer.goto(-390,-288)
    designer.pencolor("gray70")
    designer.write("Inspired by Pavel Boytchev's Elica-Logo implementation of the tangram game",
                   font=("Courier", 10, "bold"))
    nextBtn = Button("next.gif", resetgame)
    nextBtn.setpos(320,220)
    helpBtn = Button("help.gif", helpme)
    helpBtn.setpos(320,-220)
Esempio n. 25
0
def setup(color, distance):
    t = Turtle()
    t.pencolor(color)
    t.penup()
    t.forward(distance)
    t.pendown()
    return t
Esempio n. 26
0
def init_drawman():
    ''' Инициализация черепашки '''
    global t, x_current, y_current, _drawman_scale
    shag=40
    vod=0.5
    t = Turtle()
    t.penup()
    x_current = 0
    y_current = 0
    t.goto(x_current, y_current)
    drawman_scale(shag,vod)
Esempio n. 27
0
def startTurtle():
    t = Turtle()
    t.hideturtle()
    t.speed(10)
    t.up()
    t.setpos(-dim/2,-dim/2)
    colormode(255)
    return t
Esempio n. 28
0
def init_drawman():
    """ Инициализация Чертежника"""
    global t, x_current, y_current, _drawman_scale, _drawman_pen_size
    t = Turtle()
    t.penup()
    shag = 40
    vod = 0.5
    x_current = 0
    y_current = 0
    t.goto(x_current, y_current)
    drawman_scale(default_scale, shag, vod)
    drawman_pen_size(default_pen_size)
Esempio n. 29
0
    return a * b / math.gcd(a, b)


math.lcm = lcm

# Setup Turtle ###############################################################

window = Pixels(800)
turtle_global.getscreen().setup(width=int(window),
                                height=int(window),
                                startx=None,
                                starty=None)
turtle_global.screensize(int(window) - 20, int(window) - 20, "black")
turtle_global.hideturtle()

turtle = Turtle()
screen_size = Pixels(turtle.screen.screensize()[0])
world_size = CartesianResolution(900, 900)
Distance.set_conversion_factor(screen_size, world_size.x)
turtle.hideturtle()
turtle.speed(0)
turtle.color("white", "white")
turtle.begin_fill()
turtle.setpos(0, -int(TABLE_RADIUS_MM.pixels()))
turtle.circle(int(TABLE_RADIUS_MM.pixels()))
turtle.setpos(0, 0)
turtle.end_fill()
turtle.color("black", "white")
turtle.speed('fast')

turtle = Turtle()
Esempio n. 30
0
 def new_turtle():
     tt = Turtle('circle')
     tt.color('white')
     tt.penup()
     tt.speed(0)
     return tt
Esempio n. 31
0
from turtle import Turtle
t = Turtle()
t.screen.bgcolor("black")
t.hideturtle()
t.color("red")


def slanted_rectangle(length, width, angle):
    t.setheading(angle)
    for steps in range(2):
        t.fd(width)
        t.left(90)
        t.fd(length)
        t.left(90)


slanted_rectangle(length=200, angle=45, width=100)
Esempio n. 32
0
# https://docs.python.org/3/library/turtle.html
# https://cs111.wellesley.edu/labs/lab01/colors
# https://pypi.org/

from turtle import Turtle, Screen

timmy = Turtle()
print(timmy)
timmy.shape("turtle")
timmy.color("coral")
timmy.forward(100)

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

# go to pypi.prg and search for "prettytable" and install the pakage.
# File - settings - project folder - interpreter - click the "+" to add "install"

from prettytable import PrettyTable
# to see the source code, right click on "prettytable" and Go to implementation
table = PrettyTable()
table.field_names = ["Pokemon Name", "Type"]
table.add_row(["Pikcachu", "Electric"])
table.add_row(["Squirtle", "Water"])
table.add_row(["Charmander", "Fire"])
print(table)

table2 = PrettyTable()
table2.add_column("Pokemon Name", ["Pikcachu", "Squirtle", "Charmander"])
table2.add_column("Type", ["Electric", "Water", "Fire"])
Esempio n. 33
0
from turtle import Turtle, Screen

TURTLE_SIZE = 20

screen = Screen()

yertle = Turtle(shape="turtle", visible=False)
yertle.penup()
yertle.goto(TURTLE_SIZE / 2 - screen.window_width() / 2,
            screen.window_height() / 2 - TURTLE_SIZE / 2)
yertle.pendown()
yertle.showturtle()

for i in range(5):
    yertle.penup()
    yertle.forward(20)
    yertle.right(90)
    yertle.pendown()
    yertle.showturtle()
    input("Press to continue")

screen.mainloop()
Esempio n. 34
0
def main():
    p = Turtle()
    p.color("green")
    p.pensize(5)
    # p.setundobuffer(None)
    p.hideturtle(
    )  # Make the turtle invisible. It’s a good idea to do this while you’re in the middle of doing some complex drawing,
    # because hiding the turtle speeds up the drawing observably.
    # p.speed(10)
    # p.getscreen().tracer(1,0)#Return the TurtleScreen object the turtle is drawing on.
    p.speed(10)
    # TurtleScreen methods can then be called for that object.
    p.left(90)  # Turn turtle left by angle units. direction 调整画笔

    p.penup()  # Pull the pen up – no drawing when moving.
    p.goto(
        0, -200
    )  # Move turtle to an absolute position. If the pen is down, draw line. Do not change the turtle’s orientation.
    p.pendown(
    )  # Pull the pen down – drawing when moving. 这三条语句是一个组合相当于先把笔收起来再移动到指定位置,再把笔放下开始画
    # 否则turtle一移动就会自动的把线画出来

    # t = tree([p], 200, 65, 0.6375)
    t = tree([p], 200, 65, 0.6375)
Esempio n. 35
0
print("Colors extracted (rgb values): ")
for color in colors:
  colors_list.append((color.rgb[0], color.rgb[1], color.rgb[2]))

# Handy function to return a random RGB value to be used throughout the program
def generate_rgb():
  r = randint(0,255)
  g = randint(0,255)
  b = randint(0,255)
  return (r, g, b)

#print(generate_rgb())

# Create and configure turtle
timmy_the_turtle = Turtle()
timmy_the_turtle.shape("turtle")
timmy_the_turtle.color("red")
colormode(255)
# Pen up so lines will not show
timmy_the_turtle.penup()
timmy_the_turtle.hideturtle()
# Adjust turtle to be at a spot
timmy_the_turtle.setheading(225)
timmy_the_turtle.forward(250)

timmy_the_turtle.setheading(90)
timmy_the_turtle.forward(50)
timmy_the_turtle.left(90)
timmy_the_turtle.forward(500)
timmy_the_turtle.right(90)
# ['DEFAULT_ANGLEOFFSET', 'DEFAULT_ANGLEORIENT', 'DEFAULT_MODE', 'START_ORIENTATION', '__class__', '__delattr__',
# '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__',
# '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__',
# '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_cc', '_clear', '_clearstamp',
# '_color', '_colorstr', '_delay', '_drawturtle', '_getshapepoly', '_go', '_goto', '_newLine', '_pen', '_polytrafo',
# '_reset', '_rotate', '_screen', '_setDegreesPerAU', '_setmode', '_tracer', '_undo', '_undogoto', '_update',
# '_update_data', '_write', 'back', 'backward', 'begin_fill', 'begin_poly', 'bk', 'circle', 'clear', 'clearstamp',
# 'clearstamps', 'clone', 'color', 'degrees', 'distance', 'dot', 'down', 'end_fill', 'end_poly', 'fd', 'fillcolor',
# 'filling', 'forward', 'get_poly', 'get_shapepoly', 'getpen', 'getscreen', 'getturtle', 'goto', 'heading', 'hideturtle',
# 'home', 'ht', 'isdown', 'isvisible', 'left', 'lt', 'onclick', 'ondrag', 'onrelease', 'pd', 'pen', 'pencolor', 'pendown',
# 'pensize', 'penup', 'pos', 'position', 'pu', 'radians', 'reset', 'resizemode', 'right', 'rt', 'screens', 'seth',
# 'setheading', 'setpos', 'setposition', 'settiltangle', 'setundobuffer', 'setx', 'sety', 'shape', 'shapesize',
# 'shapetransform', 'shearfactor', 'showturtle', 'speed', 'st', 'stamp', 'tilt', 'tiltangle', 'towards', 'turtlesize',
# 'undo', 'undobufferentries', 'up', 'width', 'write', 'xcor', 'ycor']

from turtle import Turtle

tess = Turtle()
distancia = 1

while True:
    tess.speed(10000000)
    tess.forward(distancia)
    tess.right(90)
    tess.forward(distancia)
    tess.right(90)
    tess.forward(distancia)
    tess.begin_fill()

    distancia = distancia * 1.6
Esempio n. 37
0
root = tkinter.Tk()
root.withdraw()

is_race_on = False
screen = Screen()
screen.bgcolor("black")
screen.setup(width=500, height=400)
user_bet = screen.textinput(
    title="Make your bet",
    prompt="Which turtle will win the race? Make a bet.: ")
colors = ["red", "blue", "pink", "green", "purple", "orange"]
y_positions = [-70, -40, -10, 20, 50, 80]
all_turtles = []

for turtle_index in range(0, 6):
    new_turtle = Turtle(shape="turtle")
    new_turtle.penup()
    new_turtle.color(colors[turtle_index])
    new_turtle.goto(x=-230, y=y_positions[turtle_index])
    all_turtles.append(new_turtle)

if user_bet:
    is_race_on = True

while is_race_on:

    for turtle in all_turtles:
        if turtle.xcor() > 210:
            is_race_on = False
            winning_color = turtle.pencolor()
            if winning_color == user_bet:
Esempio n. 38
0
 def __init__(self):
     Turtle.__init__(self)
     self.shape = hexagon
def main():  # Main function
    for k in range(1, 25):  # Picking the time
        mylist = []  # lisr declaration
        for i in range(1, c):  # Reading the dataset every hour
            fun(i, k, mylist)

        print(mylist)

        ROOT3_OVER_2 = sqrt(3) / 2  # Graphics Representation
        FONT_SIZE = 12
        FONT = ('Arial', FONT_SIZE, 'normal')

        SIDE = 90  # the scale used for drawing

        # Convert hex coordinates to rectangular
        def hex_to_rect(coord):
            v, u, w = coord
            x = -u / 2 + v - w / 2
            y = (u - w) * ROOT3_OVER_2
            return x * SIDE, y * SIDE

        def hexagon(turtle, radius, color, label):
            clone = turtle.clone()  # so we don't affect turtle's state
            xpos, ypos = clone.position()
            clone.setposition(xpos - radius / 2, ypos - ROOT3_OVER_2 * radius)
            clone.setheading(-30)
            clone.color('black', color)
            clone.pendown()
            clone.begin_fill()
            clone.circle(radius, steps=6)
            clone.end_fill()
            clone.penup()
            clone.setposition(xpos, ypos - FONT_SIZE / 2)
            clone.write(label, align="center", font=FONT)

        # Initialize the turtle
        tortoise = Turtle(visible=False)
        tortoise.speed('fastest')
        tortoise.penup()
        Dict2 = {
            'Live linguistic news': 'Red',
            'Live sports event': 'Grey',
            'Cinematic movies': 'Blue',
            'Anime/Cartoon': 'Pink',
            'Study related material': 'Orange',
            'Company related material': 'Cyan',
            'Web Series': 'Yellow',
            'Fitness videos': 'Green',
            'Online gaming': 'White'
        }
        coords = [[0, 0, 0], [0, 1, -1], [-1, 1, 0], [-1, 0, 1], [0, -1, 1],
                  [1, -1, 0], [1, 0, -1], [-2, 1, 1], [4, 4, 1], [1, 1, 4]]
        labels = mylist
        #colors = [Dict2[8], Dict2[3], Dict2[8], Dict2[8], Dict2[1], Dict2[8], Dict2[8],Dict2[1],Dict2[1],Dict2[1]]
        colors = [
            Dict2[mylist[0]], Dict2[mylist[1]], Dict2[mylist[2]],
            Dict2[mylist[3]], Dict2[mylist[4]], Dict2[mylist[5]],
            Dict2[mylist[6]], Dict2[mylist[7]], Dict2[mylist[8]],
            Dict2[mylist[9]]
        ]

        # Plot the points
        for hexcoord, color, label in zip(coords, colors, labels):
            tortoise.goto(hex_to_rect(hexcoord))
            hexagon(tortoise, SIDE, color, label)

        # Wait for the user to close the window
        screen = Screen()
        time.sleep(5)
    screen.exitonclick()
Esempio n. 40
0
while score < 50:
    # open prompt for user question
    answer_state = screen.textinput(
        title=f"{score}/50 States",
        prompt="What's another State's name?").title()
    if answer_state.title() == "Exit":
        # generate list of non guessed states
        missing_states = [
            state for state in us_states_list if state not in guessed_states
        ]
        # generate a csv file with all states user couldn't name
        new_data = pandas.DataFrame(missing_states)
        new_data.to_csv("states_to_learn.csv")
        # exit prompt
        break
    # check in all the states name
    for nb in range(len(us_states_name)):

        # check if user answer match with one of US States name
        if str(answer_state) == str(us_states_name[nb]):
            guessed_states.append(answer_state)
            # write name of the state at the state coor, increase score
            name_on_map = Turtle()
            name_on_map.hideturtle()
            name_on_map.penup()
            name_on_map.goto(us_states_x[nb], us_states_y[nb])
            name_on_map.write(f"{answer_state}", font=("Calibri", 8, "bold"))
            score += 1

turtle.mainloop()
Esempio n. 41
0
# set screen size using setup method
screen.setup(width=600, height=600)
screen.bgcolor("black")
screen.title("Snake Game")
# turn screen tracker off - things are happening in code
# but it is not showing on screen.  screen.update will refresh the screen
# and show what has been happening.
screen.tracer(0)
starting_positions = [(0, 0), (-20, 0), (-40, 0)]
# for movement create an empty list of segments
segments = []

#new turtle 3 20x20 3 squares lined up on the horizon
for position in starting_positions:
    new_segment = Turtle("square")
    new_segment.color("white")
    new_segment.penup()
    new_segment.goto(position)
    segments.append(new_segment)

game_is_on = True
while game_is_on:
    # once all segments have moved calling update
    screen.update()
    # slow the snake down
    time.sleep(0.1)
    # for i in segments:
    #     i.forward(20)
    # change loop so that it goes from last to first, in reverse order
    # use the range type of for loop and pass in start,stop and step
Esempio n. 42
0
from turtle import Turtle, Screen

timmy = Turtle()


def move(user):
    user.forward(100)
    user.right(90)


for i in range(4):
    move(timmy)

screen = Screen()
screen.exitonclick()
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Oct  8 13:14:00 2020

@author: mhimanshu
"""

from turtle import Turtle
r=Turtle()

lenght = 10
dx = 5
for x in range(40):
    lenght = lenght + dx*3
    r.forward(lenght)
    r.left(120)
    r.forward(lenght)
    r.left(120)
    r.forward(lenght)
    r.penup()
    r.forward(dx)
    r.right(60)
    r.forward(dx)
    r.right(180)
    r.pendown()
    

input("enter")
exit()
Esempio n. 44
0
class Pen:
    score_a = 0
    score_b = 0

    def __init__(self):
        self.pen = Turtle()
        self.pen.speed(0)
        self.pen.shape("square")
        self.pen.color("white")
        self.pen.penup()
        self.pen.hideturtle()
        self.pen.goto(0, 260)
        self.pen.write("0       0", align="center", font=("Courier", 24, "normal"))
    
    def a_win(self):
        self.score_a += 1
        self.pen.clear()
        self.pen.write("{}       {}".format(
            self.score_a, self.score_b), align="center", font=("Courier", 24, "normal"))

    def b_win(self):
        self.score_b += 1
        self.pen.clear()
        self.pen.write("{}       {}".format(
            self.score_a, self.score_b), align="center", font=("Courier", 24, "normal"))
Esempio n. 45
0
# A turtle in a big pond that knows your voice

from turtle import Turtle, Screen

print("Creating and Ocean")
ocean = Screen()
ocean.title("Lets find Nemo")

print("Creating a turtle")
bob = Turtle()

print("Defining some commands")


def keyLeft():
    bob.left(45)


def keyRight():
    bob.right(45)


def keyUp():
    bob.forward(20)


def keyDown():
    bob.backward(20)


def keyHome():
Esempio n. 46
0
def init_drawman():
    global t, x_current, y_current
    x_current = 0
    y_current = 0
    t = Turtle()
    t.turtlesize(1)
    t.shape('turtle')
    t.color('darkgreen')
    t.penup()
    t.goto(x_current, y_current)
Esempio n. 47
0
from turtle import Turtle, Screen

tim = Turtle()
screen = Screen()


def move_forwards():
    tim.forward(2)


def move_backwards():
    tim.backward(2)


def counter_clockwise():
    tim.left(5)


def clockwise():
    tim.right(5)


def clear_drawing():
    tim.reset()


screen.listen()
screen.onkey(move_forwards, "w")
screen.onkey(move_backwards, "s")
screen.onkey(counter_clockwise, "a")
screen.onkey(clockwise, "d")
Esempio n. 48
0
# Named Constants
DELTA = 3
MINIMUM = DELTA * 2
CURSOR_SIZE = 20

num_squares = -1

# Gets input for user on the number of squares needed. In this case 100
while num_squares < 1:
    try:
        num_squares = int(input('Input the number of squares: '))
    except ValueError:
        print("please enter an integer.")

    if num_squares < 1:
        print("You must have at least 1 square.")

# Starts Turtle
screen = Screen()
turtle = Turtle("square", visible=False)
turtle.fillcolor("white")

# Uses a loop to stamp the squares into place instead of drawing them.
for size in range(((num_squares - 1) * DELTA) + MINIMUM, MINIMUM - 1, -DELTA):
    turtle.goto(turtle.xcor() + DELTA / 2, turtle.ycor() - DELTA / 2)
    turtle.shapesize(size / CURSOR_SIZE)
    turtle.stamp()

# Closes turtle when the user clicks.
screen.exitonclick()
Esempio n. 49
0
from turtle import Turtle

myTurtle = Turtle()
myWin = myTurtle.getscreen()


def listSum(numlist):
    if len(numlist) == 1:
        return numlist[0]
    else:
        return numlist[0] + listSum(numlist[1:])


def tostr(n, base):
    convertStr = "0123456789ABCDEF"
    if n < base:
        return convertStr[n]
    else:
        return tostr(n // base, base) + convertStr[n % base]


def drawspiral(myTurtle, lineLen):
    if lineLen > 0:
        myTurtle.forward(lineLen)
        myTurtle.right(90)
        drawspiral(myTurtle, lineLen - 5)


#1.
lst = [3, 5, 7, 9]
print(listSum(lst))
        return [3, 4]
    elif opc == 2:
        return [4, 6]
    else:
        return [6, 8]


# Programa principal
[filas, columnas] = menu()

pantalla = Screen()
pantalla.setup(columnas * 50, filas * 50)
pantalla.screensize(columnas * 50, filas * 50)
pantalla.setworldcoordinates(-.5, -.5, columnas + .5, filas + .5)
pantalla.delay(0)

tortuga = Turtle()
tortuga.hideturtle()
simbolo = crea_matriz(filas, columnas)
tablero = crea_matriz(filas, columnas)

temporal1 = None
temporal2 = None
inicializa_tablero(tablero)
rellena_simbolos(simbolo)
dibuja_tablero(tablero, simbolo)

pantalla.onclick(clic)

pantalla.mainloop()
Esempio n. 51
0
# -*- coding: utf-8 -*-
#!/usr/bin/python3
from turtle import Screen, Turtle

pantalla = Screen()
ancho = 625
alto = 425
pantalla.setup(ancho, alto)
pantalla.screensize(ancho - 25, alto - 25)
pantalla.setworldcoordinates(-50, -150, 350, 250)

tortuga = Turtle()
tortuga.speed(1)
tortuga.pensize(3)
tortuga.dot(10)
tortuga.forward(100)
tortuga.dot(10)
tortuga.forward(100)
tortuga.dot(10)
tortuga.forward(100)
tortuga.dot(10)

tortuga.penup()
tortuga.goto(0, 100)
tortuga.pendown()

tortuga.pencolor('red')
tortuga.pensize(5)
tortuga.circle(20)
tortuga.forward(50)
tortuga.pensize(4)
Esempio n. 52
0
from turtle import Turtle, Screen
import turtle as t
timmy = Turtle()
timmy.shape("turtle")
timmy.color("#EA4335")
t.colormode(255)
import random


def random_color():
    r = random.randint(0, 255)
    g = random.randint(0, 255)
    b = random.randint(0, 255)
    random_rgb = (r, g, b)

    # tuple is immutable
    return random_rgb


def draw_circle():
    timmy.pensize(2)
    timmy.left(25)
    timmy.circle(100)
    timmy.speed("fastest")


for walk in range(200):
    timmy.color(random_color())
    draw_circle()
"""
stops when reach the first circle
Esempio n. 53
0
 def add_segment(self, pos):
     new_segment = Turtle('square')
     new_segment.color('white')
     new_segment.penup()
     new_segment.goto(pos)
     self.segments.append(new_segment)
Esempio n. 54
0
from turtle import Turtle, Screen
cursor = Turtle()
screen = Screen()

cursor.shape()


def reset():
    cursor.clear()
    cursor.reset()


def btn_up():
    cursor.fd(5)


def btn_down():
    cursor.back(5)


def btn_left():
    head = cursor.heading() + 5
    cursor.setheading(head)


def btn_right():
    head = cursor.heading() - 5
    cursor.setheading(head)


screen.listen()
 def create_car(self):
     new_car = Turtle("square")
     new_car.shape('square')
     new_car.shapesize(1, 2)
     new_car.color(random.choice(COLORS))
     new_car.penup()
     new_car.goto(300, random.randint(-250, 250))
     self.all_cars.append(new_car)
Esempio n. 56
0
 def add_segment(self, position):
     new_snake = Turtle("square")
     new_snake.color("white")
     new_snake.penup()
     new_snake.goto(position)
     self.segments.append(new_snake)
Esempio n. 57
0
	def __init__ (self,x,y):
		Turtle.__init__(self)
		turtle.register_shape("rectangle",((0,0),(0,y),(x,y),(x,0),(0,0)))
		self.shape("rectangle")
Esempio n. 58
0
from turtle import Turtle
root = Turtle()
root.left(45)
root.forward(60)
root.right(135)
root.forward(80)
root.right(135)
root.forward(110)
root.left(135)
root.forward(80)
print(root.position())
root.left(135)
root.forward(60)
root.penup()
root.setposition(42.43, 42.43)
root.pendown()
root.left(135)
root.forward(30)
root.penup()
root.forward(10)
root.pendown()
root.forward(40)
root.penup()
root.setposition(-35.36, -39.79)
root.pendown()
root.left(180)
root.forward(10)
root.penup()
root.forward(10)
root.pendown()
root.forward(40)
Esempio n. 59
-1
 def __init__(self, w, h):
     Turtle.__init__(self, visible=False)
     self.screen = Screen()
     self.screen.setup(w, h)
     self.speed(0)
     self.penup()
     self.goto(-WINWIDTH//2 + 50, -WINHEIGHT//2 + 20)
     self.pencolor("yellow")
def create_turtles(ne):
    for i in range(ne):
        t = Turtle()
        t.ht()
        t.speed(0)
        t.seth(i * 360.0 / ne)
        t.width(3)
    return s.turtles()