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 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)
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 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 show(): turtle.hideturtle() turtle.speed(0) side = turtle.window_height()/7 grid(side) write(side) turtle.exitonclick()
def setup(): turtle.hideturtle() turtle.tracer(1e3,0) turtle.left(90) turtle.penup() turtle.goto(0,-turtle.window_height()/2) turtle.pendown()
def set(): #set of parameters turtle.hideturtle() turtle.tracer(1e3,1) turtle.left(95) turtle.penup() turtle.goto(0,-turtle.window_height()/2) turtle.pendown()
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)
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
def display_score(current_score): score_t.clear() score_t.penup() x = (t.window_width() / 2) - 50 y = (t.window_height() / 2) - 50 score_t.setpos(x, y) score_t.write(str(current_score), align='right', font=('Arial', 50, 'bold'))
def __init__(self, N): self.deltaT = 10 self.width = turtle.window_width() self.height = turtle.window_height() self.spiros = [] for i in range(N): rparams = self.genRandomParams() spiro = Spiro(*rparams) self.spiros.append(spiro) turtle.ontimer(self.update, self.deltaT)
def screen_reset(myPen): # Paints over image with white, "reseting" the screen myPen.penup() myPen.goto(boxSize/2 - turtle.window_width()/2, turtle.window_height()/2) myPen.color("#FFFFFF") myPen.pendown() myPen.begin_fill() for i in range(4): myPen.forward(1000) myPen.left(-90) myPen.end_fill()
def gameOverText(): x = (t.window_width() / 2) - 300 y = (t.window_height() / 2) - 150 t.setpos(x, y) t.write("Game Over", move=False, align='center', font=("Arial",30,"bold","underline")) t.hideturtle() te.hideturtle() tf.hideturtle() tf.clear() te.clear()
def display_score(current_score): score_turtle.clear() score_turtle.penup() x = (t.window_width() / 2) - 30 y = (t.window_height() / 2) - 50 score_turtle.setpos(x, y) score_turtle.color('blue') score_turtle.write(str(current_score), align='right', font=('Arial', 40, 'bold'))
def prepareTurtle(): # turtle.speed(0) # turtle.radians() # turtle.degrees() turtle.tracer(0, 0) turtle.hideturtle() turtle.left(90) turtle.penup() turtle.goto(0, -turtle.window_height() / 3) turtle.pendown()
def ksp(num1 = 20): #万花筒 ''' num1 -- How many kaleidoscopes do you want(num1 * 4) size -- How long is the spiral sides -- How many sides does the spiral have thick -- The turtle_pen's thick x/y -- Where is the spiral angle -- The turtle_pen's heading ''' colors = ["red", "yellow", "blue", "green", "orange", "purple", "white", "gray"] for n in range(num1): t.pencolor(random.choice(colors)) size = random.randint(15,35) sides = random.randint(4,7) thick = random.randint(1,4) x = random.randrange(size,turtle.window_width()//2) #选择随机x坐标 y = random.randrange(size,turtle.window_height()//2) #选择随机y坐标 angle = t.heading() #角度数据 #第一个螺旋线 t.penup() t.setpos(x,y) t.pendown() t.width(thick) t.setheading(angle) #设置角度 for m in range(size): t.forward(m * 2) t.left(360 / sides + 1) #第二个螺旋线 t.penup() t.setpos(-x,y) t.pendown() t.width(thick) t.setheading(180 - angle) #设置角度 for m in range(size): t.forward(m * 2) t.left(360 / sides + 1) #第三个螺旋线 t.penup() t.setpos(-x,-y) t.pendown() t.width(thick) t.setheading(angle - 180) #设置角度 for m in range(size): t.forward(m * 2) t.left(360 / sides + 1) #第四个螺旋线 t.penup() t.setpos(x,-y) t.pendown() t.width(thick) t.setheading(360 - angle) #设置角度 for m in range(size): t.forward(m * 2) t.left(360 / sides + 1) turtle.done()
def resetTopLeft(): """Remet la tortue en haut à gauche oriente vers l'est. pre: La tortue `tortue` est initialisée. post: La tortue est placée en haut à gauche et orienté vers l'est """ tortue.penup() tortue.setx(-turtle.window_width()//2) tortue.sety(turtle.window_height()//2) tortue.pendown()
def koch_flake(i, delka): t.up() t.setx(-t.window_width() * 4 / 5 / 2) t.sety(t.window_height() / 4) t.down() koch_rek(i, delka) t.right(120) koch_rek(i, delka) t.right(120) koch_rek(i, delka)
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 __checkrelease(self, event): mouse_x = event.x - (turtle.window_width() / 2) mouse_y = (turtle.window_height() / 2) - event.y if (self.__state == "btn_active" and self.__is_hover(mouse_x, mouse_y)): self.__state = "btn_hover" self.__color_by_state() if (self.__callback != None): self.__callback() if (self.__autodest): self.destroy()
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
def SCORES(game_score): #update scores turtle_score.clear() turtle_score.penup() x = (t.window_width() / 2) - 53 y = (t.window_height() / 2) - 42 turtle_score.setpos(x, y) turtle_score.write(str(game_score), align="right", font=("Arial", 19, "italic"))
def __init__(self, N): self.deltaT = 10 # set the timer value in milliseconds # get the window dimensions self.width = turtle.window_width() self.height = turtle.window_height() self.spiros = [] # create the Spiro objects for i in range(N): rparams = self.genRandomParams() # 产生随机数据 spiro = Spiro(*rparams) # set the spiro parameters self.spiros.append(spiro) turtle.ontimer(self.update, self.deltaT) # call timer
def rsp(num1 = 25): #随机螺旋图形 ''' num1 -- How many random spirals do you want x/y -- Where is the spiral size -- How long is the spiral ''' colors = ['red','blue','purple','pink','orange','yellow','gray','white'] for a in range(num1): 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 b in range(size): t.forward(b * 2) t.left(91) turtle.done()
def update_puzzle(): # Clear the drawing and show the updated puzzle t.clear() t.write(" ".join(display), align="center", font=FONT) t.goto(-(t.window_width() / 3), t.window_height() / 3) t.write("Wrong letters: " + "".join(wrong_letters), align="left", font=FONT_SIZE / 2) t.home() t.update( ) # Show changes. Required since the tracer is off (see t.tracer above).
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()
def drawSnowflakeScene(): """ Setup the canvas for drawing the snowflake and draw it.""" # pick up the pen and move the turtle so it starts at the bottom left of the canvas turtle.penup() # change the pen color turtle.pencolor("deep pink") turtle.goto(-turtle.window_width()/2 + 70, -turtle.window_height()/2 + 200) turtle.pendown() # draw the snowflake by calling your function drawSnowflake(150, 1) # pick up the pen and move the turtle so it goes to the top middle of the canvas turtle.penup() # change the pen color turtle.pencolor("firebrick") # change the fill color turtle.fillcolor("dark orchid") turtle.goto(0, turtle.window_height()/2 - 200) turtle.pendown() # start filling in turtle.begin_fill() # draw the snowflake by calling your function drawSnowflake(150, 3) # end filling in turtle.end_fill() # pick up the pen and move the turtle so it goes to the bottom left of the canvas turtle.penup() # change the pen color turtle.pencolor("rosy brown") turtle.goto(turtle.window_width()/2 - 70, -turtle.window_height()/2 + 250) turtle.pendown() # draw the snowflake by calling your function drawSnowflake(150, 2) # finished turtle.done()
def draw_grid(im): from values import dist #A var to keep what row the turtle is on row = 0 #Draws Columns for i in range(im.size[0] - 1): tur.penup() tur.forward(dist) tur.pendown() tur.right(90) tur.forward(im.size[1] * dist) tur.left(180) tur.forward(im.size[1] * dist) tur.right(90) #Move back to the start tur.penup() tur.goto(-turtle.window_width()//2, turtle.window_height()//2) tur.pendown() #Draws Rows for i in range(im.size[1] - 1): tur.penup() tur.right(90) tur.forward(dist) tur.left(90) tur.pendown() tur.forward(im.size[0] * dist) tur.left(180) tur.forward(im.size[0] * dist) tur.left(180) row += dist #Move back to the start tur.penup() tur.goto(-turtle.window_width()//2, turtle.window_height()//2 - dist) tur.pendown() return row
def draw_board(): board_drawer = turtle.Turtle() board_drawer.speed(20) board_drawer.pensize(20) board_drawer.color("white") for i in range(2): board_drawer.penup() board_drawer.goto( turtle.window_width() / 8 - turtle.window_width() / 4 * i, turtle.window_height() / 3) board_drawer.pendown() board_drawer.setheading(270) board_drawer.forward(turtle.window_height() * 2 / 3) for i in range(2): board_drawer.penup() board_drawer.goto( turtle.window_height() / 3, turtle.window_width() / 8 - turtle.window_width() / 4 * i) board_drawer.pendown() board_drawer.setheading(180) board_drawer.forward(turtle.window_height() * 2 / 3)
def house_pos(n): """ sig: int -> (int, int) Each numbered house in the game has a position. Given a houses number, this function returns the x,y location of its lower-left corner """ width = turtle.window_width() height = turtle.window_height() x = (((n + 1) // 2) * (-1)**(n % 2)) * (HOUSE_WIDTH * 2) y = -height / 2 + 50 return (x, y)
def draw_cross(xcor, ycor): #sig: int,int -> NoneType ''' Draws a cross centered at the input x and y cordinates. The size is according to the size of the position on the board. ''' turtle.up() turtle.color("red") turtle.setposition((xcor - (turtle.window_width() / 6)), (ycor + (turtle.window_height() / 6))) turtle.down() turtle.setposition((xcor + (turtle.window_width() / 6)), (ycor - (turtle.window_height() / 6))) turtle.up() turtle.setposition((xcor + (turtle.window_width() / 6)), (ycor + (turtle.window_height() / 6))) turtle.down() turtle.setposition((xcor - (turtle.window_width() / 6)), (ycor - (turtle.window_height() / 6))) turtle.up() turtle.color("black") turtle.setheading(0)
def __checkhover(self, event): mouse_x = event.x - (turtle.window_width() / 2) mouse_y = (turtle.window_height() / 2) - event.y if (self.__is_hover(mouse_x, mouse_y)): if (self.__state is "btn_normal"): self.__state = "btn_hover" self.__color_by_state() else: if (self.__state is not "btn_normal"): self.__state = "btn_normal" self.__color_by_state()
def run(): global bloom, width max_width = min(t.window_width(), t.window_height()) if width <= 0 and not bloom: bloom = True if width >= max_width and bloom: bloom = False width += (1 if bloom else -1) t.clear() figures.square(-width // 2, -width // 2, width, "red", "red") t.update() t.ontimer(run, 1000 // 24) # 24 fps
def draw_smiley(x,y): t.penup() t.setpos(x,y) t.pendown() #Head. t.pencolor("yellow") 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.fillcolor("blue") 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)
def draw_board(board): """ signature: list(str) -> NoneType Given the current state of the game, draws the board on the screen, including the lines and the X and O pieces at the position indicated by the parameter. """ turtle.clear() draw_lines() pos_lst = [(-turtle.window_width()//3,turtle.window_height()//3),(0,turtle.window_height()//3),\ (turtle.window_width()//3,turtle.window_height()//3),(-turtle.window_width()//3,0),\ (0,0),(turtle.window_width()//3,0),(-turtle.window_width()//3,-turtle.window_height()//3),\ (0,-turtle.window_height()//3),(turtle.window_width()//3,-turtle.window_height()//3)]#list of cordinates of all positions. for i in range( len(board) ): #goes through the positions on the board, drawing Xs and Os where required. if board[i] == "X": draw_cross(pos_lst[i][0], pos_lst[i][1]) elif board[i] == "O": draw_circle(pos_lst[i][0], pos_lst[i][1]) turtle.setposition(0, 0) turtle.update()
def draw_lines(): #sig: None -> NoneType ''' Draws the lines according to the size of the window. ''' turtle.up() turtle.setposition(turtle.window_width() / 6, turtle.window_height() / 2) turtle.right(90) turtle.down() turtle.forward(turtle.window_height()) turtle.up() turtle.setposition(turtle.window_width() / (-6), turtle.window_height() / 2) turtle.down() turtle.forward(turtle.window_height()) turtle.up() turtle.left(90) turtle.setposition(turtle.window_width() / -2, turtle.window_height() / 6) turtle.down() turtle.forward(turtle.window_width()) turtle.up() turtle.setposition(turtle.window_width() / -2, turtle.window_height() / (-6)) turtle.down() turtle.forward(turtle.window_width()) turtle.up()
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)
def __init__(self, n): self.delta_t = 10 # timer value in milliseconds # Get the window's dimensions self.window_width = turtle.window_width() self.window_height = turtle.window_height() # create the spiro objects self.spiros = [] for i in range(n): # Generate random params rparams = self._get_random_params() spiro = Spiro(*rparams) self.spiros.append(spiro) turtle.ontimer(self.update, self.delta_t)
def display_score(current_score): #Display score in the top right corner #this function only displays the score. score keeping is done in the main funcion loop score_turtle.clear() score_turtle.penup() x = (t.window_width() / 2) - 50 y = (t.window_height() / 2) - 50 #set turtle to x, y coordinates score_turtle.setpos(x, y) #display the score as a string score_turtle.write(str(current_score), align='right', font=('Arial', 40, 'normal'))
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() # @UndefinedVariable height = turtle.window_height() # @UndefinedVariable # VERIFY self.assertEqual(expected_width, width) self.assertEqual(expected_height, height)
def physics(): global ballx, bally global ballvx, ballvy global user1points, user2points ballx += ballvx bally += ballvy if ballx >= turtle.window_width() / 2: #Reflects ball back to the center if the ball hits right wall ballvx = -ballvx #(Actual reflection) if ballx <= -turtle.window_width() / 2: #Reflects ball back to the center if the ball hits left wall ballvx = -ballvx #(Actual reflection) if bally >= (turtle.window_height() / 2.25) - 32 and user1x - 50 <= ballx <= user1x + 50: #Reflects ball back towards center if the ball hits the top paddle based on the length of the paddle and position of ball ballvy = -ballvy #(Actual reflection) if bally <= (turtle.window_height() / -2.55) + 4 and user2x - 50 <= ballx <= user2x + 50: #Relects ball back towards center if the ball hits the bottom paddle based on the length of paddle and position of ball ballvy = -ballvy if user2x - 50 <= ballx <= user2x: ballvx = (-1 / 2) * ballvx #reflects ball back Left else: ballvx = 2 * ballvx #Reflects ball back right if bally > turtle.window_height() - 300: #If the ball is higher than the frame, player is given point and ball resets user2points += 1 reset() if bally < -turtle.window_height() + 300: #If the ball is lower than the frame, AI is given point and ball resets user1points += 1 reset()
def test_bounds_after_monkey_patch(): expected_width = 300 expected_height = 200 MockTurtle.monkey_patch(canvas=Canvas(expected_width, expected_height)) try: width = turtle.window_width() height = turtle.window_height() finally: MockTurtle.remove_monkey_patch() assert width == expected_width assert height == expected_height
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)
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)
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()
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)
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):
def hpy_d792d795d791d7945fd797d79cd795d79f(): """החזר את גובה החלון""" return turtle.window_height()
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):
#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)
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(":::...")
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();
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)
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
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.right(360/sides + 2)
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)
#!/Library/Frameworks/Python.framework/Versions/3.2/bin/python3.2 """Logoclok "CLOCK",", (screen saver)","","LOGOCLOK" "SCREEN SAVER",", (analog clock)","","LOGOCLOK" """ import math import datetime import turtle R = turtle.window_height()//2-8 def tick_lines(): """Tick lines around the face.""" for t in range(60): ha_r= math.radians(90-t*6) y_t_o = R*math.sin( ha_r ) x_t_o = R*math.cos( ha_r ) if t % 5 == 0: # Long thick mark each minute turtle.pensize(3) y_t_i = .95*R*math.sin( ha_r ) x_t_i = .95*R*math.cos( ha_r ) else: # Short thin mark each second turtle.pensize(1) y_t_i = .97*R*math.sin( ha_r ) x_t_i = .97*R*math.cos( ha_r ) turtle.penup(); turtle.goto( x_t_i, y_t_i ) turtle.pendown(); turtle.goto( x_t_o, y_t_o )
def move_down(): h = turtle.window_height() if t.ycor() > -h/2 + 10: t.seth(270) t.forward(10)
def move_up(): h = turtle.window_height() if t.ycor() < h/2 - 10: t.seth(90) t.forward(10)
def printDetails(lastAction): global personList, multipleNotShown print("\n\n\nLast action - "+str(lastAction)) print("Last actions: "+str(lastActions)) print("Current Shape - "+currentShape) print("Erase - "+str(erase)) print("Last Count - "+str(lastCount)) print("Select family - "+str(selectFamily)) print("Current family list: ") for p in currentFamilyList: print(p[0].informativeOutput()) print("Person list: ") for i, p in personList.iteritems(): #print("i: "+str(i)+" center: "+str(p[1])+" size: "+str(p[2])+" "+str(p[0].idNumber)) print(p[0].informativeOutput()) # make this stuff print out on the turtle window in bottom left windowPosX = -turtle.window_width()/2+100 windowPosY = -turtle.window_height()/2+100 turtle.goto(windowPosX, windowPosY) # clear any text that was there before drawEraseShape(185) turtle.goto(windowPosX-50, windowPosY-50) if(selectFamily == True): helpString = "Select family members\n" if(unaffectedMate): helpString += "\nOnly 1 parent is shown\n" helpString += "m: cancel" outString = helpString+"\nCurrent family members: \n\n" for i,p in enumerate(currentFamilyList): if(i%10 == 0): outString += "\n" outString += str(p[0].idNumber)+" " turtle.write(outString, font=("Arial", 16, "normal")) else: helpString = "Current shape: "+currentShape if(affected): helpString += "\nAffected = True" helpString += "\nHelp:\n"+\ "c: draw circle\n"+\ "s: draw square\n"+\ "d: draw diamond\n"+\ "a: draw affected\n"+\ "p: select family\n"+\ "o: select family with 1 parent shown\n"+\ "click: draw person\n"+\ "l: save to csv\n"+\ "u: undo\n"+\ "q: quit\n\n" if(multipleNotShown != 0): helpString += "multiple not shown: "+str(multipleNotShown) turtle.write(helpString, font=("Arial", 14, "normal"))