Beispiel #1
0
def on_walls():
    leftw = -t.window_width() / 2
    rightw = t.window_width() / 2
    topw = t.window_height() / 2
    bottomw = -t.window_height() / 2
    x, y = snake.pos()
    atWall = x <= leftw or x >= rightw or y >= topw or y <= bottomw
    return atWall
Beispiel #2
0
def inside_window():
    l_limit = (-t.window_width() / 2) + 100
    r_llimit = (t.window_width() / 2) - 100
    t_limit = (t.window_width() / 2) - 100
    b_limit = (-t.window_width() / 2) + 100
    (x, y) = t.pos()
    inside = l_limit < x < r_llimit and b_limit < y < t_limit
    return inside
Beispiel #3
0
def outisde_window():
    left_win = -t.window_width() / 2
    right_win = t.window_width() / 2
    top_win = t.window_height() / 2
    bottom_win = -t.window_height() / 2
    (x, y) = caterpillar.pos()
    outside = x < left_win or x > right_win or y > top_win or y < bottom_win
    return outside
Beispiel #4
0
def in_venster():
    limiet_links = (-t.window_width() / 2) + 100
    limiet_rechts = (t.window_width() / 2) + 100
    lenimiet_boven = (t.window_height() / 2) + 100
    limiet_onder = (-t.window_height() / 2) + 100
    (x, y) = t.pos()
    binnen = limiet_links < x < limiet_rechts and limiet_onder < y < limiet_boven
    return binnen
def inside_window():
    left_limit = (-t.window_width() / 2) + 100
    right_limit = (t.window_width() / 2) - 100
    top_limit = (t.window_height() / 2) - 100
    bottom_limit = (-t.window_height() / 2) + 100
    (x, y) = t.pos()
    inside = left_limit < x < right_limit and bottom_limit < y < top_limit
    return inside
Beispiel #6
0
def outside_window():
    left_wall = -t.window_width() / 2  # - because left side
    right_wall = t.window_width() / 2
    top_wall = t.window_height() / 2
    bottom_wall = -t.window_height() / 2
    (x, y) = caterpillar.pos()
    outside = x < left_wall or x > right_wall or y < bottom_wall or y > top_wall
    return outside
def outside_window():
    left_wall = -t.window_width() / 2
    right_wall = t.window_width() / 2
    top_wall = t.window_height() / 2
    bottom_wall = -t.window_height() / 2
    (x, y) = snake.pos()
    outside = x < left_wall or x > right_wall or y < bottom_wall or y > top_wall
    return outside
Beispiel #8
0
def outsideWindow():  # Checks if snake goes out of bounds or not
    leftWall = -t.window_width()/2
    rightWall = t.window_width()/2
    topWall = t.window_height()/2
    bottomWall = -t.window_height()/2

    (x, y) = snake.pos()
    outside = x < leftWall or x > rightWall or y > topWall or y < bottomWall
    return outside
Beispiel #9
0
def outside_window():
    left_wall = -tu.window_width() / 2
    right_wall = tu.window_width() / 2
    top_wall = tu.window_height() / 2
    bottom_wall = -tu.window_height() / 2
    (x, y) = caterpillar.pos()
    outside = x < left_wall or x > right_wall or y > top_wall or y < bottom_wall
    #outside will be TRUE if any of the condition satisfies.
    return outside
def outside_window():
    left_wall = -t.window_width()/2
    right_wall = t.window_width()/2
    top_wall = t.window_height()/2
    bottom_wall = -t.window_height()/2
    (x,y) = c1.pos()
    (x2,y2) = c2.pos()
    outside =         x<left_wall or x2<left_wall or         x>right_wall or x2>right_wall or         y>top_wall or y2>top_wall or         y<bottom_wall or y2<bottom_wall
    return outside
Beispiel #11
0
def draw_land():
    lx = -(t.window_width() / 2 - 10)
    ly = -(t.window_height() / 2 - 20)
    dist = t.window_width() - 20
    t.penup()
    t.setpos(lx, ly)
    t.pendown()
    t.forward(dist)
    t.penup()
