def draw_circle(x,y): turtle.penup() turtle.goto(x,y) turtle.pendown() turtle.begin_fill() turtle.circle(10) turtle.end_fill()
def passeio(dim, lado, passos): # Prepara grelha turtle.speed(0) grelha_2(dim,lado) turtle.color('red') turtle.home() turtle.pendown() # Passeio turtle.speed(6) turtle.dot() turtle.showturtle() lim_x = lim_y = (dim*lado)//2 cor_x = 0 cor_y = 0 for i in range(passos): vai_para = random.choice(['N','E','S','W']) if (vai_para == 'N') and (cor_y < lim_y): cor_y += lado turtle.setheading(90) turtle.fd(lado) elif (vai_para == 'E') and (cor_x < lim_x): cor_x += lado turtle.setheading(0) turtle.fd(lado) elif (vai_para == 'S') and (cor_y > -lim_y): cor_y -= lado turtle.setheading(270) turtle.fd(lado) elif (vai_para == 'W') and (cor_x > -lim_x): cor_x -= lado turtle.setheading(180) turtle.fd(lado) else: print((vai_para,turtle.xcor(),turtle.ycor())) continue
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 drawLine(self,color,coord1,coord2): """ dessine une ligne entre deux coordonné sur la grille :param color: La couleur de la ligne :param coord1: La première coordonné en tuple (i,j,"joueur") :param coord2: La deuxième coordonné en tuple (i,j,"joueur") """ if coord1[2] == coord2[2] and coord2[2] == "you": turtle.goto(38+coord1[1]*25,87-25*coord1[0]) elif coord1[2] == coord2[2] and coord2[2] == "enemy": turtle.goto(-262+(25*coord1[1]),87-25*coord1[0]) else: print('wrong player') return 0 turtle.pensize(20) turtle.pencolor(color) if coord1[1] == coord2[1]: #Vertical turtle.pendown() turtle.setheading(270) turtle.fd((coord2[0]-coord1[0])*25) elif coord1[0] == coord2[0]: #horizontal turtle.pendown() turtle.setheading(0) turtle.fd((coord2[1]-coord1[1])*25) else: print('Ligne non Hori ou Vert') return 0 turtle.penup() return 1
def drawP(size): turtle.setheading(90) turtle.penup() turtle.forward(size*1.5); turtle.pendown() turtle.forward(size*0.5); drawSemi(size, direction="right", degrees=336, colour="black")
def draw(cmds, size=2): #output tree stack = [] for cmd in cmds: if cmd=='F': turtle.forward(size) elif cmd=='-': t = random.randrange(0,7,1) p = ["Red","Green","Blue","Grey","Yellow","Pink","Brown"] turtle.color(p[t]) turtle.left(15) #slope left elif cmd=='+': turtle.right(15) #slope right t = random.randrange(0,7,1) #рандомная пер. для цвета p = ["Red","Green","Blue","Grey","Yellow","Pink","Brown"] #ряд цветов turtle.color(p[t]) #выбор цвета из ряда elif cmd=='X': pass elif cmd=='[': stack.append((turtle.position(), turtle.heading())) elif cmd==']': position, heading = stack.pop() turtle.penup() turtle.setposition(position) turtle.setheading(heading) turtle.pendown() turtle.update()
def polygon(side = 50, angle = None, xstart = None, ystart = None, numberSides = 3, color = 'black', fill = False): turtle.pensize(3) turtle.speed('fastest') turtle.hideturtle() if angle != None: turtle.left(angle) turtle.penup() if fill == True: if xstart != None or ystart != None: turtle.goto(xstart, ystart) else: turtle.goto(0, 0) turtle.color(color) turtle.pendown() turtle.begin_fill() turtle.circle(side, 360, numberSides) turtle.end_fill() turtle.penup() else: turtle.goto(xstart, ystart) turtle.color(color) turtle.pendown() turtle.circle(side, 360, numberSides) turtle.penup() return
def forGlory(sideLength=50): turtle.left(150) turtle.penup() turtle.setpos(-25,75) turtle.color("blue") turtle.pendown() hexagon(sideLength)
def drawLine(x1, y1, x2, y2, color = "black", size = 1): turtle.color(color) turtle.pensize(size) turtle.penup() turtle.goto(x1, y1) turtle.pendown() turtle.goto(x2, y2)
def entrance(pointOne): turtle.goto(pointOne[0], pointOne[1] + 36) turtle.setheading(270) turtle.pendown() turtle.forward(15) turtle.penup() drawArrows()
def drawS(turtle, height, width): """ draw the letter S using turtle, with some height and width """ # Pick pen up and move a little to the right turtle.penup() turtle.setheading(0) turtle.forward((1.0/6.0)*width) # Put pen down and draw bottom of S turtle.pendown() turtle.forward((2.0/3.0)*width) # Draw first curve turtle.left((180.0/math.pi)*math.atan((3.0/2.0)*height/width)) turtle.forward(math.sqrt(((1.0/6.0)*width)**2+((1.0/4.0)*height)**2)) turtle.left(180.0-(360.0/math.pi)*math.atan((3.0/2.0)*height/width)) turtle.forward(math.sqrt(((1.0/6.0)*width)**2+((1.0/4.0)*height)**2)) turtle.left((180.0/math.pi)*math.atan((3.0/2.0)*height/width)) # Draw middle of S turtle.forward((2.0/3.0)*width) # Draw second curve turtle.right((180.0/math.pi)*math.atan((3.0/2.0)*height/width)) turtle.forward(math.sqrt(((1.0/6.0)*width)**2+((1.0/4.0)*height)**2)) turtle.right(180.0-(360.0/math.pi)*math.atan((3.0/2.0)*height/width)) turtle.forward(math.sqrt(((1.0/6.0)*width)**2+((1.0/4.0)*height)**2)) turtle.right((180.0/math.pi)*math.atan((3.0/2.0)*height/width)) # Draw top of S, pick up pen, and move a little to the right turtle.forward((2.0/3.0)*width) turtle.penup() turtle.forward((1.0/6.0)*width)
def draw_star(size, color): turtle.pendown() turtle.begin_fill() turtle.color(1,1,1) turtle.forward(2.5) turtle.left(size) turtle.forward(2.5) turtle.right(144) turtle.forward(2.5) turtle.left(size) turtle.forward(2.5) turtle.right(144) turtle.forward(2.5) turtle.left(size) turtle.forward(2.5) turtle.right(144) turtle.forward(2.5) turtle.left(size) turtle.forward(2.5) turtle.right(144) turtle.forward(2.5) turtle.left(size) turtle.forward(2.5) turtle.right(144) turtle.end_fill() turtle.penup()
def draw(self): turtle.penup() turtle.goto(self.point_st) turtle.pendown() turtle.color(self.border_c, self.fill_c) self._draw()
def at(x, y): turtle.penup() turtle.home() turtle.forward(x) turtle.left(90) turtle.forward(y) turtle.pendown()
def curva(simbolos,identificador,linea): p1= obtener_punto(1,identificador,simbolos) p2= obtener_punto(2,identificador,simbolos) x1 = int (obtener_x(p1,simbolos)) y1 = int (obtener_y(p1,simbolos)) x2 = obtener_x(p2,simbolos) y2 = obtener_y(p2,simbolos) rotar = obtener_rotar(identificador, simbolos,linea) escalar = obtener_escalar(identificador, simbolos,linea) relleno = obtener_color(obtener_relleno(identificador,simbolos,linea)) turtle.color(relleno) tx = obtener_tx(identificador, simbolos,linea) ty = obtener_ty(identificador, simbolos,linea) potencia = obtener_potencia(identificador,simbolos) #Trasladar recta x1 = int(x1*44 + tx*44) x2 = int(x2*44 + tx*44) y1 = y1*44 + ty*44 y2 = y2*44 + ty*44 turtle.penup() for x in range(x1,x2): turtle.goto(x+(44), (x+(44))**potencia) turtle.pendown()
def circunferencia(simbolos,identificador,linea): p1= obtener_punto(2,identificador,simbolos) radio = obtener_radio(identificador,simbolos) x1 = obtener_x(p1,simbolos) y1 = obtener_y(p1,simbolos) escalar = obtener_escalar(identificador, simbolos,linea) relleno = obtener_color(obtener_relleno(identificador,simbolos,linea)) borde = obtener_color(obtener_borde(identificador,simbolos,linea)) turtle.color(borde) if escalar == 0: escalar=1 tx = obtener_tx(identificador, simbolos,linea) ty = obtener_ty(identificador, simbolos,linea) turtle.pensize(8) turtle.penup() #Trasladar circunferencia x1 = x1 + tx y1 = y1 + ty #turtle.setposition(x1, y1-(radio*44)) #turtle.pendown() #turtle.circle(radio*44) #Escalar circunferencia turtle.penup() #turtle.setposition(x1, y1-(radio*44*escalar)) turtle.setposition(x1*44, (y1*44)-(radio*44*escalar)) turtle.pendown() turtle.fillcolor(relleno) turtle.begin_fill() turtle.circle(radio*44*escalar) turtle.end_fill()
def draw_path(self, positions): ''' Draws the path given by a position list ''' def position_to_turtle(pos): '''Converts a maze position to a turtle position''' return (home_x + _DRAW_SIZE * pos[0], home_y - _DRAW_SIZE * pos[1]) # Get maze size width, height = self.size # Prepare turtle home_x = (-(_DRAW_SIZE * width) / 2) + (_DRAW_SIZE / 2) home_y = ((_DRAW_SIZE * height) / 2) - (_DRAW_SIZE / 2) turtle.showturtle() turtle.pencolor(_DRAW_PATH) # Move to star turtle.penup() turtle.goto(home_x, home_y) turtle.pendown() # Draw the path for pos in positions: turtle.goto(position_to_turtle(pos))
def main(): file_name = "go" file_name = raw_input( 'Enter a file name or exit to quit program: ') while (file_name != "exit" and file_name != "Exit" and file_name != "quit" and file_name != "Quit"): f = open( file_name, 'r' ) first_line = f.readline() first_line = first_line.split() distance = float( first_line[0] ) angle = float( first_line[1] ) stack = [] wn = tur.Screen() for line in f: wn.clear() tur.penup() tur.seth(90) tur.setx(0) tur.sety(-200) tur.pendown() interprit_line(tur, line, angle, distance, stack) ts = tur.getscreen() ts.getcanvas().postscript(file=file_name +".eps") wn.exitonclick() file_name = raw_input( 'Enter a file name or exit to quit program: ')
def draw_rectangle(length_float, width_float, color_str): """ Asks for the length, width, and color of the rectangle and draws it using turtle Recieve: The length, width and color of the triangle Return: Nothing Algorithm: Use a for loop and draw a rectangle by going forward the specified length and making a 90 degree turn to the right and then going forward the width and turning 90 degrees to the right Then do the loop again """ turtle.fillcolor(color_str) turtle.pendown() turtle.begin_fill() for i in range(2): turtle.forward(length_float) turtle.right(90) turtle.forward(width_float) turtle.right(90) turtle.end_fill() turtle.penup()
def dope_flowers(x, y): turtle.pendown() turtle.begin_fill() move(turtle, 100) flower(turtle, 10, 20.0, 60.0) turtle.end_fill() turtle.penup()
def tegnGitter(i0,i1,j0,j1): """Gitteret har søjler fra i0 til og med i1 og rækker fra j0 til og med j1. Først blankstilles lærredet""" xmin,ymin = toXY(i0,j0) xlen,ylen = (i1-i0+2)*cs,(j1-j0+2)*cs tt.clear() tt.penup() tt.color(kodefarve[4]) # vandrette linjer x,y = xmin-cs/2,ymin tt.setheading(0) # øst for j in range(j0,j1+2): tt.goto(x,y) tt.pendown() tt.forward(xlen) tt.penup() y += cs # lodrette linjer x,y = xmin,ymin-cs/2 tt.setheading(90) # nord for i in range(i0,i1+2): tt.goto(x,y) tt.pendown() tt.forward(ylen) tt.penup() x += cs
def drawPoint(x, y): turtle.penup() # Pull the pen up turtle.goto(x, y) turtle.pendown() # Pull the pen down turtle.begin_fill() # Begin to fill color in a shape turtle.circle(3) turtle.end_fill() # Fill the shape
def main(): ap = ArgumentParser() ap.add_argument('--speed', type=int, default=10, help='Number 1-10 for drawing speed, or 0 for no added delay') ap.add_argument('program') args = ap.parse_args() for kind, number, path in parse_images(args.program): title = '%s #%d, path length %d' % (kind, number, path.shape[0]) print(title) if not path.size: continue pen_up = (path==0).all(axis=1) # convert from path (0 to 65536) to turtle coords (0 to 655.36) path = path / 100. turtle.title(title) turtle.speed(args.speed) turtle.setworldcoordinates(0, 655.36, 655.36, 0) turtle.pen(shown=False, pendown=False, pensize=10) for i,pos in enumerate(path): if pen_up[i]: turtle.penup() else: turtle.setpos(pos) turtle.pendown() turtle.dot(size=10) _input('Press enter to continue') turtle.clear() turtle.bye()
def drawCircleAt(turtleX, turtleY, circleSize): turtle.penup() turtle.goto(turtleX,turtleY) turtle.pendown() turtle.begin_fill() turtle.circle(circleSize) turtle.end_fill()
def rectangle(length = 50, width = 30, x = 0, y = 0, color = 'black', fill = False): turtle.pensize(3) turtle.speed('fastest') turtle.hideturtle() if fill == True: turtle.color(color) for i in range(width): turtle.setposition(x, (y+i)) turtle.pendown() turtle.setposition((x+length), (y+i)) turtle.penup() else: turtle.penup() turtle.goto(x,y) turtle.color(color) turtle.pendown() turtle.forward(length) turtle.left(90) turtle.forward(width) turtle.left(90) turtle.forward(length) turtle.left(90) turtle.forward(width) turtle.left(90) turtle.penup() return
def draw_grid(ll,ur): size = ur - ll for gridsize in [1, 2, 5, 10, 20, 50, 100 ,200, 500]: lines = (ur-ll)/gridsize # print('gridsize', gridsize, '->', int(lines)+1, 'lines') if lines <= 11: break turtle.color('gray') turtle.width(1) x = ll while x <= ur: if int(x/gridsize)*gridsize == x: turtle.penup() turtle.goto(x, ll-.25*gridsize) turtle.write(str(x),align="center",font=("Arial",12,"normal")) turtle.goto(x,ll) turtle.pendown() turtle.goto(x,ur) # print(x,ll,'to',x,ur) x += 1 y = ll while y <= ur: # horizontal grid lines: if int(y/gridsize)*gridsize == y: turtle.penup() turtle.goto(ll-.1*gridsize, y - .06*gridsize) turtle.write(str(y),align="right",font=("Arial",12,"normal")) turtle.goto(ll,y) turtle.pendown() turtle.goto(ur,y) # print(ll,y,'to',ur,y) y += 1
def draw_vertrect(length,width,color): turtle.pendown() turtle.color(color) turtle.begin_fill() #uses color to determine length of cross if(color=="blue" or color == "red" or color == "light coral" or color=="yellow"): length*=.4375 elif(color == "snow"or color=="navy" ): length*=.42857 else: length*=.375 print("the length of the first " , length, " and the width is ", width) #loops to draw vertical rectangle for x in range(5): if(x%5==0): #draws first half of left vertical line turtle.forward((length)) print("drawing length") #draws from top of vertical to bottom of flag elif(x%2==0): turtle.forward(length*2+width) print("drawing long side") #draws small side of vertical rectangle elif(x!=5): turtle.forward(width) turtle.right(90) turtle.end_fill()
def drawFins(size): turtle.fillcolor("red") turtle.setheading(90) turtle.begin_fill() turtle.forward(0.2*size) turtle.left(120) turtle.forward(0.6*size) turtle.right(120) turtle.forward(0.3*size) turtle.right(40) turtle.forward(0.8*size) turtle.end_fill() turtle.setheading(0) turtle.begin_fill() turtle.penup() turtle.forward(size) turtle.pendown() turtle.begin_fill() turtle.right(50) turtle.forward(0.8*size) turtle.right(40) turtle.forward(0.3*size) turtle.right(120) turtle.forward(0.6*size) turtle.end_fill()
def draw_rectangle(x,y,width,height): """ Draws a rectangle with the upper left hand corner starting at point (x,y). The said rectangle has the dimensions width x height. :param x: :param y: :param width: :param height: :return: None """ turtle.penup() turtle.setx(x) turtle.sety(y) turtle.pendown() turtle.setheading(0) # Set heading in x+ direction turtle.begin_fill() turtle.begin_poly() turtle.fd(width) turtle.right(90) turtle.fd(height) turtle.right(90) turtle.fd(width) turtle.right(90) turtle.fd(height) turtle.end_poly() turtle.end_fill() return None
def draw_rectangle(): Fline = line.split() if Fline[1] == 'not_int': print(Fline) print("I'm sorry, I cannot understand that integer") return if len(Fline) < 4: print(Fline) print("I'm sorry, I do not understand that value") return x = int(Fline[1]) y = int(Fline[2]) width = int(Fline[3]) height = int(Fline[4]) turtle.penup() turtle.setpos(x, y) turtle.setheading(0) turtle.pendown() turtle.begin_fill() turtle.forward(width) turtle.setheading(-90) turtle.forward(height) turtle.setheading(180) turtle.forward(width) turtle.setheading(90) turtle.forward(height) turtle.end_fill()
def drawLine(x1, y1, x2, y2): turtle.penup() turtle.goto(x1, y1) turtle.pendown() turtle.goto(x2, y2)
def gotoxy(x, y): turtle.penup() turtle.goto(x, y) turtle.pendown()
def right_click(x, y): t.fillcolor("black") t.penup() t.goto(x, y) t.pendown() t.stamp()
turtle.forward(20) turtle.left(90) turtle.forward(20) turtle.right(90) turtle.penup() turtle.forward(20) turtle.left(90) turtle.forward(20) turtle.pendown() A = str(input()) i = 0 turtle.penup() turtle.goto(-300, 0) turtle.pendown() while i < len(A): if A[i] == '0': print0() elif A[i] == '1': print1() elif A[i] == '2': print2() elif A[i] == '3': print3() elif A[i] == '4': print4() elif A[i] == '5': print5() elif A[i] == '6': print6()
def rest1(): turtle.penup() turtle.goto(0, 0) turtle.pendown()
screen.setup(800, 800) t.shape("turtle") t.bgcolor('black') t.speed(25) angle = int(num) if not num in fig: temp = r.randint(0,2) num = case[temp] for x in range(182): t.pencolor(fig[num][x%6]) t.width(x/100+1) t.forward(x) t.left(angle) maxX = t.xcor() maxY = t.ycor() t.penup() t.goto (-350, 350) t.pendown() #t.pencolor(fig['30'][r.randint(0,5)]) t.pencolor('white') t.hideturtle() t.write('Угол поворота: ' + num) t.penup() t.goto (t.xcor() + 50, t.ycor() + 30) t.showturtle() t.mainloop()
def absolute_bewegung_ohne_zu_zeichnen(x, y): turtle.penup() turtle.setx(x) turtle.sety(y) turtle.pendown()
def curlingline(x1 , y1): turtle.penup() turtle.goto(x1,y1+100) turtle.pencolor('black') turtle.back(400) turtle.pendown() turtle.fd(800) turtle.right(180) turtle.fd(32) turtle.right(90) turtle.fd(16) turtle.back(32) turtle.fd(8) turtle.left(90) turtle.fd(8) turtle.right(90) turtle.fd(16) turtle.right(90) turtle.fd(8) turtle.right(180) turtle.fd(738) turtle.right(90) turtle.fd(8) turtle.back(32) turtle.fd(8) turtle.right(90) turtle.fd(8) turtle.left(90) turtle.fd(16) turtle.back(16) turtle.right(90) turtle.fd(722) turtle.right(180) turtle.fd(32) turtle.right(90) turtle.fd(108) turtle.back(200) turtle.fd(100) turtle.left(90) turtle.fd(672) turtle.right(90) turtle.fd(100) turtle.back(200) turtle.fd(100) turtle.right(90) turtle.fd(60) turtle.right(90) turtle.fd(100) turtle.back(200) turtle.fd(100) turtle.left(90) turtle.fd(552) turtle.right(90) turtle.fd(100) turtle.back(200) turtle.fd(100) turtle.right(90) turtle.fd(200) turtle.right(90) turtle.fd(100) turtle.back(200) turtle.fd(100) turtle.left(90) turtle.fd(352) turtle.right(180) turtle.fd(200) turtle.left(90) turtle.fd(100) turtle.back(200) turtle.fd(100) turtle.left(90) turtle.fd(140)
def key_d(): t.pendown()
def drawLine(draw): darwGap() turtle.pendown() if draw else turtle.penup() turtle.fd(40) darwGap() turtle.right(90)
def main(): # Set up window turtle.setup(800, 800, 0, 0) turtle.title( "I wanted Ozzy's 'Crazy Train' to play over this because" + " this thing would derail horribly if it ever managed to move.") turtle.speed(1) turtle.pensize(2) # Draw tracks turtle.penup() turtle.goto(-400, -300) turtle.pendown() turtle.goto(400, -300) turtle.penup() turtle.goto(400, -305) turtle.pendown() turtle.goto(-400, -305) # Draw sleepers x = -388 for i in range(16): turtle.penup() turtle.goto(x, -305) turtle.pendown() turtle.goto(x, -310) turtle.goto(x + 25, -310) turtle.goto(x + 25, -305) x += 50 # Draw car body turtle.color("blue") turtle.penup() turtle.goto(-350, -200) turtle.pendown() turtle.goto(-350, 200) turtle.goto(-75, 200) turtle.goto(-75, 220) turtle.goto(-375, 220) turtle.goto(-375, 200) turtle.goto(-375, 200) turtle.goto(-100, 200) turtle.goto(-100, -200) turtle.goto(-100, 100) turtle.goto(300, 100) turtle.goto(300, -200) turtle.goto(275, -200) turtle.penup() turtle.goto(175, -200) turtle.pendown() turtle.goto(75, -200) turtle.penup() turtle.goto(-25, -200) turtle.pendown() turtle.goto(-125, -200) turtle.penup() turtle.goto(-325, -200) turtle.pendown() turtle.goto(-350, -200) # Draw whistle turtle.penup() turtle.goto(-25, 100) turtle.pendown() turtle.goto(-25, 120) turtle.goto(25, 120) turtle.goto(25, 130) turtle.goto(0, 130) turtle.goto(0, 120) turtle.goto(50, 120) turtle.goto(50, 100) # Draw chimney turtle.penup() turtle.goto(125, 100) turtle.pendown() turtle.goto(100, 175) turtle.goto(112, 200) turtle.goto(188, 200) turtle.goto(200, 175) turtle.goto(100, 175) turtle.goto(200, 175) turtle.goto(175, 100) # Draw cylinder at front of train turtle.penup() turtle.goto(300, 50) turtle.pendown() turtle.goto(325, 50) turtle.goto(325, -50) turtle.goto(335, -50) turtle.goto(335, 0) turtle.goto(325, 0) turtle.goto(325, -100) turtle.goto(300, -100) # Draw cowcatcher turtle.goto(300, -175) turtle.goto(310, -175) turtle.goto(375, -275) turtle.goto(300, -275) turtle.goto(300, -175) # Draw decorations on car turtle.penup() turtle.goto(-100, -40) turtle.pendown() turtle.goto(300, -40) turtle.goto(300, -50) turtle.goto(-100, -50) turtle.penup() turtle.goto(-10, 100) turtle.pendown() turtle.goto(-10, -40) turtle.goto(0, -40) turtle.goto(0, 100) turtle.goto(200, 100) turtle.goto(200, -40) turtle.goto(210, -40) turtle.goto(210, 100) # Draw horizontal rivets x = -97 turtle.penup() for i in range(50): turtle.goto(x, -45) turtle.dot(5, "black") x += 8 # Draw vertical rivets for x in [-5, 205]: y = 95 for i in range(17): turtle.goto(x, y) turtle.dot(5, "black") y -= 8 # Draw windows turtle.fillcolor("grey") for x in [-317, -208]: turtle.goto(x, 150) turtle.pendown() turtle.begin_fill() turtle.goto(x + 75, 150) turtle.goto(x + 75, 25) turtle.goto(x, 25) turtle.goto(x, 150) turtle.end_fill() turtle.penup() # Draw arches above wheels # Arch 1 turtle.goto(-125, -200) turtle.left(90) turtle.pendown() turtle.circle(100, 180) # Arch 2 turtle.penup() turtle.goto(75, -200) turtle.left(180) turtle.pendown() turtle.circle(50, 180) # Arch 3 turtle.penup() turtle.goto(275, -200) turtle.left(180) turtle.pendown() turtle.circle(50, 180) # Draw the wheels turtle.color("red") turtle.fillcolor("white") # Wheel 1 turtle.penup() turtle.goto(-135, -200) turtle.left(180) turtle.pendown() turtle.circle(90) turtle.penup() turtle.goto(-145, -200) turtle.pendown() turtle.circle(80) draw_spokes(80) turtle.penup() turtle.goto(-203, -200) turtle.left(180) turtle.pendown() turtle.begin_fill() turtle.circle(20) turtle.end_fill() # Wheel 2 turtle.penup() turtle.goto(65, -200) turtle.pendown() turtle.circle(40) turtle.penup() turtle.goto(55, -200) turtle.pendown() turtle.circle(30) draw_spokes(30) turtle.penup() turtle.goto(35, -200) turtle.left(180) turtle.pendown() turtle.begin_fill() turtle.circle(10) turtle.end_fill() # Wheel 3 turtle.penup() turtle.goto(265, -200) turtle.pendown() turtle.circle(40) turtle.penup() turtle.goto(255, -200) turtle.pendown() turtle.circle(30) draw_spokes(30) turtle.penup() turtle.goto(235, -202) turtle.left(180) turtle.pendown() turtle.begin_fill() turtle.circle(10) turtle.end_fill() # Persist the drawing turtle.done()
import turtle as tl def draw_fractal(scale): if scale >= 5: draw_fractal(scale / 3.0) tl.left(45) draw_fractal(scale / 3.0) tl.right(90) draw_fractal(scale / 3.0) tl.left(45) draw_fractal(scale / 3.0) else: tl.forward(scale) scale = 400 tl.pensize(2) tl.penup() tl.goto(-scale, -scale / 4) tl.pendown() draw_fractal(scale) tl.done()
point3 = (-200, 30) #Second line x axis point4 = (0, 30) #Second line y axis point5 = (0, 60) #Third line x axis point6 = (-200, 60) #Third line y axis window = turtle.Screen() window.bgcolor('light green') turtle = turtle.Turtle() turtle.color("blue") turtle.pensize(3) turtle.penup() #no drawing when moving turtle.goto(point1) turtle.pendown() #drawing when moving turtle.goto(point2) turtle.penup() turtle.goto(point3) turtle.pendown() turtle.goto(point4) turtle.penup() turtle.goto(point5) turtle.pendown() turtle.goto(point6) turtle.hideturtle() #this hides arrow
def drawLine(draw): #绘制单段数码管 turtle.pendown() if draw else turtle.penup() turtle.fd(40) turtle.right(90)
import turtle # 设置初始位置 turtle.penup() # 提起画笔 turtle.speed(100) turtle.pensize(5) turtle.left(90) # 逆时针旋转九十度 turtle.fd(200) # 向前移动一段距离 fd=forward turtle.pendown() # 放下画笔移动画笔开始绘制 turtle.right(90) # 顺时针旋转九十度 # 花蕊 turtle.fillcolor("red") # 填充颜色 turtle.begin_fill() # 开始填充 turtle.circle(10, 180) # 画一圆,10是半径,180是弧度 turtle.circle(25, 110) turtle.left(50) turtle.circle(60, 45) turtle.circle(20, 170) turtle.right(24) turtle.fd(30) turtle.left(10) turtle.circle(30, 110) turtle.fd(20) turtle.left(40) turtle.circle(90, 70) turtle.circle(30, 150) turtle.right(30) turtle.fd(15) turtle.circle(80, 90) turtle.left(15)
def main(): turtle.pensize(3) turtle.penup() turtle.goto(-200,-50) turtle.pendown() turtle.begin_fill() turtle.color("red") turtle.circle(40, steps=3) turtle.end_fill() turtle.penup() turtle.goto(-100,-50) turtle.pendown() turtle.begin_fill() turtle.color("blue") turtle.circle(40, steps=4) turtle.end_fill() turtle.penup() turtle.goto(0,-50) turtle.pendown() turtle.begin_fill() turtle.color("green") turtle.circle(40, steps=5) turtle.end_fill() turtle.penup() turtle.goto(100,-50) turtle.pendown() turtle.begin_fill() turtle.color("yellow") turtle.circle(40, steps=6) turtle.end_fill() turtle.penup() turtle.goto(200,-50) turtle.pendown() turtle.begin_fill() turtle.color("purple") turtle.circle(40) turtle.end_fill() turtle.color("green") turtle.penup() turtle.goto(-100,50) turtle.pendown() turtle.write(("Cool Colorful shapes"), font = ("Times", 18, "bold")) turtle.hideturtle() turtle.done
def pendown(): turtle.pendown() return
def down(): turtle.pendown()
def start(): # char=list(main) # valid=["c", "C", "e", "E", "l", "L", "i", "I", "f", "F", "h", "H"] # if valid[1] or valid[2] or valid[3] or valid[4] or valid[5] or valid[6] or valid[7] or valid[8] or valid[9] or valid[10] or valid[11] or valid[12]: # main=str(input("Please choose any of the follwing six letters to see them printed out in ASCII art (C, E, L, I, F, H). Or type 'quit' to leave the loop: ")) string1 = str(len(main)) list1 = list(main) i = 0 # main=str(input("Please choose any of the follwing six letters to see them printed out in ASCII art (C, E, L, I, F, H). Or type 'quit' to leave the loop: ")) turtle.reset() for i in range(int(string1)): if list1[i] == "c" or list1[i] == "C": turtle.penup() turtle.setposition(turtle.xcor() + 10, 0) turtle.pendown() turtle.forward(100) turtle.back(100) turtle.right(90) turtle.forward(100) turtle.left(90) turtle.forward(100) elif list1[i] == "e" or list1[i] == "E": turtle.penup() turtle.setposition(turtle.xcor() + 10, 0) turtle.pendown() turtle.forward(100) turtle.back(100) turtle.right(90) turtle.forward(50) turtle.left(90) turtle.forward(100) turtle.back(100) turtle.right(90) turtle.forward(50) turtle.left(90) turtle.forward(100) elif list1[i] == "l" or list1[i] == "L": turtle.penup() turtle.setposition(turtle.xcor() + 10, 0) turtle.pendown() turtle.right(90) turtle.forward(100) turtle.left(90) turtle.forward(50) elif list1[i] == "i" or list1[i] == "I": turtle.penup() turtle.setposition(turtle.xcor() + 10, 0) turtle.pendown() turtle.forward(100) turtle.back(50) turtle.right(90) turtle.forward(100) turtle.left(90) turtle.back(50) turtle.forward(100) elif list1[i] == "f" or list1[i] == "F": turtle.penup() turtle.setposition(turtle.xcor() + 10, 0) turtle.pendown() turtle.forward(100) turtle.back(100) turtle.right(90) turtle.forward(30) turtle.left(90) turtle.forward(100) turtle.back(100) turtle.right(90) turtle.forward(70) turtle.left(90) turtle.penup() turtle.setposition(turtle.xcor() + 100, 0) elif list1[i] == "h" or list1[i] == "H": turtle.penup() turtle.setposition(turtle.xcor() + 10, 0) turtle.pendown() turtle.right(90) turtle.forward(100) turtle.back(50) turtle.left(90) turtle.forward(50) turtle.left(90) turtle.forward(50) turtle.back(100) turtle.right(90) i = i + 1
def Skip(step): turtle.penup() turtle.forward(step) turtle.pendown()
def left_click(x, y): t.fillcolor("red") t.penup() t.goto(x, y) t.pendown() t.stamp()
import turtle as tr import numpy as np tr.shape('turtle') tr.speed(300) def star(n): if n % 2 == 1: for i in range(0, n, 1): tr.forward(100) tr.left(180 - 180 / n) star(5) tr.penup() tr.goto(200, 0) tr.pendown() star(11)
import turtle turtle.color("blue") #顏色藍色 turtle.penup() #舉起筆 turtle.goto(-110, -25) turtle.pendown() #放下筆 turtle.circle(45) turtle.color("black") turtle.penup() turtle.goto(0, -25) turtle.pendown() turtle.circle(45) turtle.color("red") turtle.penup() turtle.goto(110, -25) turtle.pendown() turtle.circle(45) turtle.color("yellow") turtle.penup() turtle.goto(-55, -75) turtle.pendown() turtle.circle(45) turtle.color("green") turtle.penup() turtle.goto(55, -75) turtle.pendown() turtle.circle(45)
def writeText(s, x, y): turtle.penup() turtle.goto(x, y) turtle.pendown() turtle.write(s)
def drawLine(draw): #绘制单段数码管 drawGap() t.pendown() if draw else t.penup() t.fd(40) drawGap() t.right(90)
def drawCircle(x = 0, y = 0, radius = 10): turtle.penup() turtle.goto(x, y - radius) turtle.pendown() turtle.circle(radius)
def create_drawing_canvas(): # Set up the drawing window with enough space for the grid and # legend turtle.setup(window_width, window_height) turtle.setworldcoordinates(-margin, -margin, window_width - margin, window_height - margin) # Draw as quickly as possible turtle.tracer(False) # Choose a neutral background colour (if you want to draw your # own background put the code here, but do not change any of the # following code that draws the grid) turtle.bgcolor('light grey') # Get ready to draw the grid turtle.penup() turtle.color('slate grey') turtle.width(2) # Draw the horizontal grid lines turtle.setheading(0) # face east for y_coord in range(0, (num_squares + 1) * grid_size, grid_size): turtle.penup() turtle.goto(0, y_coord) turtle.pendown() turtle.forward(num_squares * grid_size) # Draw the vertical grid lines turtle.setheading(90) # face north for x_coord in range(0, (num_squares + 1) * grid_size, grid_size): turtle.penup() turtle.goto(x_coord, 0) turtle.pendown() turtle.forward(num_squares * grid_size) # Draw each of the labels on the x axis turtle.penup() y_offset = -27 # pixels for x_coord in range(0, (num_squares + 1) * grid_size, grid_size): turtle.goto(x_coord, y_offset) turtle.write(str(x_coord), align='center', font=('Arial', font_size, 'normal')) # Draw each of the labels on the y axis turtle.penup() x_offset, y_offset = -5, -10 # pixels for y_coord in range(0, (num_squares + 1) * grid_size, grid_size): turtle.goto(x_offset, y_coord + y_offset) turtle.write(str(y_coord), align='right', font=('Arial', font_size, 'normal')) # Mark the space for drawing the legend turtle.goto(750, 700) turtle.fillcolor('light blue') turtle.pendown() turtle.begin_fill() turtle.setheading(0) turtle.width(5) turtle.forward(300) turtle.right(90) turtle.forward(700) turtle.right(90) turtle.forward(300) turtle.right(90) turtle.forward(700) turtle.right(90) turtle.end_fill() turtle.penup() turtle.goto(760, 650) turtle.write(' Programming', align='left', font=('Arial', 24, 'normal')) turtle.goto(760, 600) turtle.write(' Languages', align='left', font=('Arial', 24, 'normal')) tokens = { 'python': python_icon, 'Ruby': ruby_icon, 'C++': c_plusplus_icon, 'R': r_icon, 'JS': javascript_icon } icon_location = [810, 500] for name, token in tokens.items(): turtle.goto(icon_location) token() turtle.color('slate grey') turtle.goto(icon_location[0] + 60, icon_location[1] - 25) turtle.write(name, align='left', font=('Arial', 24, 'normal')) icon_location[1] -= 100 # Reset everything ready for the student's solution turtle.pencolor('black') turtle.width(1) turtle.penup() turtle.home() turtle.tracer(True)
def wheel(colors, radius=250, center=(25, 50)): slice_angle = 360 / len(colors) heading, position = 90, (center[0] + radius, center[1]) for color in colors: turtle.color('black', color) turtle.penup() turtle.goto(position) turtle.setheading(heading) turtle.pendown() turtle.begin_fill() turtle.circle(radius, extent=slice_angle) heading, position = turtle.heading(), turtle.position() turtle.penup() turtle.goto(center) turtle.end_fill() turtle.penup() turtle.goto(190,-100) turtle.write('800$',True,"center",("Arial",12,"bold")) turtle.penup() turtle.goto(230,-60) turtle.write('470$',True,"center",("Arial",12,"bold")) turtle.penup() turtle.goto(250,5) turtle.write('free-play',True,"right",("Arial",12,"bold")) turtle.penup() turtle.goto(240,60) turtle.write('150$',True,"center",("Arial",12,"bold")) turtle.penup() turtle.goto(230,120) turtle.write('350$',True,"center",("Arial",12,"bold")) turtle.penup() turtle.goto(210,180) turtle.write('1000$',True,"center",("Arial",12,"bold")) turtle.penup() turtle.goto(160,220) turtle.write('500$',True,"center",("Arial",12,"bold")) turtle.penup() turtle.goto(100,250) turtle.write('740$',True,"center",("Arial",12,"bold")) turtle.penup() turtle.goto(50,260) turtle.write('990$',True,"center",("Arial",12,"bold")) turtle.penup() turtle.goto(0,260) turtle.write('1125$',True,"center",("Arial",12,"bold")) turtle.penup() turtle.goto(-60,255) turtle.write('420$',True,"center",("Arial",12,"bold")) turtle.penup() turtle.goto(-110,220) turtle.write('100$',True,"center",("Arial",12,"bold")) turtle.penup() turtle.goto(-150,180) turtle.pencolor('white') turtle.write('bankrupt',True,"center",("Arial",12,"bold")) turtle.pencolor('black') turtle.penup() turtle.goto(-190,120) turtle.write('5000$',True,"center",("Arial",12,"bold")) turtle.penup() turtle.goto(-190,60) turtle.write('630$',True,"center",("Arial",12,"bold")) turtle.penup() turtle.goto(-190,20) turtle.write('300$',True,"center",("Arial",12,"bold")) turtle.penup() turtle.goto(-190,-40) turtle.write('lose-turn',True,"left",("Arial",12,"bold")) turtle.penup() turtle.goto(-170,-95) turtle.write('880$',True,"center",("Arial",12,"bold")) turtle.penup() turtle.goto(-115,-130) turtle.write('770$',True,"center",("Arial",12,"bold")) turtle.penup() turtle.goto(-70,-160) turtle.write('575$',True,"center",("Arial",12,"bold")) turtle.penup() turtle.goto(-10,-175) turtle.write('690$',True,"center",("Arial",12,"bold")) turtle.penup() turtle.goto(50,-175) turtle.write('50$',True,"center",("Arial",12,"bold")) turtle.penup() turtle.goto(100,-170) turtle.write('1111$',True,"center",("Arial",12,"bold")) turtle.penup() turtle.goto(150,-140) turtle.write('195$',True,"center",("Arial",12,"bold")) turtle.hideturtle()
import turtle as t t.setup(800, 400, 200, 200) # 设置绘图窗口 t.penup() # 抬起画笔,海龟飞行 t.fd(-250) # t.pendown() # 画笔落下,海龟在爬行 t.pensize(25) # 画笔尺寸 t.pencolor("purple") # 画笔颜色 # t.forward(100) # 运动控制函数,向前走 # t.circle(-100, 90) # 运动控制函数,弧型走 t.setheading(-40) for i in range(4): t.circle(40, 80) t.circle(-40, 80) t.circle(40, 80 / 2) t.fd(40) t.circle(16, 180) t.fd(40 * 2 / 3) # t.left(30) # t.right(30) t.done()
def drawline(draw): turtle.pendown() if draw else turtle.penup() turtle.fd(40) turtle.right(90)