def drawBorder(): """Draw a circle for the outline of the thingy. that is a circle of radius 100""" turtle.right( 90 ) turtle.down() turtle.circle( 100 ) turtle.up() turtle.left( 90 )
def bezier(smooth, x1, y1, x2, y2, x3, y3, *others): if len(others) % 2 != 0: print("Missing point data.") return if smooth < 1: print("Invalid smooth value") return wasDown = turtle.isdown() points = list(others) xval = [x1, x2, x3] + points[0:len(points):2] yval = [y1, y2, y3] + points[1:len(points):2] t, n, factn, step = 0, len(xval) - 1, factoral(len(xval) - 1), 1.0/smooth turtle.up() turtle.goto(x1, y1) if wasDown: turtle.down() while(t <= 1): x, y = 0, 0 for i in range(0, n+1): b = factn / ((factoral(i)) * (factoral(n - i))) #binomial coefficient k = ((1 - t) ** (n - i)) * (t ** i) #powers x += b * k * xval[i] #parametric application y += b * k * yval[i] #to x and y turtle.goto(x, y) t += step
def tree1(argv, x, y): lsys_filename1 = argv[1] lsys1 = ls.createLsystemFromFile( lsys_filename1 ) print lsys1 num_iter1 = int( 3 ) dist = float( 5 ) angle1 = float( 22 ) s1 = ls.buildString( lsys1, num_iter1 ) #draw lsystem1 '''this is my first lsystem with filename mysystem1.txt with 3 iterations and with angle = 45 dist = 10''' turtle.tracer(False) turtle.speed(50000000) turtle.up() turtle.goto(0,0) turtle.goto(x, y) turtle.down() turtle.pencolor('White') it.drawString( s1, dist, angle1 ) # wait and update turtle.update()
def sun(argv): lsys_filename3 = argv[3] lsys3 = ls.createLsystemFromFile( lsys_filename3 ) print lsys3 num_iter3 = int( 3 ) dist = 5 angle3 = float( 120 ) s3 = ls.buildString( lsys3, num_iter3 ) #draw lsystem3 '''this is my third lsystem with filename mysystem3.txt with 3 iterations and with angle = 45 dist = 10''' turtle.up() turtle.goto(0,0) turtle.goto(300, 200) turtle.down() turtle.setheading(0) turtle.left(90) turtle.pencolor('Red') it.drawString( s3, dist, angle3 ) # wait and update turtle.update()
def initBannerCanvas( numChars , numLines, scale ): """ Set up the drawing canvas to draw a banner numChars wide and numLines high. The coordinate system used assumes all characters are 20x20 and there are 10-point spaces between them. Precondition: The initial canvas is default size, then input by the first two user inputs, every input after that defines each letter's scale, probably between 1 and 3 for the scale values to have the window visible on the screen. Postcondition: The turtle's starting position is at the bottom left corner of where the first character should be displayed, the letters are printed. """ scale = int(input("scale, integer please")) # This setup function uses pixels for dimensions. # It creates the visible size of the canvas. canvas_height = 80 * numLines *scale canvas_width = 80 * numChars *scale turtle.setup( canvas_width *scale, canvas_height *scale) # This setup function establishes the coordinate system the # program perceives. It is set to match the planned number # of characters. height = 30 *scale width = 30 * numChars *scale margin = 5 # Add a bit to remove the problem with window decorations. turtle.setworldcoordinates( -margin+1 * scale, -margin+1 * scale, width + margin* scale, numLines*height + margin * scale) turtle.reset() turtle.up() turtle.setheading( 90 ) turtle.forward( ( numLines - 1 ) * 30 ) turtle.right( 90 ) turtle.pensize( 1 *scale)
def drawCircle(x, y, r): turtle.up() turtle.setpos(x+r,y) turtle.down() for i in range(0, DEGREES_IN_CIRCLE): a = math.radians(i+1) turtle.setpos(x+r*math.cos(a), y+r*math.sin(a))
def ejes(): #################################### # Ejes Coordenados # # los ejes x e y van de -150 a 150 # #################################### turtle.delay(0) turtle.ht() turtle.speed(0) turtle.pencolor('red') turtle.down() turtle.fd(301) turtle.rt(90) turtle.fd(1) turtle.rt(90) turtle.fd(300) turtle.lt(90) turtle.fd(300) turtle.rt(90) turtle.fd(1) turtle.rt(90) turtle.fd(300) turtle.lt(90) turtle.fd(300) turtle.rt(90) turtle.fd(1) turtle.rt(90) turtle.fd(300) turtle.lt(90) turtle.fd(300) turtle.rt(90) turtle.fd(1) turtle.rt(90) turtle.fd(300) turtle.up() turtle.pencolor('blue')
def drawSpiral (n,x): # Lift the pen up, so no lines are drawn turtle.up() # Initial positions spiral.rt(45) spiral.fd(90) spiral.rt(135) # Sets the pen down, so that turtle can draw spiral.down() # While the value of x is lesser than n, continuously do this: for i in range(n): spiral.fd(200) spiral.rt(61) spiral.fd(200) spiral.rt(61) spiral.fd(200) spiral.rt(61) spiral.fd(200) spiral.rt(61) spiral.fd(200) spiral.rt(61) spiral.fd(200) spiral.rt(61) spiral.rt(11.1111) # Add 1 to the value of x so that it's closer to n after every iteration x = x + 1
def main(): '''Creates lsystem from filename and then creates an arrangement''' # creates object from lsystem l = ls.Lsystem('lsystemextension2.txt') #number of iterations # for growth effect in task 3, made iters a parameter num_iter = 4 # creates buildstring function s = l.buildString(num_iter) #specific angle angle = 30 #creates an object from TI class ti = it.TurtleInterpreter() # sets the colors of the tracer and calls the drawstring function turtle.pencolor('ForestGreen') '''tree with stem color of forestgreen''' turtle.up() turtle.setposition(0,0) turtle.setheading(90) turtle.down() ti.drawString(s, 50 ,angle) ti.hold()
def choix_position(self): #position aléatoire dans l'écran self.x = random.randint(-350, 350) self.y = random.randint(-350, 350) tt.up() tt.goto(self.x, self.y) tt.down()
def line(a, b, x, y): "Draw line from `(a, b)` to `(x, y)`." import turtle turtle.up() turtle.goto(a, b) turtle.down() turtle.goto(x, y)
def draw_leaf(no_of_leafs): """ Draws leafs at the end of branch. Min 0 and max = no_of_leafs :pre: pos(0,0), heading east, up :post: pos(0,0), heading east, up :param no_of_leafs: maximum number of leads drawn :return: None """ for i in range(no_of_leafs): # draws random poylgon from triangle to hexagon sides = random.randint(3, 6) color = random.choice(COLORS) size = 10 angle = 360/sides t.left(90 - i * angle) t.right(90) t.begin_fill() t.down() t.color(color) for _ in range(sides): t.forward(size) t.left(angle) t.left(90) t.up() t.end_fill() t.right(90 - i * angle) global LEAF_COUNTER LEAF_COUNTER += 1
def f(l, n): t.up() t.goto( - l / 2, l / 3 ) t.down() for i in rang(3): vk(l, n) t.right(120)
def drawS(length): """ Draw English character 'S' :pre: (relative) pos (X,Y), heading (east), up :post: (relative) pos (X+length,Y), heading (east), up :return: None """ turtle.up() turtle.left(90) turtle.forward(length) turtle.right(90) turtle.down() turtle.forward(length) turtle.right(180) turtle.forward(length) turtle.left(90) turtle.forward(length / 2) turtle.left(90) turtle.forward(length) turtle.right(90) turtle.forward(length / 2) turtle.right(90) turtle.forward(length) turtle.right(180) turtle.forward(length) turtle.up()
def drawHouse(wallSize): """ This is the function for drawing house which takes wall size as a input. :pre: (relative) pos (0,0), heading (east), right :post: (relative) pos (wallSize,0), heading (north), up :return: total wood required to built the house. """ turtle.down() turtle.forward(wallSize) turtle.left(90) turtle.forward(wallSize) maxX = turtle.xcor() turtle.left(45) turtle.forward(wallSize / math.sqrt(2)) maxY = turtle.ycor() turtle.left(90) turtle.forward(wallSize / math.sqrt(2)) turtle.left(45) turtle.forward(wallSize) turtle.left(90) turtle.forward(wallSize) turtle.up() return 2 * (wallSize + wallSize / math.sqrt(2))
def questionMark(): """ Draw a question mark. """ scale = int(input("scale, integer please")) turtle.forward( 10 *scale) turtle.down() turtle.left( 90 ) turtle.forward( 2 *scale) turtle.up() turtle.forward( 3 *scale) turtle.down() turtle.forward( 5 *scale) turtle.right( 90 ) turtle.forward( 10 *scale) turtle.left( 90 ) turtle.forward( 10 *scale) turtle.left( 90 ) turtle.forward( 20 *scale) turtle.left( 90 ) turtle.forward( 5 *scale) turtle.up() turtle.forward( 15 *scale) turtle.left( 90 ) turtle.forward ( 30 *scale)
def draw_triangle(point1, point2, point3): turtle.up() turtle.goto(point1) turtle.down() turtle.goto(point2) turtle.goto(point3) turtle.goto(point1)
def hexagone(c, longueur,m, col1, col2, col3,deform): """ Draws a hexagon with or without deformation """ lo = longueur x,y,z = c #Hexagon centre pa1,pa2,pa3 = (x+lo,y,z), (x+(lo/2),y-m,z), (x-(lo/2),y-m,z)#First losange coordinates (lower right) pb1,pb2,pb3 = (x+lo,y,z), (x+(lo/2),y+m,z), (x-(lo/2),y+m,z)#Losange 2 (upper right) pc1,pc2,pc3 = (x-(lo/2),y+m,z), (x-lo,y,z), (x-(lo/2),y-m,z)#Losange 3 (left) pts = [pa1,pa2,pa3,c,pb1,pb2,pb3,c,pc1,pc2,pc3,c] d = [] for point in pts: xd,yd,zd = deform(point) d.extend((xd,yd)) up() setpos(d[6],d[7])#Turtle resets to c down() col = [col1,col2,col3] i = 0 for e in col: color(e) begin_fill() goto(d[i],d[i+1]) goto(d[i+2],d[i+3]) goto(d[i+4],d[i+5]) goto(d[i+6],d[i+7]) end_fill() i += 8
def roach(turt): #make moves a global variable global moves turt.pencolor(randrange(255),randrange(255),randrange(255)) turtle.up() turtle.goto(0,0) turtle.down() #write the code for roach to go & turn while True: moves += 1 turt_heading = randrange(0,361) turt.left(turt_heading) turt_length = randrange(0,31) turt.forward(turt_length) distance = dist(turt) #if statement to determine if the roach is outside the circle or inside #if inside, keep moving #if outside, stop moving #return coordinate if distance >= 200: break turt.up() moves += moves #accummulate total moves print(moves) return moves
def draw_l(word): turtle.up() turtle.clear() turtle.setposition(0, 0) turtle.setheading(0) turtle.bk(INITIAL_POS[0]) turtle.down() turtle.st() stack = [] for char in word: if char == '0': turtle.fd(SIZE[0]) if char == '1': turtle.fd(SIZE[0]) if char == '[': stack.append((turtle.position(), turtle.heading())) turtle.lt(45) if char == ']': position, heading = stack.pop() turtle.up() turtle.setposition(position) turtle.setheading(heading) turtle.rt(45) turtle.down() turtle.ht()
def drawCloud(words, num = 20): """ Draws a wordcloud with 20 random words, sized by frequency found in the WORDS dictionary. """ t.reset() t.up() t.hideturtle() topCounts = sorted([words[word] for word in list(words.keys()) if len(word) > 3]) largest = topCounts[0] normalized_counts = {} for item in list(words.keys()): if len(item) > 3: newSize = int(float(words[item]) / largest * 24) normalized_counts[item] = newSize size = t.screensize() width_dim = (int(-1 * size[0] / 1.5), int(size[0] / 2)) height_dim = (int(-1 * size[1] / 1.5), int(size[1] / 1.5)) for item in random.sample(list(normalized_counts.keys()), num): t.goto(random.randint(*width_dim), random.randint(*height_dim)) t.color(random.choice(COLORS)) try: t.write(item, font = ("Arial", int(normalized_counts[item]), "normal")) except: try: t.write(str(item, errors = 'ignore'), font = ("Arial", int(normalized_counts[item]), "normal")) except: pass
def drawEyes(): """ Draw the pair of eyes. :pre: (relative) pos (0,0), heading (east), up :post: (relative) pos (0,0), heading (east), up :return: None """ # left eye turtle.forward(10) turtle.left(90) turtle.forward(10) turtle.right(90) turtle.down() turtle.begin_fill() turtle.circle(5) turtle.end_fill() turtle.up() # right eye turtle.forward(30) turtle.down() turtle.begin_fill() turtle.circle(5) turtle.end_fill() turtle.up() # return back turtle.back(30) turtle.left(90) turtle.back(10) turtle.right(90) turtle.back(10)
def drawA(): """ :pre: pos (0,0), heading (east), up :post: pos (0,0), heading (east), up :return: None """ turtle.down() turtle.left(ANGLENINETY) turtle.forward(UNIT * 2) turtle.right(ANGLENINETY) turtle.forward(UNIT) turtle.right(ANGLENINETY) turtle.forward(UNIT) turtle.right(ANGLENINETY) turtle.forward(UNIT) turtle.up() turtle.right(180) turtle.forward(UNIT) turtle.right(ANGLENINETY) turtle.down() turtle.forward(UNIT) turtle.up() turtle.right(ANGLENINETY) turtle.forward(UNIT) turtle.right(180) turtle.down()
def drawK(): """ Draw the alphabet K :pre: (relative) pos (0,0), heading (east), up :post: (relative) pos(CHAR_WIDTH + CHAR_GAP,0), heading (east), up :return: None """ turtle.down() turtle.left(90) turtle.forward(CHAR_HEIGHT) turtle.backward(CHAR_HEIGHT/2) angleK = math.degrees(math.atan(2 * CHAR_WIDTH/CHAR_HEIGHT)) turtle.right(angleK) #turtle.forward(math.sqrt(CHAR_HEIGHT^2 + CHAR_WIDTH^2)/2) turtle.forward(CHAR_HYPOT) turtle.backward(CHAR_HYPOT) turtle.right(180 - 2 * angleK) turtle.forward(CHAR_HYPOT) turtle.backward(CHAR_HYPOT) turtle.right(angleK) turtle.forward(CHAR_HEIGHT/2) turtle.left(90) turtle.up() turtle.forward(CHAR_WIDTH + CHAR_GAP)
def initBannerCanvas( numChars, numLines ): """ Set up the drawing canvas to draw a banner numChars wide and numLines high. The coordinate system used assumes all characters are 20x20 and there are 10-point spaces between them. Postcondition: The turtle's starting position is at the bottom left corner of where the first character should be displayed. """ # This setup function uses pixels for dimensions. # It creates the visible size of the canvas. canvas_height = 80 * numLines canvas_width = 80 * numChars turtle.setup( canvas_width, canvas_height ) # This setup function establishes the coordinate system the # program perceives. It is set to match the planned number # of characters. height = 30 width = 30 * numChars margin = 5 # Add a bit to remove the problem with window decorations. turtle.setworldcoordinates( -margin+1, -margin+1, width + margin, numLines*height + margin ) turtle.reset() turtle.up() turtle.setheading( 90 ) turtle.forward( ( numLines - 1 ) * 30 ) turtle.right( 90 ) turtle.pensize( 2 * scale)
def linha(x1,y1,x2,y2): """ Traça uma linha entre dois pontos.""" turtle.up() turtle.goto(x1,y1) turtle.pd() turtle.goto(x2,y2) turtle.up()
def tSquare(size, level): """ The T-Square fractal. http://en.wikipedia.org/wiki/T-Square_%28fractal%29 """ if level < 1: drawSquare(size, True) else: drawSquare(size, True) bk(size / 4.0) left(90) fd(size / 4.0) right(90) tSquare(size / 2.0, level - 1) up() fd(size) down() tSquare(size / 2.0, level - 1) right(90) fd(size) left(90) tSquare(size / 2.0, level - 1) bk(size) tSquare(size / 2.0, level - 1) left(90) up() fd(size * 3 / 4.0) down() right(90) fd(size / 4.0)
def drawTongue(): """ Draw the tongue. :pre: (relative) pos (0,0), heading (east), up :post: (relative) pos (0,0), heading (east), up :return: None """ turtle.color('red') turtle.forward(25) turtle.left(90) turtle.forward(60) turtle.down() turtle.forward(25) turtle.left(45) turtle.forward(10) turtle.back(10) turtle.right(90) turtle.forward(10) turtle.back(10) turtle.left(45) turtle.up() turtle.back(85) turtle.right(90) turtle.back(25) turtle.color('black')
def newSnow(size,n): x=size/2 y=.4 if n<=0 or size<10: return else: for i in range(2): if n%2==0: turtle.color("#0099CC") elif n%3==0: turtle.color("#B2DFEE") else: turtle.color("#00B2EE") turtle.forward(y*size/2) turtle.left(60) newSnow(x,n-1) turtle.right(120) newSnow(x,n-1) turtle.left(60) x/=2 y+=.2 if n%2==0: turtle.color("#0099CC") elif n%3==0: turtle.color("#B2DFEE") else: turtle.color("#00B2EE") turtle.forward(.4*size/2) turtle.up() turtle.back(1.4*size/2) turtle.down() return
def tree2(argv, x, y): lsys_filename2 = argv[2] lsys2 = ls.createLsystemFromFile( lsys_filename2 ) print lsys2 num_iter2 = int( 3 ) dist = float( 5 ) angle2 = float( 30 ) s2 = ls.buildString( lsys2, num_iter2 ) #draw lsystem2 '''this is my second lsystem with filename mysystem2.txt with 5 iterations and with angle = 120 dist = 10''' turtle.up() turtle.goto(0,0) turtle.goto(x,y) turtle.down() turtle.setheading(0) turtle.left(90) turtle.pencolor('White') it.drawString( s2, dist, angle2 ) # wait and update turtle.update()
t.pd() t.goto(0, 0) t.color("grey") t.pendown() t.setheading(0) t.forward(side) t.right(120) for j in range(6): t.forward(side) t.right(60) side = side - 10 #Draw face turtle.pensize(2) turtle.begin_fill() turtle.up() turtle.goto(120, -170) turtle.down() turtle.seth(45) turtle.color('black', 'red') turtle.circle(270, 90) turtle.color('black', 'red') turtle.circle(170, 90) turtle.color('black', 'red') turtle.circle(270, 90) turtle.color('black', 'red') turtle.circle(170, 90) turtle.end_fill() #Draw web pattern
import turtle as t t.setworldcoordinates(0, 0, 7, 6) t.hideturtle() t.up() t.goto(0, 2) t.down() t.goto(7, 2) t.goto(5, 0) t.goto(2, 0) t.goto(0, 2) t.up() t.goto(2, 2) t.down() t.goto(2, 6) t.goto(4, 3) t.goto(2, 2) t.up() t.goto(5, 2) t.down() t.goto(5, 4) t.goto(6, 2.5) t.goto(5, 2)
def GoTo(x,y): t.up() t.goto(x, y) t.down()
def draw_background(): #create screen object screen = turtle.Screen() #dimentions for the screen screen.setup(1200, 700) #background color screen.bgcolor('#b3d9ff') #create new turtle turtle.hideturtle() turtle.speed(10000) turtle.pensize(2) turtle.color('black') #parameters for mountain MAX_SLOPE = 45 MIN_SLOPE = -40 MIN_HEIGHT = 0 def dist_squared(P1, P2): return (P1[0] - P2[0])**2 + (P1[1] - P2[1])**2 #funtion for drawing mountain #if you dont need it delete it def mountain(P1, P2): if dist_squared(P1, P2) < 9: turtle.goto(P2) return x1, y1 = P1 x2, y2 = P2 x3 = random.uniform(x1, x2) y3_max = min((x3 - x1) * math.tan(math.radians(MAX_SLOPE)) + y1, (x2 - x3) * math.tan(-math.radians(MIN_SLOPE)) + y2) y3_min = max((x3 - x1) * math.tan(math.radians(MIN_SLOPE)) + y1, (x2 - x3) * math.tan(-math.radians(MAX_SLOPE)) + y2) y3_min = max(y3_min, MIN_HEIGHT) y3 = random.uniform(y3_min, y3_max) P3 = (x3, y3) mountain(P1, P3) mountain(P3, P2) return #function for drawing stars #if you dont need delete it def drawstar(): turns = 5 turtle.begin_fill() while turns > 0: turtle.forward(25) turtle.left(145) turns = turns - 1 turtle.end_fill() #if you dont need the mountain delete this too turtle.up() turtle.goto(-600, MIN_HEIGHT) turtle.down() mountain((-600, MIN_HEIGHT), (600, MIN_HEIGHT)) #if you dont need the stars delete this too num_stars = 0 while num_stars < 20: xt = randint(-600, 600) yt = randint(150, 390) drawstar() turtle.penup() turtle.goto(xt, yt) turtle.pendown() num_stars = num_stars + 1 #screen.exitonclick() def clouds(screen): # function for movement of an object def moving_object(obj): #obj= turtle.Turtle() #turtle.bgcolor('lightblue') obj.fillcolor('white') #begin filling the object obj.begin_fill() obj.speed(1000000) obj.left(90) #use 6 arcs of circle to create a cloud #following show those six for x in range(1, 9): obj.left(10) obj.forward(2 + 0.3 * x) obj.left(280) for y in range(1, 18): obj.left(10) t = y if y >= 10: t = 19 - y obj.forward(2 + 0.1 * t) obj.left(280) for z in range(1, 9): obj.left(10) obj.forward(4.7 - 0.3 * z) obj.left(100) obj.left(270) for x in range(1, 9): obj.left(10) obj.forward(2 + 0.3 * x) obj.left(280) for y in range(1, 18): obj.left(10) t = y if y >= 10: t = 19 - y obj.forward(2 + 0.1 * t) obj.left(280) for z in range(1, 9): obj.left(10) obj.forward(4.7 - 0.3 * z) obj.left(100) obj.left(180) obj.end_fill() # screen updaion screen.tracer(0) # create a turtle object object move = turtle.Turtle() move1 = turtle.Turtle() move2 = turtle.Turtle() move3 = turtle.Turtle() move4 = turtle.Turtle() # set a turtle object color move.color('white') move1.color('white') move2.color('white') move3.color('white') move4.color('white') # set turtle object speed #move.speed(0) # set turtle object width move.width(2) move1.width(2) # hide turtle object move.hideturtle() # turtle object in air move.penup() move1.penup() #generate random number for use for parameters of the clouds c = randint(100, 340) c1 = randint(100, 340) c2 = randint(100, 340) c3 = randint(100, 340) c4 = randint(100, 340) # set initial position for 5 cloud with random possition move.goto(-600, c) move1.goto(-800, c1) move2.goto(-1000, c2) move3.goto(200, c3) move4.goto(-300, c4) #set moving speed for the clouds using random number m = ((c / 800.0) + .2) m1 = ((c1 / 800.0) + .2) m2 = ((c2 / 800) + .2) m3 = ((c3 / 800) + .2) m4 = ((c4 / 800) + .2) # move turtle object to surface move.pendown() move1.pendown() move2.pendown() move3.pendown() move4.pendown() #initialize a parameter to loop the clouds b = 0 b1 = 0 b2 = 0 b3 = 0 b4 = 0 # infinite loop while True: # clear turtle work move.clear() move1.clear() move2.clear() move3.clear() move4.clear() # call function to draw ball moving_object(move) moving_object(move1) moving_object(move2) moving_object(move3) moving_object(move4) # update screen screen.update() # forward motion by turtle object move.forward(m) move1.forward(m1) move2.forward(m2) move3.forward(m3) move4.forward(m4) #increment the finfing criteria b = b + 1 b1 = b1 + 1 b2 = b2 + 1 b3 = b3 + 1 b4 = b4 + 1 #fimdimg wether coloud gone out if gone out again bring back randomly if b * m >= 1500: c = randint(0, 375) b = 0 m = ((c / 800) + .2) move.goto(-620, c) if b1 * m1 >= 1600: c1 = randint(0, 375) b1 = 0 m1 = ((c1 / 800) + .2) move1.goto(-600 - c1, c1) if b2 * m2 >= 1600: c2 = randint(0, 375) b2 = 0 m2 = ((c2 / 800) + .2) move2.goto(-600 - c2, c2) if b3 * m3 >= 1600: c3 = randint(0, 375) b3 = 0 m3 = ((c3 / 800) + .2) move3.goto(-600 - c3, c3) if b4 * m4 >= 1600: c4 = randint(0, 375) b4 = 0 m4 = ((c4 / 800) + .2) move4.goto(-600 - c4, c4) clouds(screen)
def branch(steps, size): turtle.up() turtle.goto(0, -150) turtle.left(90) turtle.down() branch_draw(5, 400)
def binary_tree(branch): turtle.left(90) turtle.up() turtle.goto(0, -180) turtle.down() tree(branch)
def square(a): turtle.up() turtle.goto(-50, 50) turtle.down() square_draw(a)
def levi(steps, size): turtle.up() turtle.goto(-100, 0) turtle.down() levi_fun(steps, size)
def mink(order, size): turtle.up() turtle.goto(-200, 0) turtle.down() mink_draw(order, size)
def koch_curve(ln): turtle.up() turtle.goto(-ln * 1.2, 0) turtle.down() koch_curve_draw(ln)
maxval=2010)) first_sum = (month + year + day) #GUI design turtle.speed(0) turtle.pencolor('pink') turtle.bgcolor('black') x = 0 turtle.down() while x < 120: #create first object turtle.fd(200) turtle.rt(70) turtle.rt(11.1111) x = x + 1 turtle.up() #move towards second object turtle.fd(200) turtle.rt(40) turtle.down() y = 0 turtle.down() while y < 100: #create second object turtle.fd(200) turtle.rt(70) turtle.rt(11.1111) y = y + 1 turtle.pencolor('blue') #iteration(first digit sum to a single digit) accum = 0 for x in str(first_sum):
import turtle as p p.reset() p.Pen() p.pencolor('blue') p.bgcolor('pink') p.pensize(5) #p.fillcolor('red') #p.begin_fill() p.up() p.forward(30) p.down() p.forward(100) p.up() p.forward(30) p.right(90) p.forward(30) p.down() p.forward(100) p.up() p.forward(30) p.right(90) p.forward(30) p.down() p.forward(100) p.up() p.forward(30) p.right(90)
def fly(x, y): t.up() t.goto(x, y) t.down()
def reset(): turtle.up() turtle.forward(10) turtle.down()
def Chiko(): t.pensize(2) t.pencolor('#3b1546') t.fillcolor('#623683') t.up() t.right(90) t.forward(30) t.left(90) t.forward(60) t.down() t.begin_fill() t.left(30) t.forward(25) t.left(100) t.forward(20) t.right(70) t.forward(35) t.left(110) t.forward(25) t.right(70) t.forward(45) t.left(95) t.forward(45) t.right(70) t.forward(35) t.left(110) t.forward(35) t.right(65) t.forward(35) t.left(110) t.forward(30) t.right(70) t.forward(30) t.left(100) t.forward(20) t.end_fill() t.up() t.home() t.pencolor('#781d3c') t.fillcolor('#d4597f') t.up() t.forward(60) t.down() t.begin_fill() t.left(90) t.circle(60, 20) t.right(110) t.circle(7, 300) t.right(180) t.circle(60, 60) t.circle(10, 50) t.forward(5) t.right(120) t.circle(13, 50) t.left(30) t.circle(67, 270) t.end_fill() t.fillcolor('#bd4a6b') t.begin_fill() t.circle(67, -80) t.left(20) t.pencolor('#bd4a6b') t.circle(130, 40) t.end_fill() t.circle(130, -40) t.right(22) t.pencolor('#781d3c') t.circle(67, 80) t.up() t.left(5) t.forward(30) t.left(110) t.down() t.pensize(8) t.pencolor('#3b1546') t.fillcolor('white') t.forward(28) t.right(80) t.begin_fill() t.circle(20, 490) t.end_fill() t.right(86) t.forward(8) t.left(86) t.begin_fill() t.circle(-20, 550) t.end_fill() t.left(45) t.forward(20) t.up() t.left(32) t.back(46) t.down() t.pencolor('black') t.circle(1) t.up() t.right(160) t.forward(28) t.down() t.circle(1) t.up() t.left(95) t.forward(40) t.right(85) t.pensize(5) t.pencolor('#8e1237') t.down() t.circle(-30, 30) t.circle(-30, -30) t.up() t.back(25) t.right(20) t.down() t.circle(-30, -30) t.up() t.right(80) t.forward(57) t.down() t.pencolor('#8f0f37') t.circle(2) t.forward(2) t.pensize(2) t.right(20) t.forward(10) t.circle(9, 160) t.up() t.right(87) t.forward(40) t.right(75) t.pencolor() t.fillcolor('#d5597d') t.pencolor('#7b1735') t.pensize(2) t.begin_fill() t.down() t.left(50) t.circle(-30, 55) t.circle(-5, 180) t.circle(30, 50) t.circle(-5, 200) t.forward(15) t.end_fill() t.up() t.right(110) t.forward(110) t.left(20) t.down() t.begin_fill() t.circle(-10, 80) t.circle(-20, 60) t.left(40) t.circle(-60, -20) t.end_fill() t.up() t.right(160) t.forward(50) t.right(45) t.down() t.begin_fill() t.circle(-10, 60) t.circle(5, 120) t.circle(20, 40) t.circle(5, 90) t.circle(60, 17) t.left(70) t.forward(7) t.end_fill() t.up() t.back(7) t.left(90) t.down() t.begin_fill() t.circle(60, 20) t.circle(5, 45) t.circle(20, 37) t.circle(5, 120) t.circle(10, 60) t.right(90) t.forward(10) t.left(80) t.forward(10) t.end_fill() t.up() t.home()
def mygoto(x, y): turtle.up() turtle.goto(x, y) turtle.down()
def rainbow(): # Sky color top_fill('#D9ECEF') # Clouds cloud(2, -200, 150, 'white', 'white') cloud(3, 120, 40, 'white', 'white') cloud(1, -250, 30, 'white', 'white') # Rainbow element t.forward(50) t.pencolor('purple') t.fillcolor('purple') t.left(90) t.down() t.begin_fill() t.circle(70, 180) t.right(90) t.forward(5) t.right(90) t.circle(-75, 180) t.end_fill() t.right(180) t.pencolor('dark blue') t.fillcolor('dark blue') t.begin_fill() t.circle(75, 180) t.right(90) t.forward(5) t.right(90) t.circle(-80, 180) t.end_fill() t.right(180) t.begin_fill() t.pencolor('light blue') t.fillcolor('light blue') t.circle(80, 180) t.right(90) t.forward(5) t.right(90) t.circle(-85, 180) t.end_fill() t.right(180) t.begin_fill() t.pencolor('green') t.fillcolor('green') t.circle(85, 180) t.right(90) t.forward(5) t.right(90) t.circle(-90, 180) t.end_fill() t.right(180) t.begin_fill() t.pencolor('yellow') t.fillcolor('yellow') t.circle(90, 180) t.right(90) t.forward(5) t.right(90) t.circle(-95, 180) t.end_fill() t.right(180) t.begin_fill() t.pencolor('red') t.fillcolor('red') t.circle(95, 180) t.right(90) t.forward(5) t.right(90) t.circle(-100, 180) t.end_fill() t.up() t.home()
def Jumper(): t.pensize(2) t.pencolor('#0171b9') t.fillcolor('#84d4f7') t.forward(60) t.down() t.begin_fill() t.left(90) t.circle(60) t.end_fill() t.up() t.circle(60, 160) t.pencolor('#00c3f3') t.fillcolor('#00c3f3') t.left(25) t.down() t.begin_fill() t.circle(80, 90) t.pencolor('#0171b9') t.left(25) t.circle(60, -135) t.end_fill() t.up() t.left(45) t.forward(38) t.right(80) t.pencolor('#0171b9') t.fillcolor('#84d4f7') t.down() t.begin_fill() t.circle(5, -180) t.right(10) t.circle(-25, -40) t.left(50) t.back(10) t.left(80) t.circle(-20, 80) t.right(25) t.circle(-15, 60) t.circle(-40, 35) t.end_fill() t.up() t.pencolor('#02c2f4') t.fillcolor('#02c2f4') t.begin_fill() t.right(170) t.down() t.circle(30, 50) t.circle(7, 120) t.circle(15, 25) t.left(95) t.pencolor('#0171b9') t.back(6) t.left(80) t.circle(-20, 80) t.right(25) t.circle(-15, 60) t.circle(-40, 35) t.end_fill() t.up() t.right(90) t.forward(35) t.right(80) t.down() t.pencolor('#0171b9') t.fillcolor('#84d4f7') t.begin_fill() t.circle(35, 50) t.circle(5, 100) t.circle(60, 38) t.circle(5, 90) t.circle(40, 25) t.left(20) t.circle(30, 30) t.end_fill() t.up() t.left(150) t.forward(20) t.right(70) t.pencolor('#02c2f4') t.fillcolor('#02c2f4') t.down() t.begin_fill() t.circle(-16, 60) t.forward(13) t.right(28) t.pencolor('#0171b9') t.circle(-60, -23) t.circle(-5, -100) t.back(5) t.end_fill() t.up() t.left(70) t.forward(20) t.right(115) t.down() t.pencolor('#0171b9') t.fillcolor('#84d4f7') t.begin_fill() t.circle(30, 20) t.circle(7, 80) t.circle(65, 30) t.circle(5, 120) t.circle(60, 22) t.left(45) t.circle(-30, 30) t.end_fill() t.up() t.left(100) t.forward(2) t.down() t.pencolor('#02c2f4') t.fillcolor('#02c2f4') t.begin_fill() t.circle(15, 50) t.circle(30, 35) t.pencolor('#0171b9') t.left(16) t.circle(60, -25) t.right(20) t.circle(10, -120) t.end_fill() t.left(190) t.forward(5) t.up() t.right(7) t.forward(60) t.right(92) t.pencolor('#0171b9') t.fillcolor('#84d4f7') t.down() t.begin_fill() t.circle(-40, 20) t.circle(-9, 95) t.circle(-40, 20) t.right(130) t.circle(60, 30) t.end_fill() t.up() t.left(75) t.forward(117) t.pencolor('#0171b9') t.fillcolor('#84d4f7') t.down() t.begin_fill() t.left(10) t.circle(-65, 80) t.circle(-20, 185) t.right(180) t.circle(-65, -54) t.left(80) t.circle(60, 6) t.right(65) t.end_fill() t.pencolor('#02c2f4') t.fillcolor('#02c2f4') t.begin_fill() t.circle(-75, 65) t.circle(-30, 30) t.right(35) t.pencolor('#0171b9') t.circle(-20, -64) t.circle(-75, -65) t.end_fill() t.up() t.right(115) t.forward(25) t.left(95) t.pencolor('#0171b9') t.fillcolor('#84d4f7') t.down() t.begin_fill() t.circle(-40, 30) t.circle(-35, 170) t.circle(-13, 120) t.circle(-50, 40) t.circle(-50, -8) t.right(90) t.circle(-30, -60) t.end_fill() t.left(90) t.circle(60, 10) t.right(100) t.pencolor('#02c2f4') t.fillcolor('#02c2f4') t.down() t.begin_fill() t.circle(-60, 50) t.circle(-8, 40) t.circle(-40, 75) t.right(60) t.forward(5) t.right(40) t.circle(-45, 55) t.pencolor('#0171b9') t.right(20) t.circle(-40, -55) t.left(30) t.circle(-18, -60) t.left(15) t.circle(-30, -28) t.circle(-40, -70) t.left(15) t.circle(-40, -80) t.end_fill() t.up() t.right(40) t.back(17) t.pensize(4) t.down() t.circle(-10, 70) t.up() t.circle(-60, 20) t.right(20) t.down() t.circle(10, 70) t.up() t.pensize(2) t.fillcolor('white') t.right(150) t.forward(30) t.right(120) t.down() t.begin_fill() t.circle(30, 30) t.circle(15, 170) t.circle(30, 30) t.circle(13, 160) t.end_fill() t.begin_fill() t.right(70) t.circle(-30, 10) t.circle(-13, 110) t.circle(-30, 40) t.circle(-10, 150) t.left(30) t.circle(-20, 35) t.right(10) t.circle(40, 20) t.end_fill() t.back(20) t.pencolor('black') t.fillcolor('black') t.begin_fill() t.circle(-5, 490) t.end_fill() t.pencolor('white') t.fillcolor('white') t.begin_fill() t.circle(-2) t.end_fill() t.up() t.left(20) t.back(30) t.left(80) t.down() t.pencolor('black') t.fillcolor('black') t.begin_fill() t.circle(-5, 490) t.end_fill() t.pencolor('white') t.fillcolor('white') t.begin_fill() t.circle(-2) t.end_fill() t.up() t.pencolor('#f37694') t.fillcolor('#f37694') t.right(17) t.forward(23) t.down() t.begin_fill() t.circle(4) t.end_fill() t.up() t.pencolor('#0171b9') t.fillcolor('#ef4d40') t.left(10) t.forward(7) t.right(30) t.down() t.circle(-20, 25) t.up() t.right(65) t.back(25) t.down() t.begin_fill() t.left(27) t.circle(-40, 90) t.back(8) t.left(155) t.circle(30, 70) t.circle(6, 90) t.circle(-20, 40) t.up() t.right(90) t.forward(5) t.left(90) t.down() t.end_fill() t.up() t.left(120) t.forward(12) t.left(120) t.down() t.fillcolor('white') t.begin_fill() t.circle(-10, 150) t.right(40) t.circle(-20, 15) t.circle(-10, 25) t.end_fill() t.right(60) t.forward(20) t.back(10) t.right(80) t.circle(-10, 60) t.up() t.home()
import turtle as tu tu.setup(1920, 1080) tu.up() tu.left(135) tu.forward(300) tu.left(-135) tu.down() tu.ht() tu.speed(0) def draw_curve(tu, l, order): if order == 0: tu.forward(l) return else: l /= 3 draw_curve(tu, l, order - 1) tu.left(60) draw_curve(tu, l, order - 1) tu.left(-120) draw_curve(tu, l, order - 1) tu.left(60) draw_curve(tu, l, order - 1) def darw_full_curve(tu, l, order): draw_curve(tu, l, order) tu.left(-120) draw_curve(tu, l, order)
def move_pen_position(x, y): turtle.hideturtle() turtle.up() turtle.goto(x, y) turtle.down() turtle.showturtle()
def make_bodice_box(full_bust): box_len = (full_bust / 2) # top_right corner turtle.up() turtle.goto((-box_len), (nape_to_waist + cm)) back_line_top = turtle.pos() turtle.down() # top_left corner turtle.goto(box_len, (nape_to_waist + cm)) front_line_top = turtle.pos() turtle.up() # bottom_right corner turtle.goto((-box_len), waistline) turtle.down() waistline_front = turtle.pos() # bottom_left corner turtle.goto(box_len, waistline) waistline_back = turtle.pos() # top left to bottom left turtle.goto(waistline_back) turtle.goto(front_line_top) turtle.up() # top rt to bottom rt turtle.goto(back_line_top) turtle.down() turtle.goto(waistline_front) # neckline on backline turtle.goto(back_line_top) turtle.color("red") turtle.goto((-box_len), nape_to_waist) backline_neckline = turtle.pos() backline_x = turtle.xcor() # from backline, sq off 1/5 neck_cir on top turtle.up() turtle.goto(back_line_top) turtle.seth(east) turtle.down() turtle.forward(neck_cir / 5) back_shoulder_neckline = turtle.pos() # from back_shoulder_neckline, measure out 10cm to make the back_shoulder_slope turtle.up() turtle.forward(shoulder_len) turtle.seth(south) turtle.forward(cm) back_shoulder_slope_point = turtle.pos() back_shoulder_slope = turtle.heading() turtle.down() turtle.color("blue") # draw shoulder slope, line may need to be extended to match shoulder measurement turtle.goto(back_shoulder_neckline) # draw back neckline turtle.color("red") turtle.up() turtle.goto(backline_neckline) turtle.down() turtle.seth(east) this_far = (neck_cir / 6) turtle.forward(this_far) turtle.circle(20, 55) # mark out center_front_neckline turtle.up() turtle.goto(front_line_top) turtle.seth(south) turtle.down() turtle.forward((neck_cir / 5)) # shoulder_front_neckline turtle.up() turtle.goto(front_line_top) turtle.seth(west) turtle.down() turtle.forward((neck_cir / 5)) shoulder_front_neckline = turtle.pos() # draw in front neck line turtle.goto(shoulder_front_neckline) turtle.seth(south) turtle.circle((neck_cir / 5), 90) # front_shoulder_dart turtle.up() turtle.goto(shoulder_front_neckline) shoulder_dart = ((full_bust - front_width - back_width) / 3) turtle.color("yellow") turtle.seth(east) turtle.forward(shoulder_dart) outer_leg_shoulder_dart = turtle.pos() turtle.backward(shoulder_dart / 2) midpoint_shoulder_dart = turtle.pos() turtle.color("blue") turtle.up() turtle.goto(midpoint_shoulder_dart) turtle.seth(south) turtle.down() turtle.forward((nape_to_waist + cm)) turtle.color("green") turtle.bk(bust_height) shoulder_dart_bustline = turtle.pos() turtle.color("orange") shoulder_dart_point = turtle.pos() turtle.goto(shoulder_front_neckline) turtle.up() turtle.goto(outer_leg_shoulder_dart) turtle.down() turtle.goto(shoulder_dart_point) turtle.forward(cm) front_dart_point = turtle.pos() front_dart_point_x = turtle.xcor() turtle.goto(front_dart_point_x, waistline) front_dart_midpoint = turtle.pos() # front shoulder turtle.up() turtle.goto(back_shoulder_slope_point) turtle.seth(south) turtle.forward(cm) # turtle.down() turtle.color("grey") # guide @ back shoulder - grey_line = guide from back shoulder to front shoulder grey_line_start = turtle.pos() grey_line_start_x = turtle.xcor() grey_line_start_y = turtle.ycor() # guide @ front shoulder front_shoulder_slope = turtle.heading() turtle.goto(outer_leg_shoulder_dart) grey_line_end = turtle.pos() grey_line_end_x = turtle.xcor() grey_line_end_y = turtle.ycor() turtle.seth(west) turtle.up() turtle.forward(shoulder_len) turtle.seth(south) turtle.forward(30) # blue line = front shoulder guide blue_line_pt = turtle.pos() blue_line_pt_x = turtle.xcor() blue_line_pt_y = turtle.ycor() front_shoulder_intersect = ( (grey_line_end_y - grey_line_start_y) * (blue_line_pt_x - grey_line_start_x) / (grey_line_end_x - grey_line_start_x)) + (grey_line_start_y) round(front_shoulder_intersect) turtle.goto(blue_line_pt_x, front_shoulder_intersect) turtle.down() turtle.goto(outer_leg_shoulder_dart) turtle.color("green") # sq off front armhole @ shoulder turtle.up() turtle.goto(blue_line_pt_x, front_shoulder_intersect) turtle.down() turtle.forward(15) front_shoulder_sq_down = turtle.pos() # sq off back armhole @ shoulder turtle.up() turtle.goto(back_shoulder_slope_point) turtle.setheading(south) turtle.down() turtle.forward(15) back_shoulder_sq_down = turtle.pos() # on bustline, mark out 1/2 front_width + 1/2 dart turtle.up() turtle.goto(front_line_top) turtle.seth(west) turtle.forward(((front_width / 2) + (front_waist_dart / 2))) # front_side_guide front_side_guide_x = turtle.xcor() front_side_guide_y = turtle.ycor() turtle.seth(south) turtle.down() turtle.forward((nape_to_waist + cm)) # on bustline, mark out 1/2 back_width turtle.up() turtle.goto(back_line_top) turtle.seth(east) turtle.forward((back_width / 2)) back_side_guide_x = turtle.xcor() back_side_guide_y = turtle.ycor() turtle.seth(south) turtle.down() turtle.forward((nape_to_waist + cm)) # find and mark midpoint of front_side_guide and back_side_guide at bust_height- doesnt work as a function turtle.up() side_seam_guide = (((front_side_guide_x + back_side_guide_x) / 2), ((armhole_height + armhole_height) / 2)) turtle.goto(side_seam_guide) side_dart_point = turtle.pos() turtle.seth(south) turtle.down() turtle.forward(armhole_height) side_dart_midpoint = turtle.pos() # divide back section in half, mark from bust_height to waistline turtle.up() turtle.goto(backline_x, bust_height) backline_y = turtle.ycor() back_dart_guide = (((back_side_guide_x + backline_x) / 2), ((backline_y + backline_y) / 2)) turtle.goto(back_dart_guide) back_dart_point = turtle.pos() turtle.seth(south) turtle.down() turtle.forward(bust_height) back_dart_midpoint = turtle.pos() # back armhole_height/3 at back_side_guide_x turtle.up() # changed from bust height to armhole turtle.goto(back_side_guide_x, armhole_height) back_armhole_ref = turtle.pos() turtle.seth(north) turtle.down() turtle.color("red") # turtle.forward((armhole_height/3)) turtle.forward((armhole_height / 4)) back_armhole_notch = turtle.pos() # front armhole_height/4 front_side_guide_x turtle.up() # changed from bust height to armhole turtle.goto(front_side_guide_x, armhole_height) front_armhole_ref = turtle.pos() turtle.seth(north) turtle.down() # turtle.forward((armhole_height/4)) turtle.forward((armhole_height / 5)) front_armhole_notch = turtle.pos() # from back_armhole_ref draw a 2.5 cm diagonal line turtle.up() turtle.goto(back_armhole_ref) turtle.seth(((north + east) / 2)) turtle.down() turtle.forward(an_inch) back_armpit_notch = turtle.pos() # front_armhole_ref draw a 2 cm diagonal line turtle.up() turtle.goto(front_armhole_ref) turtle.seth(((north + west) / 2)) turtle.down() turtle.forward(two_cm) front_armpit_notch = turtle.pos() # connecting back armhole turtle.color("grey") turtle.up() turtle.goto(back_shoulder_sq_down) turtle.down() turtle.goto(back_armhole_notch) turtle.goto(back_armpit_notch) turtle.goto(side_dart_point) # connecting front armhole turtle.up() turtle.goto(front_shoulder_sq_down) turtle.down() turtle.goto(front_armhole_notch) turtle.goto(front_armpit_notch) turtle.goto(side_dart_point) # difference = (full_bust/2) - (waist_cir/2) # back_waist_dart = (difference/3) turtle.up() turtle.color("gold") turtle.goto(back_dart_midpoint) turtle.seth(west) turtle.forward(back_waist_dart / 2) turtle.down() turtle.goto(back_dart_point) turtle.goto(back_dart_midpoint) turtle.seth(east) turtle.forward(back_waist_dart / 2) turtle.goto(back_dart_point) # front_waist_dart = (back_waist_dart - cm) turtle.up() turtle.goto(front_dart_midpoint) turtle.seth(west) turtle.forward(front_waist_dart / 2) turtle.down() turtle.goto(front_dart_point) turtle.goto(front_dart_midpoint) turtle.seth(east) turtle.forward(front_waist_dart / 2) turtle.goto(front_dart_point) # side_waist_dart = (back_waist_dart + cm) turtle.up() turtle.goto(side_dart_midpoint) turtle.seth(west) turtle.forward(side_waist_dart / 2) turtle.down() turtle.goto(side_dart_point) turtle.goto(side_dart_midpoint) turtle.seth(east) turtle.forward(side_waist_dart / 2) turtle.goto(side_dart_point)
def draw(spot, mark, board): turtle.up() turtle.back(10) if (spot == 1 or spot == 4 or spot == 7): if (spot == 4): turtle.right(90) turtle.forward(100) turtle.left(90) turtle.down() if (mark == "X"): drawX() else: drawO() elif (spot == 7): turtle.right(90) turtle.forward(200) turtle.left(90) turtle.down() if (mark == "X"): drawX() else: drawO() else: if (mark == "X"): drawX() else: drawO() elif (spot == 2 or spot == 5 or spot == 8): turtle.forward(100) if (spot == 5): turtle.right(90) turtle.forward(100) turtle.left(90) turtle.down() if (mark == "X"): drawX() else: drawO() elif (spot == 8): turtle.right(90) turtle.forward(200) turtle.left(90) turtle.down() if (mark == "X"): drawX() else: drawO() else: if (mark == "X"): drawX() else: drawO() else: turtle.forward(200) if (spot == 6): turtle.right(90) turtle.forward(100) turtle.left(90) turtle.down() if (mark == "X"): drawX() else: drawO() elif (spot == 9): turtle.right(90) turtle.forward(200) turtle.left(90) turtle.down() if (mark == "X"): drawX() else: drawO() else: if (mark == "X"): drawX() else: drawO()
def draw_bowties(size, depth): """ :param size: determines length of triangle sides :param depth: input by user, determines how many times draw_one_bowtie is called draws bow ties by calling the draw_one_bowtie until the depth variable is satisfied """ if depth == 0: pass else: draw_one_bowtie(size) tt.up() tt.left(30) tt.forward(2 * size) tt.down() draw_bowties(size / 3, depth - 1) tt.up() tt.forward(-2 * size) tt.right(60) tt.up() tt.forward(size * -2) tt.down() draw_bowties(size / 3, depth - 1) tt.up() tt.forward(2 * size) tt.right(150) tt.down() draw_one_bowtie(size) tt.up() tt.left(30) tt.forward(size * 2) tt.down() draw_bowties(size / 3, depth - 1) tt.up() tt.forward(-2 * size) tt.right(60) tt.forward(-2 * size) tt.down() draw_bowties(size / 3, depth - 1) tt.up() tt.forward(size * 2) tt.left(210)
import turtle as t r = 120 t.color("red") t.begin_fill(); t.circle(r); t.end_fill() t.color("black") t.begin_fill() t.circle(r, 180); t.circle(r/2, 180); t.circle(-r/2, 180) t.end_fill() t.right(90); t.up(); t.forward(r/2 - r/10); t.right(90) t.color("black") t.begin_fill(); t.circle(r/10); t.end_fill() t.left(90); t.up(); t.forward(r); t.right(90) t.color("red") t.begin_fill(); t.circle(r/10); t.end_fill() t.hideturtle()
def dragg(turtle, x, y): turtle.up() turtle.ondrag(None) # disable ondrag event inside drag_handler turtle.goto(x, y) turtle.ondrag(lambda x, y, turtle=turtle: dragg(turtle, x, y))
def drawo(x, y): t.up() t.goto(x + 67, y + 5) t.down() t.circle(62)
tle.forward(l) tle.left(120) tle.end_fill() """triangle_bleu(100) tle.left(120) triangle_bleu(100) tle.forward(100) tle.right(120) triangle_bleu(100)""" triangle_bleu(200) tle.left(60) tle.forward(200) tle.left(30) tle.up() tle.forward(50) tle.down() tle.left(150) triangle_bleu(150) tle.exitonclick() # Une fonction qui ne retourne rien est appellée une procédure. # Ceci dit, en Python, None est retourné par défaut #triangle_bleu(300) ############################## # EXERCICES # ##############################
import turtle # 设置画布大小 turtle.setup(800, 800) turtle.speed(0) # 1画轮廓 #1-1 顶部 turtle.up() turtle.goto((150, 150)) turtle.down() turtle.fillcolor('#ffff00') turtle.begin_fill() turtle.left(90) turtle.circle(150, 180) #1-2中间 turtle.forward(300) #1-3底部 turtle.circle(150, 180) turtle.forward(300) turtle.end_fill() # 画眼睛 turtle.fillcolor('white') turtle.begin_fill() turtle.width(5) turtle.up() #抬笔 turtle.left(90) turtle.fd(150) turtle.right(90)
def restore(): pos, angl = q.pop() turtle.up() turtle.setposition(pos) turtle.seth(angl) turtle.down()
def draw_hexagon( x, y, count, color, ): """ В данной функции 72.17 получена путем решения уравнения, где 500=8x,x=62.5, что равно половине длинны шестиугольника, а сторона шестиугольника=62,5/cos(30)=72,17 далее функция адаптируется к количеству путем домножения стороны на коэф=4/кол-во шестиугольников """ for j in range(0, count): t.up() t.goto(x, y) t.down() x_side = (72.17 * 4 / count * sqrt(3)) / 2 y_side = 72.17 * 4 / count / 2 t.setheading(-90) t.up() t.fd(y_side) t.down() t.pencolor("black") t.fillcolor(color) t.begin_fill() t.left(120) t.fd(72.17 * 4 / count) right_fd(60, 72.17 * 4 / count, 6) t.end_fill() x = x + (125 * (4 / count)) x = -100 y = y - (125 * (4 / count)) t.up() t.goto(x, y) t.down() for i in range(2, count + 1): if i % 2 == 1: for j in range(0, count): t.up() t.goto(x, y + 10 * 4 / count) t.down() x_side = (72.17 * 4 / count * sqrt(3)) / 2 y_side = 72.17 * 4 / count / 2 t.setheading(-90) t.up() t.fd(y_side) t.down() t.pencolor("black") t.fillcolor(color) t.begin_fill() t.left(120) t.fd(72.17 * 4 / count) right_fd(60, 72.17 * 4 / count, 6) t.end_fill() x = x + (125 * (4 / count)) else: for j in range(0, count): t.up() t.goto(x + 62 * 4 / count, y + 10 * 4 / count) t.down() x_side = (72.17 * 4 / count * sqrt(3)) / 2 y_side = 72.17 * 4 / count / 2 t.setheading(-90) t.up() t.fd(y_side) t.down() t.pencolor("black") t.fillcolor("green") t.begin_fill() t.left(120) t.fd(72.17 * 4 / count) right_fd(60, 72.17 * 4 / count, 6) t.end_fill() x = x + (125 * (4 / count)) x = -100 y = y - (115 * (4 / count)) t.up() t.goto(x, y) t.down()