Beispiel #12
0
def posicionar_aleatorio():
    '''Posiciona a tartaruga em uma posicao aleatoria da tela'''
    levantar_caneta()
    x = random.randrange(-turtle.window_width() // 2,
                         turtle.window_width() // 2)
    y = random.randrange(-turtle.window_height() // 2,
                         turtle.window_height() // 2)
    andar_ate(x, y)
    abaixar_caneta()
Beispiel #13
0
def outside_window():
    #Stay inside the window
    left_wall = -t.window_width() / 2
    right_wall = t.window_width() / 2
    top_wall = t.window_height() / 2
    bottom_wall = -t.window_height() / 2

    (x, y) = cplr.pos()

    outside = x > right_wall or x < left_wall or y > top_wall or y < bottom_wall
    return outside
 def move(self):
     while math.fabs(self.xcor()) < turtle.window_width() / 2 and math.fabs(
             self.ycor()) < turtle.window_height() / 2:
         self.goto(self.xcor() + self.dx, self.ycor() + self.dy)
     if math.fabs(self.xcor()) >= turtle.window_width() / 2:
         self.dx = 0 - self.dx
         self.goto(self.xcor() + self.dx, self.ycor() + self.dy)
     else:
         self.dy = 0 - self.dy
         self.goto(self.xcor() + self.dx, self.ycor() + self.dy)
     self.move()
Beispiel #15
0
def outside_window():
    left_wall = -t.window_width() / 2
    right_wall = t.window_width() / 2
    top_wall = t.window_height() / 2
    bottom_wall = -t.window_height() / 2
    (x, y) = caterpillar.pos()
    outside = \
            x< left_wall or \
            x> right_wall or \
            y< bottom_wall or \
            y> top_wall
    return outside
def outside_window():
    left_wall = -t.window_width() / 2
    right_wall = t.window_width() / 2
    top_wall = t.window_height() / 2
    bottom_wall = -t.window_height() / 2
    (x, y) = caterpillar.pos()
    outside = \
            x < left_wall or \
            x > right_wall or \
            y < bottom_wall or \
            y > top_wall
    return outside
Beispiel #17
0
def outsideWindow():
    left_boundary = -t.window_width() / 2
    right_boundary = t.window_width() / 2
    top_boundary = t.window_height() / 2
    bottom_boundary = -t.window_height() / 2
    (x, y) = snake.pos()
    outside= \
        x<left_boundary or \
            x>right_boundary or \
                y<bottom_boundary or \
                    y>top_boundary
    return outside
Beispiel #18
0
def buiten_venster():
    muur_links = -t.window_width() / 2
    muur_rechts = t.window_width() / 2
    muur_boven = t.window_height() / 2
    muur_onder = -t.window_height() / 2
    (x, y) = rups.pos()
    buiten = \
        x < muur_links or \
        x > muur_rechts or \
        y < muur_onder or \
        y > muur_boven
    return buiten
Beispiel #19
0
def inside_window():
    left_limit = (-t.window_width() / 2) + 100
    right_limit = (t.window_width() / 2) - 100
    top_limit = (t.window_height() / 2) - 100
    bottom_limit = (-t.window_height() / 2) + 100

    print(left_limit, right_limit, top_limit, bottom_limit)

    (x, y) = t.pos()

    inside = (left_limit < x < right_limit) and (bottom_limit < y < top_limit)

    return inside
Beispiel #20
0
def random_spiral():
    t.pencolor(random.choice(colors))  
    size = random.randint(10,40)        
    x = random.randrange(-turtle.window_width()//2,
                         turtle.window_width()//2)
    y = random.randrange(-turtle.window_height()//2,
                         turtle.window_height()//2)
    t.penup()
    t.setpos(x,y)
    t.pendown()
    for m in range(size):
        t.forward(m*2)
        t.left(91)
def TurtlePainting(Image,filtervalue):
    pix=Image.load()
    #turtle.speed(0)
    turtle.tracer(0)
    turtle.penup()
    width=Image.size[0]
    height=Image.size[1]
    turtle.setup(width,height+30,-turtle.window_width(),-turtle.window_height())
    for i in range(height):
        for j in range(width):
            if pix[j,i][0]<=filtervalue:
                turtle.setpos(j-turtle.window_width()/2,-i+turtle.window_height()/2-10)
                turtle.dot(8)
Beispiel #22
0
def outside_window(): # hàm check khi monster còn trong khung window hay không
    left_wall = -tt.window_width() /2
    right_wall = tt.window_width() /2
    top_wall = tt.window_height() /2
    bottom_wall = -tt.window_height() /2

    (x,y) = monster.pos() # function return two values(a 'tuple')
    outside = \
        x < left_wall or \
        x > right_wall or \
        y < bottom_wall or \
        y > top_wall 
    return outside # if any of 4 above condition true --> outside is true 
Beispiel #23
0
def random_spiral():
    t.pencolor(random.choice(colors))
    size = random.randint(10, 40)
    x = random.randrange(-turtle.window_width() // 2,
                         turtle.window_width() // 2)
    y = random.randrange(-turtle.window_height() // 2,
                         turtle.window_height() // 2)
    t.penup()
    t.setpos(x, y)
    t.pendown()
    for m in range(size):
        t.forward(m * 2)
        t.left(91)
def draw_grid():
    # left down line
    pen.up()
    pen.setpos(-turtle.window_width() / 2 + turtle.window_width() / 3,
               turtle.window_height() / 2)
    pen.setheading(-90)
    pen.down()
    pen.forward(turtle.window_height())

    # right down line
    pen.up()
    pen.setpos(turtle.window_width() / 2 - turtle.window_width() / 3,
               turtle.window_height() / 2)
    pen.setheading(-90)
    pen.down()
    pen.forward(turtle.window_height())

    # up right line
    pen.up()
    pen.setpos(-turtle.window_width() / 2,
               turtle.window_height() / 2 - turtle.window_height() / 3)
    pen.setheading(0)
    pen.down()
    pen.forward(turtle.window_width())

    # down right line
    pen.up()
    pen.setpos(-turtle.window_width() / 2,
               turtle.window_height() / 2 - turtle.window_height() / 3 * 2)
    pen.setheading(0)
    pen.down()
    pen.forward(turtle.window_width())
Beispiel #25
0
def outside_window():
    #通过比较毛毛虫坐标和墙的位置,判断是否出界
    left_wall = -t.window_width() / 2
    right_wall = t.window_width() / 2
    top_wall = t.window_height() / 2
    bottom_wall = -t.window_height() / 2
    #窗口宽度为400,左墙距离中间距离为200,即坐标为-200,同理可得上面四个
    (x, y) = caterpillar.pos()  #一个函数返回两个值(一个元组)
    outside = \
            x < left_wall or \
            x > right_wall or \
            y < bottom_wall or \
            y > top_wall
    return outside  #如果上面有一个条件为TRUE,那么outside为TRUE
Beispiel #26
0
def inside_window():
    #Knowing Limits of X-Axis
    left_limit = (-turtle.window_width()) / 2.0 + 100
    right_limit = (turtle.window_width()) / 2.0 - 100
    #Knowing Limits of Y-Axis
    top_limit = turtle.window_height() / 2.0 - 100
    bottom_limit = (-turtle.window_height()) / 2.0 + 100
    #Get the Cursor Position
    (x, y) = turtle.pos()

    #Check Trutle is inside the Window or not
    inside = (left_limit < x < right_limit)and \
             (bottom_limit < y < top_limit)
    return inside
Beispiel #27
0
def display_score(current_score, current_score2):
    score_turtle.clear()
    score_turtle.penup()
    x = (t.window_width() / 2) - 50
    y = (t.window_height() / 2) - 50
    score_turtle.setpos(x, y)
    score_turtle.write(str(current_score), align='right', \
                       font=('Arial', 40, 'bold'))

    score_turtle.penup()
    x = (t.window_width() / 2) - 350
    y = (t.window_height() / 2) - 50
    score_turtle.setpos(x, y)
    score_turtle.write(str(current_score2), align='right', \
                       font=('Arial', 40, 'bold'))
Beispiel #28
0
def random_spiral():
    # Generate spirals of random sizes/colors at random locations
    t.pencolor(random.choice(colors))  # Pick a random color
    size = random.randint(10, 40)  # Pick a random spiral size
    # Generate a random (x,y) location on the screen
    x = random.randrange(-turtle.window_width() // 2,
                         turtle.window_width() // 2)
    y = random.randrange(-turtle.window_height() // 2,
                         turtle.window_height() // 2)
    t.penup()
    t.setpos(x, y)
    t.pendown()
    for m in range(size):
        t.forward(m * 2)
        t.left(91)
Beispiel #29
0
    def draw(self):
        jerry.goto((jerry.window_width()/2)-40,(jerry.window_height()/2)-40)
        jerry.setheading(0)
        jerry.pendown()
        jerry.pencolor(self.color)
        jerry.pensize(20)

        jerry.backward(jerry.window_width()-80)
        jerry.right(-90)
        jerry.backward(jerry.window_height()-80)
        jerry.right(-90)
        jerry.backward(jerry.window_width()-80)
        jerry.right(-90)
        jerry.backward(jerry.window_height()-80)
        jerry.penup()
Beispiel #30
0
def scored(current_score):
    score.clear()
    score.penup()
    x = (t.window_width() / 2) - 50
    y = (t.window_height() / 2) - 50
    score.setpos(x, y)
    score.write(str(current_score), align='right', font=('Arial', 18, 'bold'))
 def __init__(self, world_size, beacons):
     self.beacons = beacons
     self.width = int(world_size)
     self.height = int(world_size)
     turtle.setworldcoordinates(0, 0, self.width, self.height)
     self.update_cnt = 0
     self.one_px = float(turtle.window_width()) / float(self.width) / 2
Beispiel #32
0
def display_score(current_score):
    score_turtle.clear()
    score_turtle.penup()
    x = (t.window_width()/2) - 50
    y = (t.window_height()/2) - 100
    score_turtle.setposition(x,y)
    score_turtle.write(str(current_score),align='right',font=('arial',40,'bold'))
Beispiel #33
0
def draw_demo(turtle):
    width = turtle.window_width()
    height = turtle.window_height()
    cell_size = min(width/8.5, height/7)
    turtle.up()
    turtle.back(width*.475)
    turtle.left(90)
    turtle.forward(height*0.4)
    turtle.right(90)
    turtle.down()

    state1 = """\
3|6 2|0 2
        -
5 3 1|2 3
- -
3 1 4|3 6
        -
5|5 6|6 1
"""
    draw_diagram(turtle, state1, cell_size, solution=True)

    turtle.right(90)
    turtle.forward(cell_size*7)
    turtle.left(90)
Beispiel #34
0
def displayscore(currscore):
    score.clear()
    score.penup()
    x = (t.window_width() / 2) - 50
    y = (t.window_height() / 2) - 50
    score.setpos(x, y)
    score.write(str(currscore), align='right', font=('Arial', 40, 'bold'))
def display_score(current_score):
    score_turtle.clear()
    score_turtle.penup()
    x = (t.window_width() / 2) - 50
    y = (t.window_height() / 2) - 50
    score_turtle.setpos(x, y)
    score_turtle.write(str(current_score), align='right', font=('Arial', 40, 'bold'))
	def __init__(self):

		# Getting width and height of turtle window
		self.screenWidth = turtle.window_width()
		self.screenHeight = turtle.window_height()

		self.wait = 3	# Time to wait before turtle window closes
Beispiel #37
0
def pressed_keys():
    """
    sig: () -> NoneType
    function for when the user presses the up, down, left, right, 'j', 'i', 'k', or 'l' key
    """
    turtle.color("black")
    global waves
    objects.clear()
    global length
    global width
    global bounce_once_avg
    global bounce_twice_avg
    bounce_once_avg = 0
    bounce_twice_avg = 0
    turtle.clear()
    store_objects()
    turtle.listen()
    init_waves()
    store_objects()
    waves.clear()
    draw_speaker()
    draw_audience()
    turtle.color("black")
    draw_wall()
    turtle.up()
    turtle.goto(-turtle.window_width() / 2 + 10,
                turtle.window_height() / 2 - 200)
    turtle.down()
    msg = "Press 's' when ready to see new sound waves"
    turtle.write(msg, font=("Arial", 20, "normal"))
    draw_wall()
 def starting_positions(self, y):
     """
     Lets get the turtles in their starting positions!
     """
     self.penup()
     self.setx(-turtle.window_width()/2)
     self.sety(y)
     self.pendown()
Beispiel #39
0
 def render(self):
     turtle.up()
     w=turtle.window_width()
     self.dist=w/len(self.string)
     turtle.back(w/2)
     turtle.shape("turtle")
     for c in self.string:
         self.draw(c)
     turtle.hideturtle()
     turtle.exitonclick()        
def setGoal(turtle) :
	turtle.pencolor("Black")
	turtle.color("Black")
	turtle.clear()
	rangeX=turtle.window_width()/2-110
	rangeY=turtle.window_height()/2-110
	pos=(random.uniform(-rangeX, rangeX), random.uniform(-rangeY, rangeY))
	drawSquare(turtle, pos, 100)
	turtle.pencolor("WHITE")
	turtle.color("WHITE")
	return pos
Beispiel #41
0
    def __init__(self):
        print("initializing board")
        self.board = turtle.Turtle()
        screen = self.board.getscreen()
        self.w = turtle.window_width()
        self.h = turtle.window_height()  # room for display
        self.boardHeight = self.h - self.textDisplayHeight

        # make the symbol sizes relative to the board width
        self.oSymbolRadius = math.floor(0.09 * self.w)

        screen.setworldcoordinates(0, 0, turtle.window_width(), turtle.window_height())
        self.board.hideturtle()
        self.board.speed(0)
        self.board.pensize(3)
        self.board.pencolor("blue")
        turtle.speed(0)
        turtle.title("Tic Tac Toe")

        self.drawBoard()
    def test_bounds_after_monkey_patch(self):
        # SETUP
        expected_width = 300
        expected_height = 200

        # EXEC
        MockTurtle.monkey_patch(canvas=Canvas(expected_width, expected_height))
        width = turtle.window_width()
        height = turtle.window_height()

        # VERIFY
        self.assertEqual(expected_width, width)
        self.assertEqual(expected_height, height)
Beispiel #43
0
 def __init__(self, N):
     # timer value in milliseconds
     self.deltaT = 10
     # get window dimensions
     self.width = turtle.window_width()
     self.height = turtle.window_height()
     # create spiro objects
     self.spiros = []
     for i in range(N):
         # generate random parameters
         rparams = self.genRandomParams()
         # set spiro params
         spiro = Spiro(*rparams)
         self.spiros.append(spiro)
     # call timer
     turtle.ontimer(self.update, self.deltaT)
Beispiel #44
0
 def __init__(self, N):
     #set value of timer in millis
     self.deltaT = 10
     #get window dimensions
     self.width = turtle.window_width()
     self.height = turtle.window_height()
     #create spiros
     self.spiros = []
     for i in range(N):
         #generate random parameters
         rparams = self.genRandomParams()
         #set spiro parameters
         spiro = Spiro(*rparams)
         #add new spiro to array
         self.spiros.append(spiro)
     #set the ontimer method to call update() every deltaT millis
     turtle.ontimer(self.update, self.deltaT)
Beispiel #45
0
    def __init__(self, maze):
        self.maze = maze
        self.width   = len(maze[0])
        self.height  = len(maze)
        turtle.setworldcoordinates(0, 0, self.width, self.height)
        self.blocks = []
        self.update_cnt = 0
        self.one_px = float(turtle.window_width()) / float(self.width) / 2

        self.beacons = []
        for y, line in enumerate(self.maze):
            for x, block in enumerate(line):
                if block:
                    nb_y = self.height - y - 1
                    self.blocks.append((x, nb_y))
                    if block == 2:
                        self.beacons.extend(((x, nb_y), (x+1, nb_y), (x, nb_y+1), (x+1, nb_y+1)))
Beispiel #46
0
def Sierpinsmod(size,mod,alto=1024,ancho=700,dx=4):
    r=1.0*dx  
    pp=dx  # Grueso de los puntos
    turtle.colormode(1)
    turtle.ht()
   
    turtle.speed("fastest")
    turtle.tracer(False)
    turtle.penup()
    turtle.home()
    ox = -(turtle.window_width()/2)+2*dx
    oy = (turtle.window_height()/2)-2*dx
 
    P=Pascal(size,mod)

    turtle.setpos(ox,oy)
   
    turtle.dot(pp,clr(P[0][0],mod))
    turtle.seth(90)
   
    for d in range(1,2*size-1):
        print("iniciando diagonal ",d),
        if d< size:
            initx=0  # Posiciones iniciales
            inity=d
        else:
            initx = d-size+1
            inity = size-1
       
        turtle.setpos(ox+initx*dx-dx,oy-inity*dx-dx)
 
        for k in range(initx,inity+1):  
            # Recorremos la diagonal de suma d
            # Los puntos corresponden a (k, d-k)
            turtle.right(90)
            turtle.forward(dx)
            turtle.left(90)
            turtle.forward(dx)
            t=P[k][d-k]
            if t > 0:
                turtle.dot(pp, clr(t,mod))
        if d % 20 ==0: turtle.update()        
Beispiel #47
0
import turtle

t = turtle.Pen()
t.hideturtle()

LARGEUR_ECRAN = turtle.window_width()
HAUTEUR_ECRAN = turtle.window_height()

def ligne(t, a, b, couleur):
  etat_precedent = t.pen()
  t.penup()
  t.goto(a)
  t.pendown()
  t.color(couleur)
  t.goto(b)
  t.pen(etat_precedent)

t.speed("fastest")

pas = 20

for x in range(-LARGEUR_ECRAN, LARGEUR_ECRAN, pas):
  ligne(t, (0, 0), (x, -HAUTEUR_ECRAN), "blue")
  ligne(t, (0, 0), (x, HAUTEUR_ECRAN), "yellow")

for y in range(-HAUTEUR_ECRAN, HAUTEUR_ECRAN, pas):
  ligne(t, (0, 0), (-LARGEUR_ECRAN, y), "red")
  ligne(t, (0, 0), (LARGEUR_ECRAN, y), "green")

raw_input();
#project3.py

import turtle
WIDTH = turtle.window_width() / 2.3


def convertXY(origX, origY, width): #converts original x,y coordinates from txt file and scale them to size of window
       x=origX*width
       y=origY*width
       return (x,y)
       
def drawStar(origX, origY, t, brightness, col): #draws each star, with brightness times a factor of 3/10
       scrCoords=convertXY(origX,origY,WIDTH)
       t.color(col)
       t.up()
       t.goto(scrCoords)
       t.down()
       t.begin_fill()
       t.circle(.3*brightness)
       t.end_fill()
       
       
def drawLine(origX1, origY1, origX2, origY2, t, col): #calls convertXY, then draws line between two stars
       scrCoords1=convertXY(origX1,origY1,WIDTH)
       scrCoords2=convertXY(origX2,origY2,WIDTH)
       t.color(col)
       t.penup()
       t.goto(scrCoords1)
       t.pendown()
       t.goto(scrCoords2)
       
import random
import turtle
t = turtle.Pen()
t.speed(0)
turtle.bgcolor('black')
colors=['red', 'yellow', 'blue', 'green', 'orange', 'purple', 'white', 'gray']
for n in range(50):
    # generate spirals of random sizes/colors at random locations on the screen
    t.pencolor(random.choice(colors))   # pick a random color from colors[]
    size = random.randint(10,40)        # random size spiral from 10 to 40
    sides = random.randint(3,9)        # random number of sides in spiral
    thick = random.randint(1,6)         # random thickness of the lines
    t.width(thick)
    angle = t.heading()
    # generate a random (x,y) location on the screen
    x = random.randrange(size,turtle.window_width()//2)
    y = random.randrange(size,turtle.window_height()//2)
    # first spiral
    t.penup()
    t.setpos(x,y)
    t.pendown()
    for m in range(size):
        t.forward(m*2)
        t.left(360/sides + 2)
    # second spiral
    t.penup()
    t.setpos(-x,y)
    t.pendown()
    t.setheading(180-angle)
    for m in range(size):
        t.forward(m*2)
    t.end_fill()
    # Left eye
    t.setpos(x-15, y+60)
    t.fillcolor("blue")
    t.begin_fill()
    t.circle(10)
    t.end_fill()
    # Right eye
    t.setpos(x+15, y+60)
    t.begin_fill()
    t.circle(10)
    t.end_fill()
    # Mouth
    t.setpos(x-25, y+40)
    t.pencolor("black")
    t.width(10)
    t.goto(x-10, y+20)
    t.goto(x+10, y+20)
    t.goto(x+25, y+40)
    t.width(1)

for n in range(50):
    x = random.randrange(-turtle.window_width()//2,
                         turtle.window_width()//2)
    y = random.randrange(-turtle.window_height()//2,
                         turtle.window_height()//2)
    draw_smiley(x,y)


    
#Tara Moses
#Assignment 8: Snowflake Fractal
#February 4, 2013

#1. Program draws a snowflake fractal depending on the user-specified fractal order.
#2. Program fills the snowflake with a certain user-specified color.

import turtle,Tkinter

order=int(raw_input("What order fractal would you like? "))
snowflake_color=raw_input("What color would you like it to be? ")

screen_width=turtle.window_width()-50.0
screen_height=turtle.window_height()-50.0


top_corner_x=-1*(screen_width/2.0)
top_corner_y=screen_height/2.0

directions="srsrs"
length=300.0

turtle.speed(0)
if order>4:
    turtle.tracer(3)
turtle.dot()
turtle.up()
turtle.goto(-150, 90)
turtle.down()
turtle.fillcolor(snowflake_color)
turtle.fill(True)
Beispiel #52
0
import sys
import turtle

wn = turtle.Screen()
wn.bgcolor('lightblue')

snake = turtle.shape("circle")
turtle.pensize(10)
turtle.penup()

cherry = 10
t = 0
x, y = 0, 0
Vsnake = 10
xlimit, ylimit = turtle.window_width() / 2.5, turtle.window_height() / 2.5

def move():
    global x, y, Vsnake, t, cherry
    t = t + 1
    turtle.forward(Vsnake)
    turtle.stamp();

    if cherry > 0:
        cherry = cherry - 1
    else:
        turtle.clearstamps(1)


    turtle.ontimer(move, 100)
turtle.ontimer(move, 100)
turtle.bgcolor("black")  # 애러('bgcolor' 를 turtle 라이버리에서 찾을 수 없음.)
colors = ["red", "yellow", "blue", "green", "orange", "purple", "white", "gray"]


def fff():
    for m in range(size):
        t.forward(m * 2)
        t.left(91)


def ddd(dfd1, dfd2):
    t.penup()
    t.setpos(dfd1, dfd2)
    t.pendown()


for n in range(50):
    t.pencolor(random.choice(colors))
    size = random.randint(10, 40)
    x = random.randrange(0, turtle.window_width() // 2)  # 문제1('window_width'를 turtle 라이버리에서 찾을 수 없음)
    y = random.randrange(0, turtle.window_height() // 2)  # 문제('window height'를 turtle 라이버리에서 찾을 수 없음)
    ddd(x, y)
    fff()
    ddd(-x, y)
    fff()
    ddd(-x, -y)
    fff()
    ddd(x, -y)
    fff()
input(":::...")
def move_right():
    w = turtle.window_width()
    if t.xcor() < w/2 - 10:      
        t.seth(0)
        t.forward(10)
    t.fillcolor('yellow')
    t.begin_fill()
    t.circle(50)
    t.end_fill()
    # Left Eye
    t.setpos(x-15, y+60)
    t.fillcolor('blue')
    t.begin_fill()
    t.circle(10)
    t.end_fill()
    # Right Eye
    t.setpos(x+15, y+60)
    t.begin_fill()
    t.circle(10)
    t.end_fill()
    # Mouth
    t.setpos(x-25,y+40)
    t.pencolor('black')
    t.width(10)
    t.goto(x-10, y+20)
    t.goto(x+10, y+20)
    t.goto(x+25, y+40)
    t.width(1)

for n in range(50):
    x = random.randrange(int(-turtle.window_width()/2 + 50),
                         int(turtle.window_width()/2 - 50))
    y = random.randrange(int(-turtle.window_height()/2),
                         int(turtle.window_height()/2) - 100)
    draw_smiley(x,y)
import turtle
import random
import winsound


wn = turtle.Screen()
print(wn.screensize())


#wn.bgcolor("#808000")
#wn.bgcolor("lightgreen")
wn.bgcolor("orange")
print(turtle.window_height(), turtle.window_width())
#turtle.setup(width=_CFG["width"], height=_CFG["height"], startx=_CFG["leftright"], starty=_CFG["topbottom"])
#turtle.setup(width=_CFG["width"], height=_CFG["height"], startx=_CFG["leftright"], starty=_CFG["topbottom"])

tess = turtle.Turtle()
tess.shape("turtle")
tess.color("blue")

wn.textinput("NIM", "Name of first player:")
tid_i_sekunder = wn.numinput("Poker", "Your stakes:", 1000, minval=10, maxval=10000)
tid_i_sekunder = int(tid_i_sekunder)
tess.penup()                # This is new
tess.pendown()

print(turtle.turtles())
#turtle.screensize(canvwidth=None, canvheight=None, bg=None)
size = 1
turtle.colormode(255)
for i in range(tid_i_sekunder):
turtle2 = TurtleRacer('Leonardo')
turtle3 = TurtleRacer('Raphaelo')

# Lets set the starting positions so they don't collide.
turtle1.starting_positions(-100)
turtle2.starting_positions(0)
turtle3.starting_positions(100)

# We can store extra stuff in objects. Lets put the turtles here so we can loop through them.
screen.turtles = [turtle1, turtle2, turtle3]

# We need this to tell us if the race finished
finished = False


while not finished:

    for turtle_racer in screen.turtles:

        turtle_racer.forward(random.randint(1,10))

        if turtle_racer.xcor() >= turtle.window_width() // 2:

            turtle_racer.home()
            turtle_racer.write(turtle_racer.name + ' won!', font=('arial', 24, 'bold'))
            turtle_racer.do_a_360()
            finished = True
            break

turtle.exitonclick()
Beispiel #58
0
import turtle

turtle.showturtle()

WINDOW_WIDTH = turtle.window_width()
WINDOW_HEIGHT=turtle.window_height()

tile_width = WINDOW_WIDTH/10
tile_height = WINDOW_HEIGHT/10

turtle.up()

turtle.setx(-WINDOW_WIDTH/2)
turtle.sety(WINDOW_HEIGHT/2)

# draw vertical lines
turtle.setheading(270)
for x in range(-WINDOW_WIDTH/2, WINDOW_WIDTH/2):
	# draw a line every tile_height pixels
	if (x % tile_width)==0:
		# draw a horizontal line
		turtle.setx(x)
		turtle.down()
		turtle.forward(WINDOW_HEIGHT)
		turtle.up()
		turtle.sety(WINDOW_HEIGHT/2)

# draw horizontal lines
turtle.setheading(0)
for y in range(-WINDOW_HEIGHT/2, WINDOW_HEIGHT/2):
	# draw a line every tile_height pixels
def move_left():
    w = turtle.window_width()
    if t.xcor() > -w/2 + 10:
        t.seth(180)
        t.forward(10)
Beispiel #60
0
    turtle.up()
    turtle.goto(point1)
    turtle.down()
    turtle.goto(point2)
    turtle.goto(point3)
    turtle.goto(point1)

if __name__ == '__main__':

    padding = 30
    level_count = 6

    triangle_list = []

    turtle.setup()
    side_length = min(turtle.window_height(), turtle.window_width()) - padding

    point2 = (side_length / 2, -(turtle.window_height() / 2 - padding))
    point3 = (-side_length / 2, -(turtle.window_height() / 2 - padding))

    x2,y2 = point2
    y1 = (side_length ** 2 - (side_length / 2) ** 2) ** 0.5 + y2

    point1 = (0, y1)

    draw_triangle(point1, point2, point3)

    triangle_list.append((point1, point2, point3))

    for i in range(level_count):