def branching(depth,length,bushiness,leafiness): turtle.resizemode('user') width = random.randint(2,5) trunk = random.randint(2,4) extra = random.randint(15,35) if(bushiness>=0.1 and bushiness<=0.3): turtle.pensize(width) branchColor() drawTree(depth-1,(length+extra)/trunk,bushiness,leafiness) turtle.right(90) drawTree(depth-1,(length+extra)/trunk,bushiness,leafiness) elif(bushiness>0.3 and bushiness<=0.7): turtle.pensize(width) branchColor() drawTree(depth-1,(length+extra)/trunk,bushiness,leafiness) for _ in range(2): turtle.right(45) drawTree(depth-1,(length+extra)/trunk,bushiness,leafiness) else: turtle.pensize(width) branchColor() drawTree(depth-1,(length+extra)/trunk,bushiness,leafiness) for _ in range(3): turtle.right(30) drawTree(depth-1,(length+extra)/trunk,bushiness,leafiness)
def enlarge(): global lengthSize global widthSize turtle.resizemode("user") turtle.shapesize(lengthSize+1,widthSize+1) lengthSize += 1 widthSize += 1
def draw(seq, length): #Interprets a list of '1's and '0's and draws it turtle.resizemode("Auto") turtle.bgcolor("DarkGray") turtle.speed(0) turtle.ht() time.clock() counter, rights, lefts = 0, 0, 0 for x in seq: turtle.pencolor(color[math.floor(counter / len(seq) * len(color)) % len(color)]) counter += 1 os.system('cls') print(loadingbar(counter, len(seq), 20), "| Current color: ", turtle.pencolor(), '\n', "Rights: ", rights, '\n', "Lefts: ", lefts, '\n', "Time: ", datetime.timedelta(seconds=int(time.clock()))) if x == '1': turtle.right(90) rights += 1 else: turtle.left(90) lefts += 1 turtle.forward(length) return turtle.update()
def main(): # Initial params for drawing turtle.resizemode("auto") turtle.delay(0) wn = turtle.Screen() wn.bgcolor("black") wn.title("Maze") wn.setup(800, 800) regex = re.compile(r'\d+') # maze_name = wn.textinput("", "Arquivo de labirinto:") maze_num = wn.numinput("", "Numero de labirinto:") alg_name = wn.textinput( "", "Algoritmo: \nbusca_largura, busca_profundidade,\nbusca_best_first ou busca_Aestrela" ) # path_name = wn.textinput("", "Arquivo de Solução:") path_name = alg_name + "/caminho" + str(int(maze_num)) dimensions, maze = read_maze(maze_num) # Retrieve the path from the file with open("caminhos/" + path_name + ".txt") as f: path = f.readline() path = literal_eval(path) square_size = 650 / len(maze) pen = Pen(square_size) penpath = PenPath(square_size) setup_maze(maze, pen) print_path(path, penpath, maze) wn.tracer(0) turtle.mainloop()
def __init__(self): turtle.Turtle.__init__(self) self.shape("Wall.gif") self.penup() self.speed(0) self.shapesize(2, 2, 2) turtle.resizemode("user")
def show_sharks(self, sharks): self.update_cnt += 1 if UPDATE_EVERY > 0 and self.update_cnt % UPDATE_EVERY != 1: return turtle.clearstamps() draw_cnt = 0 px = {} for shark in sharks: draw_cnt += 1 shark_shape = 'classic' if shark.tracked else 'classic' if DRAW_EVERY == 0 or draw_cnt % DRAW_EVERY == 0: # Keep track of which positions already have something # drawn to speed up display rendering scaled_x = int(shark.x * self.one_px) scaled_y = int(shark.y * self.one_px) scaled_xy = scaled_x * 10000 + scaled_y turtle.color(shark.color) turtle.shape(shark_shape) turtle.resizemode("user") turtle.shapesize(1.5,1.5,1) if not scaled_xy in px: px[scaled_xy] = 1 turtle.setposition(*shark.xy) turtle.setheading(math.degrees(shark.h)) turtle.stamp()
def show_attraction_point(self, att): turtle.color('black') turtle.shape('circle') turtle.fillcolor("") turtle.resizemode("user") turtle.shapesize(1.5, 1.5, 1) turtle.setposition(att) turtle.setheading(0) turtle.stamp() turtle.update()
def reduceSize(): global lengthSize global widthSize turtle.resizemode("user") if lengthSize > 1 and widthSize >1: turtle.shapesize(lengthSize-1,widthSize-1) lengthSize -= 1 widthSize -= 1 else: turtle.shapesize(1,1) lengthSize = 1 widthSize = 1
def drawSquare(self, r, c): blocksize = blockSize = self.width / cols scale = 25 * 1.4 / rows x = mapVal(c, 0, cols, -self.width / 2, self.width / 2) + blockSize / 2 y = mapVal(r, 0, rows, -self.height / 2, self.height / 2) + blockSize / 2 turtle.resizemode("user") turtle.shape("square") turtle.shapesize(scale, scale, 1) turtle.penup() turtle.setpos(x, y) turtle.pendown() turtle.stamp()
def __init__(self, x, y, theta, tx, ty): self.x = x self.y = y self.theta = theta self.targetx = tx self.targety = ty turtle.shape("circle") turtle.resizemode("user") turtle.shapesize(2, 2) turtle.penup() turtle.setpos(self.x * scale, self.y * scale) turtle.seth(self.theta) turtle.speed(0) turtle.pendown()
def drawSquare(self, r, c): self.mat[r][c] = turtle.pencolor() #save pixel in bitmap blocksize = blockSize = self.width / cols scale = 30 * 1.4 / rows x = mapVal(c, 0, cols, -self.width / 2, self.width / 2) + blockSize / 2 y = mapVal(r, 0, rows, -self.height / 2, self.height / 2) + blockSize / 2 turtle.resizemode("user") turtle.shape("square") turtle.shapesize(scale, scale, 1) turtle.penup() turtle.setpos(x, y) turtle.pendown() turtle.stamp()
def __init__(self, *args, **kwargs): """ Args: *args: Variable length arguments list to be passed to Graphic class. At index 2 includes an integer to zoom the rectangles **kwargs: Arbitrary keyword arguments Attributes: zoom (int): an integer to zoom the shape style (tuple): tuple of (font, size, font style) """ Graphic.__init__(self, *args[:2]) self.zoom = args[2] self.style = ('Courier', 15, 'bold') # initialize turtle object turtle.title("Earth") turtle.resizemode("auto") turtle.speed("fastest") turtle.bgcolor("light blue")
def dibujar_turtle(Lista): anchodelapiz = 3 contador_filas = 0 rango_fila = range(len(Lista[0])) #instanciando largo y ancho y velosidad del trasador turtle.screensize(5000, 5000, "white") turtle.tracer(0, 0) turtle.resizemode("auto") #crea objeto ventana para facilitar su uso ventana = turtle.Screen() ventana.bgcolor("lightgreen") ventana.title("Automata Celular - Regla exactamente 1") #crea el lapiz lapiz = turtle.Turtle() lapiz.color("blue") lapiz.pensize(anchodelapiz) lapiz.hideturtle() lapiz.speed(0) #Dos for anidados que divida las listas en sus elementos mas pequeños for fila in Lista: for i in rango_fila: if fila[i] == 1: #Si el caracter es 1 , escribe una cantidad x pixeles hacia la derecha lapiz.fd(anchodelapiz) print(lapiz.pos()) else: #En el caso que el caracter es 0, el lapiz se sube y se mueve una cantidad x de pixeles para luego se rbajado lapiz.penup() lapiz.fd(anchodelapiz) lapiz.pendown() print(lapiz.pos()) #Una vez finalizado el dibujo de una linea, el lapiz vuelve a la posicion inicial pero x pixeles mas abajo contador_filas += -anchodelapiz lapiz.penup() lapiz.goto(0, contador_filas) lapiz.pendown()
def drawboard(board): turtle.setworldcoordinates(-248,-248,0,0) numbers=('1','2','3','4','5','6','7','8') turtle.hideturtle() turtle.speed(0) turtle.penup() turtle.goto(-223,-10) turtle.shape("square") turtle.color("blue") turtle.resizemode("user") turtle.shapesize(25,25,10) for i in range(0,8): turtle.color("black") turtle.write(numbers[i], font=("Arial",15,"normal")) turtle.goto(turtle.xcor()+25, turtle.ycor()) turtle.goto(-240, turtle.ycor()-15) for i, row in enumerate(board): turtle.color("black") turtle.write(numbers[i], font=("Arial",15,"normal")) turtle.goto(turtle.xcor()+19,turtle.ycor()) for column in row: turtle.shape('square') turtle.color("blue") turtle.shapesize(2,2) turtle.stamp() if column==1: turtle.shape("circle") turtle.color("white") turtle.shapesize(1,1) turtle.stamp() turtle.goto(turtle.xcor()+25,turtle.ycor()) elif column==2: turtle.shape("circle") turtle.color("black") turtle.shapesize(1,1) turtle.stamp() turtle.goto(turtle.xcor()+25,turtle.ycor()) else: turtle.goto(turtle.xcor()+25,turtle.ycor()) turtle.goto(-240, turtle.ycor()-25)
def Arrow(txy, ax='X'): a = [0.1, 0, -0.1] b = [-0.1, 0.3, -0.1] tr.up() tr.goto(0, 0) tr.begin_poly() for i in range(2): tr.goto(a[i], b[i]) tr.end_poly() # останавливаем запись p = tr.get_poly() # ссылка на многоугольник tr.register_shape("myArrow", p) tr.resizemode("myArrow") tr.shapesize(1, 2, 1) if (ax == 'X'): # для оси X tr.tiltangle(0) # угол для формы tr.goto(txy[1] + 0.2, 0) # к месту стрелки pw = [int(txy[1]), -1.0] # место для надписи else: # для оси Y else: tr.tiltangle(90) # новый угол для формы tr.goto(0, txy[1] + 0.2) # к месту стрелки pw = [0.2, int(txy[1])] # место для надписи tr.stamp() # оставить штамп - стрелка tr.goto(pw) # к месту надписи tr.write(ax, font=("Arial", 14, "bold"))
def Arrow(txy, ax='X'): a = [0.1, 0, -0.1] b = [-0.1, 0.3, -0.1] tr.up() tr.goto(0, 0) tr.begin_poly() for i in range(2): tr.goto(a[i], b[i]) tr.end_poly() p = tr.get_poly() tr.register_shape("myArrow", p) tr.resizemode("myArrow") tr.shapesize(1, 2, 1) if ax == 'X': tr.tiltangle(0) tr.goto(txy[1] + 0.2, 0) pw = [int(txy[1]), -1.0] else: tr.tiltangle(90) tr.goto(0, txy[1] + 0.2) pw = [0.2, int(txy[1])] tr.stamp() tr.goto(pw) tr.write(ax, font=("Arial", 14, "bold"))
def test_resizemode(self): english_options = ['auto', 'user', 'noresize'] spanish_options = ['auto', 'usuario', 'sin_cambio_de_tamano'] for english_option, spanish_option in zip(english_options, spanish_options): tortuga.resizemode(spanish_option) tortuga.forward(3) tortuga.modo_cambio_tamano(spanish_option) tortuga.forward(3) tortuga.resizemode(english_option) tortuga.forward(3) turtle.resizemode(english_option) turtle.forward(3) turtle.resizemode(english_option) turtle.forward(3) turtle.resizemode(english_option) turtle.forward(3)
def walk(t): global colordict if t.data == "end": sysexit(0) elif t.data == "movement": name, number = t.children { 'ileri': turtle.fd, 'geri': turtle.bk, 'sağ': turtle.lt, 'sol': turtle.rt, }[name](int(number)) elif t.data == "change_color": colors = list() for color in t.children: colors.append(colordict[color.strip()]) try: turtle.color(colors[0], colors[1]) except IndexError: turtle.color(colors[0]) elif t.data == "repeat": count, block = t.children for i in range(int(count)): walk(block) elif t.data == "fill": turtle.begin_fill() walk(t.children[0]) turtle.end_fill() elif t.data == "code_block": for cmd in t.children: walk(cmd) elif t.data == "tsleep": sleep(int(t.children[0])) elif t.data == "backg": turtle.bgcolor(colordict[t.children[0].strip()]) elif t.data == "tup": turtle.up() elif t.data == "tdown": turtle.down() elif t.data == "tspeed": turtle.speed(int(t.children[0])) elif t.data == "treset": turtle.reset() elif t.data == "sclear": # clear screen turtle.clearscreen() elif t.data == "tsize": turtle.pensize(int(t.children[0])) elif t.data == "stitle": turtle.title(t.children[0][1:-1]) elif t.data == "sresize": turtle.setup(int(t.children[0]), int(t.children[1])) elif t.data == "comment": pass # nothing to do with comments elif t.data == "tshape": shape = { "ok": "arrow", "kare": "square", "çember": "circle", "üçgen": "triangle", "klasik": "classic" }[t.children[0].strip()] turtle.shape(shape) elif t.data == "ev": turtle.home() elif t.data == "git": turtle.goto(int(t.children[0]), int(t.children[1])) elif t.data == "tauto": turtle.resizemode("auto") elif t.data == "tcircle": turtle.circle(int(t.children[0])) elif t.data == "tstamp": turtle.stamp() elif t.data == "tclearstamps": turtle.clearstamps()
def draw(self): oldmode = turtle.resizemode() turtle.shapesize(outline=self.diameter) id = super().draw() turtle.resizemode(oldmode) return id
# coding: utf-8 import turtle,math def regular_shape(aturtle, radius, sides): c = 2 * math.pi * radius cs = c / m asp = 360.0 / m for x in range(m): t.seth(0) t.left(asp*x) t.forward(cs) t = turtle.Pen() turtle.resizemode("auto") t.speed=1 lpp=15 print("Numero de filas") n=int(input()) h=float(0) #print("Numero de lados del poligono de la base") circumference = 2 * math.pi * lpp m=n+2 s=n l=1 t.speed=7 while (l<=s): for h in range(0,n): t.pendown() regular_shape(turtle.Turtle(),lpp,m) t.seth(0) t.penup() t.forward(125)
SIZE_Y = 500 turtle.setup(SIZE_X, SIZE_Y) turtle.penup() SQUARE_SIZE = 20 START_LENGTH = 1 pos_list = [] stamp_list = [] food_pos = [] food_stamps = [] turtle.register_shape("clinton2.gif") snake = turtle.clone() snake.shape("clinton2.gif") turtle.resizemode("user") snake.turtlesize(0.5, 0.5, 0.5) turtle.hideturtle() for i in range(START_LENGTH): x_pos = snake.pos()[0] y_pos = snake.pos()[1] x_pos += SQUARE_SIZE my_pos = (x_pos, y_pos) snake.goto(x_pos, y_pos) pos_list.append(my_pos) new_stamp = snake.stamp() stamp_list.append(new_stamp) W_KEY = 'w'
def draw(self): turtle.shapesize(outline=20) draw_shape = super().draw() turtle.resizemode("auto") return draw_shape
def move_down(): canvas.yview_scroll(1, "units") turtle.sety(turtle.ycor() - MAGNIFICATION) screen = Screen() width, height = screen.screensize() screen.screensize(width * MAGNIFICATION, height * MAGNIFICATION) canvas = screen.getcanvas() canvas.config(xscrollincrement=str(MAGNIFICATION)) canvas.config(yscrollincrement=str(MAGNIFICATION)) turtle.width(MAGNIFICATION) turtle.resizemode('auto') screen.onkey(move_left, "Left") screen.onkey(move_right, "Right") screen.onkey(move_up, "Up") screen.onkey(move_down, "Down") screen.listen() screen.mainloop() #_________________________ """3, 4, 5, 7, 11, 13, 17, 23, 29, 43, 47, 83, 131, 137, 359, 431, 433, 449, 509, 569, 571, 2971, 4723, 5387, 9311, 9677, 14431, 25561, 30757, 35999, 37511, 50833, 81839, 104911, 130021, 148091, 201107, 397379, 433781, 590041, 593689, 604711, 931517,
def drawmonsterdetails(mirror, scale, generikmon, startoftoes): detailsbit = generikmon['detail0'] turtle.penup() turtle.goto(startoftoes) turtle.pendown() ### draw the toes webs and claws numofToes = generikmon['numofToes'] fullwidth = turtle.xcor() tailwidth = fullwidth * generikmon['tailbodyratio'] #talibodywidthratio, pawswidth = fullwidth - tailwidth frontpawwidth = pawswidth * generikmon['frontbackratio'] #fronttobackratio toewidth = frontpawwidth / (numofToes) for i in range(numofToes): turtle.setheading(270) turtle.forward(scale * generikmon['toelengthD']) #toelengthD turtle.right(mirror * 90) turtle.forward( mirror * toewidth * 0.1) #mirror required here since xcord is negative on second hlaf # start claw layout calcs xclawstart = turtle.xcor() xclawtip = xclawstart - toewidth * 0.4 xclawend = xclawtip - toewidth * 0.4 yclawstart = turtle.ycor() yclawtip = yclawstart - scale * detailsbit['clawlength'] yclawend = yclawstart #draw claw (it's already at the start) turtle.goto(xclawtip, yclawtip) turtle.goto(xclawend, yclawend) turtle.forward( mirror * toewidth * 0.1) #mirror required here since xcord is negative on second hlaf turtle.right(mirror * 90) turtle.forward(scale * generikmon['toelengthD']) #toelegnth - going back up #into the rear toes. # all lengths scaled by generikmon[16] = frontotbackratio toewidth = (pawswidth - frontpawwidth) / numofToes #redefines toe width for backpaws. for i in range(numofToes): turtle.setheading(270) turtle.forward(scale * generikmon['frontbackratio'] * generikmon['toelengthD']) #toelengthD turtle.right(mirror * 90) turtle.forward( mirror * toewidth * 0.1) #mirror required here since xcord is negative on second hlaf # start claw layout calcs xclawstart = turtle.xcor() xclawtip = xclawstart - toewidth * 0.4 xclawend = xclawtip - toewidth * 0.4 yclawstart = turtle.ycor() yclawtip = yclawstart - scale * detailsbit['clawlength'] * generikmon[ 'frontbackratio'] yclawend = yclawstart #draw claw (it's already at the start) turtle.goto(xclawtip, yclawtip) turtle.goto(xclawend, yclawend) turtle.forward( mirror * toewidth * 0.1) #mirror required here since xcord is negative on second hlaf turtle.right(mirror * 90) turtle.forward(scale * generikmon['frontbackratio'] * generikmon['toelengthD']) #toelegnth - going back up ### draw the ears turtle.penup() turtle.home() turtle.setheading(90) turtle.right(mirror * 90) #requires turtle to be facing upwards turtle.forward(scale * generikmon['crownD']) #crownD follow crown line exactly turtle.left(mirror * generikmon['ear1A']) #ear1A turtle.right(mirror * 90) #turns back into shape. turtle.forward(scale * (generikmon['ear2D'] * 0.1 + 0.01)) startoftheear = turtle.pos() turtle.pendown() # start actually drawing turtle.setheading(90) turtle.right(mirror * 90) turtle.left(mirror * generikmon['ear1A']) #ear1A turtle.forward(scale * generikmon['ear2D'] * 0.8) #ear2D turtle.right(mirror * generikmon['ear3A']) #ear3A turtle.forward(scale * generikmon['ear2D'] * 0.8) #ear2D turtle.right(mirror * generikmon['ear4A']) #ear4A turtle.forward(scale * generikmon['ear6D'] * 0.7) #ear6D turtle.right(mirror * generikmon['ear5A']) #ear5A turtle.forward(scale * generikmon['ear6D'] * 0.7) #ear5D turtle.goto(startoftheear) #finishs the ear off. ### draw the eyes (stamped over ears if needed) turtle.penup() turtle.home() # print(turtle.xcor(),turtle.ycor()) turtle.setheading(90) turtle.right(mirror * 90) #requires turtle to be facing upwards turtle.forward(scale * generikmon['crownD'] * detailsbit['eyeratio']) #crownD, #eyeratio turtle.setheading(270) turtle.forward(scale * generikmon['cheekD'] * (1 - detailsbit['eyeratio'])) #cheekD, #eyeratio turtle.shape("circle") turtle.resizemode("user") turtle.shapesize(detailsbit['eyesize'], detailsbit['eyesize'] * detailsbit['eyeratio'] * 4, 1) # print(turtle.shapesize()) turtle.tilt(mirror * detailsbit['frownA']) turtle.stamp() turtle.tilt(-1 * mirror * detailsbit['frownA'] ) #takes the tilt off the turtle to avoid later confusion turtle.shapesize(1, 1, 1) #takes off the eye size, i think. ### draw the nose turtle.penup() turtle.home() turtle.setheading(270) turtle.forward(scale * generikmon['cheekD']) #cheekD turtle.shape("triangle") turtle.shapesize(detailsbit['nosesize'], detailsbit['nosesize'], 1) turtle.stamp() #and from the nose, the mouth turtle.pendown() turtle.forward(scale * generikmon['shoulderD'] * detailsbit['nosesize'] + detailsbit['nosesize']) #shouldD below the nose turtle.left(mirror * 90) turtle.forward(scale * generikmon['crownD'] * detailsbit['mouthsize']) #crownD #width of mouth turtle.penup() turtle.home() return ()
#Robert C. Plata III Lab 1 8/25/2015 #This program is of a spaceship orbiting the sun. #It isn't moving because the sun is so far away! #The Image was resized to 600 by 600 pixels. #fixed all lab requirements fixed #3rd submit import turtle # bring in code that lets you draw things turtle.bgpic("sun.gif") # specify the name of your background image turtle.resizemode("user") # if you want to let the user to resize the screen turtle.hideturtle() #Ask_User turtle.penup() turtle.goto(0, 250) myColor = input("What color do you want? ") turtle.color(myColor) myTitle = input("What title do you want? ") turtle.write(myTitle, font=("Times", 16, "bold", "normal")) #Turtle_Setting turtle.hideturtle() turtle.pensize(5) # make a thick line turtle.speed("slow") # so you can see it better #Picture_Frame pictureWIDTH = 300 pictureHEIGHT = 300
border.pendown() border.goto(SIZE_X/2,SIZE_Y/2) border.goto(-SIZE_X/2,SIZE_Y/2) border.goto(-SIZE_X/2,-SIZE_Y/2) border.goto(SIZE_X/2,-SIZE_Y/2) border.hideturtle() pygame.init() pygame.mixer.music.load("music.wav") pygame.mixer.music.play(-1) pygame.mixer.music.set_volume(0.3) turtle.hideturtle() turtle.resizemode('user') turtle.penup() UP_ARROW = 'Up' LEFT_ARROW = 'Left' DOWN_ARROW = 'Down' RIGHT_ARROW = 'Right' TIME_STEP = 100 START_LENGTH=1 SPACEBAR = 'space' UP = 0 DOWN = 1 LEFT = 2 RIGHT = 3
def drawmonsterdetails(mirror, scale, generikmon,startoftoes): detailsbit = generikmon['detail0'] turtle.penup() turtle.goto(startoftoes) turtle.pendown() ### draw the toes webs and claws numofToes = generikmon['numofToes'] fullwidth= turtle.xcor() tailwidth= fullwidth*generikmon['tailbodyratio'] #talibodywidthratio, pawswidth= fullwidth-tailwidth frontpawwidth=pawswidth*generikmon['frontbackratio'] #fronttobackratio toewidth=frontpawwidth/(numofToes) for i in range(numofToes): turtle.setheading(270) turtle.forward(scale*generikmon['toelengthD'])#toelengthD turtle.right(mirror*90) turtle.forward(mirror*toewidth*0.1) #mirror required here since xcord is negative on second hlaf # start claw layout calcs xclawstart = turtle.xcor() xclawtip = xclawstart - toewidth*0.4 xclawend = xclawtip - toewidth*0.4 yclawstart = turtle.ycor() yclawtip = yclawstart-scale*detailsbit['clawlength'] yclawend = yclawstart #draw claw (it's already at the start) turtle.goto(xclawtip, yclawtip) turtle.goto(xclawend, yclawend) turtle.forward(mirror*toewidth*0.1) #mirror required here since xcord is negative on second hlaf turtle.right(mirror*90) turtle.forward(scale*generikmon['toelengthD']) #toelegnth - going back up #into the rear toes. # all lengths scaled by generikmon[16] = frontotbackratio toewidth=(pawswidth-frontpawwidth)/numofToes #redefines toe width for backpaws. for i in range(numofToes): turtle.setheading(270) turtle.forward(scale*generikmon['frontbackratio']*generikmon['toelengthD'])#toelengthD turtle.right(mirror*90) turtle.forward(mirror*toewidth*0.1) #mirror required here since xcord is negative on second hlaf # start claw layout calcs xclawstart = turtle.xcor() xclawtip = xclawstart - toewidth*0.4 xclawend = xclawtip - toewidth*0.4 yclawstart = turtle.ycor() yclawtip = yclawstart-scale*detailsbit['clawlength']*generikmon['frontbackratio'] yclawend = yclawstart #draw claw (it's already at the start) turtle.goto(xclawtip, yclawtip) turtle.goto(xclawend, yclawend) turtle.forward(mirror*toewidth*0.1) #mirror required here since xcord is negative on second hlaf turtle.right(mirror*90) turtle.forward(scale*generikmon['frontbackratio']*generikmon['toelengthD']) #toelegnth - going back up ### draw the ears turtle.penup() turtle.home() turtle.setheading(90) turtle.right(mirror*90) #requires turtle to be facing upwards turtle.forward(scale*generikmon['crownD']) #crownD follow crown line exactly turtle.left(mirror*generikmon['ear1A']) #ear1A turtle.right(mirror*90) #turns back into shape. turtle.forward(scale*(generikmon['ear2D']*0.1+0.01)) startoftheear = turtle.pos() turtle.pendown() # start actually drawing turtle.setheading(90) turtle.right(mirror*90) turtle.left(mirror*generikmon['ear1A']) #ear1A turtle.forward(scale*generikmon['ear2D']*0.8) #ear2D turtle.right(mirror*generikmon['ear3A']) #ear3A turtle.forward(scale*generikmon['ear2D']*0.8) #ear2D turtle.right(mirror*generikmon['ear4A']) #ear4A turtle.forward(scale*generikmon['ear6D']*0.7) #ear6D turtle.right(mirror*generikmon['ear5A']) #ear5A turtle.forward(scale*generikmon['ear6D']*0.7) #ear5D turtle.goto(startoftheear) #finishs the ear off. ### draw the eyes (stamped over ears if needed) turtle.penup() turtle.home() # print(turtle.xcor(),turtle.ycor()) turtle.setheading(90) turtle.right(mirror*90) #requires turtle to be facing upwards turtle.forward(scale*generikmon['crownD']*detailsbit['eyeratio']) #crownD, #eyeratio turtle.setheading(270) turtle.forward(scale*generikmon['cheekD']*(1-detailsbit['eyeratio'])) #cheekD, #eyeratio turtle.shape("circle") turtle.resizemode("user") turtle.shapesize(detailsbit['eyesize'],detailsbit['eyesize']*detailsbit['eyeratio']*4,1) # print(turtle.shapesize()) turtle.tilt(mirror*detailsbit['frownA']) turtle.stamp() turtle.tilt(-1*mirror*detailsbit['frownA']) #takes the tilt off the turtle to avoid later confusion turtle.shapesize(1,1,1) #takes off the eye size, i think. ### draw the nose turtle.penup() turtle.home() turtle.setheading(270) turtle.forward(scale*generikmon['cheekD']) #cheekD turtle.shape("triangle") turtle.shapesize(detailsbit['nosesize'],detailsbit['nosesize'],1) turtle.stamp() #and from the nose, the mouth turtle.pendown() turtle.forward(scale*generikmon['shoulderD']*detailsbit['nosesize']+detailsbit['nosesize']) #shouldD below the nose turtle.left(mirror*90) turtle.forward(scale*generikmon['crownD']*detailsbit['mouthsize']) #crownD #width of mouth turtle.penup() turtle.home() return()
volver sobre sí misma hacia abajo estas funciones no estaban definidas en el tutorial. En la declaracion como en el cambio de valor se hace usa declaracion múltiple """ dirUp, dirDown, dirLeft, dirRight = True, True, True, True """ Inicio de la declaración de los objetos del juego (spanglish every where XD) ------------------------------------------------- """ #window config wn = turtle.Screen() wn.title("Snake") wn.bgcolor("black") wn.setup(width=w, height=h) wn.tracer(0) turtle.resizemode("noresize") #head snake head = turtle.Turtle() head.speed(0) #Al iniciar la ventana el objeto ya esta pintado head.shape("square") #Forma del objeto en este caso un cuadrado head.color("white") #Color del objeto head.penup() #Quitar el rastro de movimiento del objeto head.goto(0, 0) #Posición del objeto (0,0) es el centro de la ventana head.direction = "stop" #Dirección inicial de movimiento del objeto #feed feed = turtle.Turtle() feed.speed(0) feed.shape("circle") feed.color("red")
def __setScreen(self): """set the screen/window depending on view static attributes.""" turtle.resizemode('noresize') self.width = self.GRID_MARGINLEFT + 2 * self.gridWidth + self.GAP_BETWEEN_GRIDS + self.GRID_MARGINRIGHT self.height = self.GRID_MARGINTOP + self.gridWidth + self.GRID_MARGINBOTTOM turtle.setup(width=self.width + 10, height=self.height + 10) turtle.screensize(self.width, self.height) turtle.bgpic("Ressources/fire_ocean.gif") turtle.reset()