def a(fill=False): '''draws a capital A.''' turtle.setheading(0) if fill: bf() fd(10) turtle.goto(turtle.xcor() + 5, turtle.ycor() + 40) fd(10) turtle.goto(turtle.xcor() + 5, turtle.ycor() - 40) fd(10) turtle.goto(turtle.xcor() - 15, turtle.ycor() + 110) turtle.setx(turtle.xcor() - 10) turtle.goto(turtle.xcor() - 15, turtle.ycor() - 110) if fill: ef() pu() turtle.goto(turtle.xcor() + 17, turtle.ycor() + 50) pd() if fill: cfc = fc() fc(turtle.getscreen().bgcolor()) bf() fd(6) turtle.goto(turtle.xcor() - 3, turtle.ycor() + 40) turtle.goto(turtle.xcor() - 3, turtle.ycor() - 40) if fill: ef() fc(cfc) pu() turtle.goto(turtle.xcor() + 33, turtle.ycor() - 50) pd()
def draw(list_rectangles, list_squares): """ draw list of rec ands squares """ for rec in list_rectangles: rec = rec.to_dictionary() turtle.up() turtle.setx(rec["x"]) turtle.sety(rec["y"]) turtle.down() turtle.fd(rec["width"]) turtle.right(90) turtle.fd(rec["height"]) turtle.right(90) turtle.fd(rec["width"]) turtle.right(90) turtle.fd(rec["height"]) for square in list_squares: size = square["size"] turtle.up() turtle.setx(square["x"]) turtle.sety(square["y"]) turtle.down() turtle.fd(size) turtle.right(90) turtle.fd(size) turtle.right(90) turtle.fd(size) turtle.right(90) turtle.fd(size) turtle.right(90)
def plot(k): numPrimes = 0 turtle.pu() turtle.speed(0) turtle.pencolor("green") turtle.dot(5) n = 1 dir = 1 for i in range(100): for j in range(n): turtle.setx(turtle.xcor() + 7 * dir) if k in l: # if isPrime(k): # print(k) numPrimes += 1 turtle.pencolor("red") else: turtle.pencolor("black") turtle.dot(5) k += 1 for j in range(n): turtle.sety(turtle.ycor() + 7 * dir) # if isPrime(k): if k in l: # print(k) numPrimes += 1 turtle.pencolor("red") else: turtle.pencolor("black") turtle.dot(5) k += 1 n += 1 dir = -dir # print (k - 1, numPrimes) turtle.hideturtle()
def main(): number = int(input("How many trees in your forest?")) answer = str(input("Is there a house in the forest?")) turtle.up() turtle.setx(-225) turtle.sety(-225) turtle.down() maxheight, maxheightPosition, woodUsed = drawTree(number) if "y" in answer.lower(): drawHouse(100) woodUsed += (2 * 100 + 2 * math.sqrt(2) * 100) drawStar(maxheight, number - maxheightPosition) enter = str(input("Night is done... Press Enter for Day")) right = '' if enter == right: print('We have %d units of lumber for the building' % woodUsed) print('We will build a house with walls %d tall' % (woodUsed / (2 + math.sqrt(2)))) turtle.clear() turtle.up() turtle.setx(-225) turtle.sety(-225) turtle.down() drawHouse(woodUsed / (2 + math.sqrt(2))) drawSun(woodUsed) else: exit() turtle.getscreen()._root.mainloop()
def drawRectanglePattern(centerX, centerY, offset, width, height, count, rotation): # keep track of iterations i = 0 # rotation tr.setheading(rotation) while i < count: # make turtle go to center point tr.penup() tr.setx(centerX) tr.sety(centerY) # set random color tr.pencolor(setRandomColor()) # have it draw a rectangle with correct position tr.forward(offset) tr.pendown() setRandomColor() drawRectangle(width, height) tr.left(360 / count) # keep track of iterations i += 1
def set(turtle, x, y): turtle.pencolor("black") turtle.pensize(2) turtle.hideturtle() turtle.penup() turtle.setx(x) turtle.sety(y)
def do_coordinate(*args, **kwargs): turtle.penup() x = float(input("Insert x: ")) y = float(input("Insert y: ")) turtle.setx(x) turtle.sety(y) turtle.pendown()
def ff(): turtleturner = 90 myxloc = turtle.xcor turtle.penup() turtle.setx(0) turtle.sety(0) turtle.setheading(random.randrange(0, 360)) turtle.pendown() turtlecolorr = random.randrange(0, 16) turtlecolorg = random.randrange(0, 16) turtlecolorb = random.randrange(0, 16) turtle.color(turtlecolorr * 16, turtlecolorg * 16, turtlecolorb * 16) turtle.pencolor(turtlecolorr * 16, turtlecolorg * 16, turtlecolorb * 16) turtle.fillcolor(turtlecolorr * 16, turtlecolorg * 16, turtlecolorb * 16) for zzz in range(1, 1000): myXLoc = turtle.xcor() print(myXLoc) turtle.forward(random.randrange(1, 2)) turtle.right(turtleturner) turtle.forward(random.randrange(1, 2) * turtle.distance(0, 0) + random.randrange(-30, 30)) turtleturner = turtleturner * -1 turtle.right(turtleturner) turtle.forward(random.randrange(1, 2)) turtle.right(turtle.distance(0, 0) / random.randrange(1000, 2500)) turtle.update()
def write_table(self): # 绘制x-y轴, 用于后期对称绘字 turtle.setx(-600) turtle.setx(600) turtle.home() turtle.sety(-600) turtle.sety(600) turtle.home() turtle.dot('red') turtle.seth(135) turtle.setpos(-600, 600) turtle.home() turtle.seth(45) turtle.setpos(600, 600) turtle.home() turtle.seth(45) turtle.setpos(600, -600) turtle.home() turtle.seth(45) turtle.setpos(-600, -600) turtle.home() print(turtle.xcor()) # xcor() return x的位置 print(turtle.ycor()) # turtle.forward(20) # forward(distance) 移动distance的距离 turtle.up() # 移到某位值而不绘制路线 turtle.goto(20, 30) turtle.bgcolor('orange') turtle.mainloop()
def tabuleiro(posx,posy,lado, n, cor1, cor2): turtle.speed(0) #posição inicial turtle.penup() turtle.goto(posx, posy) turtle.pendown() for i in range(1,n+1): #desenha linha i if i%2 == 0: par = cor2 impar = cor1 else: par = cor1 impar = cor2 for j in range(1,n+1): # desenha coluna j da linha i if j%2 == 0: quadrado(turtle.xcor(), turtle.ycor(), lado, par) else: quadrado(turtle.xcor(), turtle.ycor(), lado, impar) turtle.setx(turtle.xcor() + lado) turtle.penup() turtle.goto(posx, turtle.ycor() + lado) turtle.pendown()
def draw_pyramid(pyramid): index = 0 #Assign the "turtle" coordinates of each node in the pyramid's list. pyramid.assignTurtleCoordinates() #Draw the pyramid of nodes to the screen while index < len(pyramid.nodes_list): #Draw the node's value (numerical value) to the screen #based on the Node's turtle x,y coordinates; offset these #coordinates by subtracting the dot diameter from them, so when #a dot is drawn on the node (for visited and unvisted nodes), #the dot is on the number rather than next to it turtle.setx(pyramid.nodes_list[index].turtle_x + -(DOT_DIAMETER)) turtle.sety(pyramid.nodes_list[index].turtle_y + -(DOT_DIAMETER)) turtle.write(str(pyramid.nodes_list[index].value), font=("Arial", 16, "normal")) #Draw the dot on the node (because, all unvisited nodes have #a dot as well) turtle.setx(pyramid.nodes_list[index].turtle_x) turtle.sety(pyramid.nodes_list[index].turtle_y) #Draw the dot with the 'NO_DOTS_COLOR' color to indicate that #this node has not dots at it yet turtle.dot(DOT_DIAMETER, NO_DOTS_COLOR) index += 1
def cursor_stamp(): turtle.penup() for i in range (1, 400): turtle.stamp() turtle.fillcolor(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) turtle.setx(random.randint(-300, 300)) turtle.sety(random.randint(-200, 200))
def convert(command_type, command_value, command_stat): if (int(command_type) == 0): turtle.clearscreen() elif (int(command_type) == 1): turtle.forward(int(command_value)) elif (int(command_type) == 2): turtle.backward(int(command_value)) elif (int(command_type) == 3): turtle.left(int(command_value)) elif (int(command_type) == 4): turtle.right(int(command_value)) elif (int(command_type) == 5): turtle.up() elif (int(command_type) == 6): turtle.down() elif (int(command_type) == 7): turtle.setx(int(command_value)) elif (int(command_type) == 8): turtle.sety(int(command_value)) elif (int(command_type) == 9): turtle.pensize(int(command_value)) elif (int(command_type) == 10): r = (command_value[0] + command_value[1] + command_value[2]) g = (command_value[3] + command_value[4] + command_value[5]) b = (command_value[6] + command_value[7] + command_value[8]) turtle.pencolor((int(r), int(g), int(b))) else: print("Error on command ", command_stat)
def main(): boyut = int(input('Boyut girin: ')) side = 50 x_coord = -250 y_coord = 300 turtle = Turtle() turtle.speed('fastest') turtle.pensize(5) fill = False for i in range(boyut**2): if not i % boyut: y_coord -= side turtle.penup() turtle.setx(x_coord) turtle.sety(y_coord) turtle.pendown() if not boyut % 2: fill = not fill if fill: turtle.begin_fill() for _ in range(4): turtle.forward(side) turtle.right(90) turtle.forward(side) turtle.end_fill() fill = not fill
def tGraph(word='F', theta=0, alpha=0, step=10, x0=0, y0=0): #Run, turtle, RUN!!! #tr.clear() tr.radians() tr.speed(0) tr.pu() tr.setx(x0) tr.sety(y0) tr.seth(alpha) tr.pd() st = [] for c in word: if c == 'F': tr.fd(step) if c == 'b': tr.pu() tr.bk(step) tr.pd() if c == '[': st.append({'x': tr.xcor(), 'y': tr.ycor(), 'ang': tr.heading()}) if c == ']': pos = st.pop() tr.pu() tr.setx(pos['x']) tr.sety(pos['y']) tr.seth(pos['ang']) tr.pd() if c == '+': tr.lt(theta) if c == '-': tr.rt(theta)
def main(): size = get_side_length() mycolor = get_color() # start to draw signs turtle.speed() # Make pen up avoid lines turtle.penup() # Draw first sign draw_plus_sign(size, mycolor) # Move to the right turtle.setx(turtle.xcor() + 3 * size) # Draw second sign draw_plus_sign(size, mycolor) # Move to the top turtle.goto(turtle.xcor() - 3 * size, turtle.ycor() + 3 * size) # Draw third sign draw_plus_sign(size, mycolor) # Move to the left turtle.goto(turtle.xcor() - 3 * size, turtle.ycor() - 3 * size) # Draw fourth sign draw_plus_sign(size, mycolor) # Move to the bottom turtle.goto(turtle.xcor() + 3 * size, turtle.ycor() - 3 * size) # Draw fifth sign draw_plus_sign(size, mycolor) turtle.down()
def render(RNA,matches): '''given and RNA sequence and paris of binded bases, draws the backbone and the pairs''' length = 500 turtle.setx(-250) turtle.pendown() turtle.forward(length) turtle.left(180) turtle.penup() turtle.forward(length) turtle.left(180) for i in range(0,len(RNA)-1): #draw RNA backbone turtle.dot(5,"blue") turtle.write(RNA[i],font = ("arial",16,"normal")) turtle.forward(length/(len(RNA)-1)) turtle.dot(5,"blue") turtle.write(RNA[len(RNA)-1],font = ("arial",16,"normal")) turtle.pencolor("red") start_list = 0 for i in range(1,len(matches)): if matches[i][1] > matches[i-1][1]: #divide the matches into individual loops draw_sec(RNA,matches[start_list:i]) start_list = i if i == len(matches)-1: #draw the last loop draw_sec(RNA,matches[start_list:i+1]) turtle.done()
def plot_plain_stars(picture_size, coordinates_dict): ''' Function for drawing a picture based off the given coordinates from the read_coords function. ''' turtle.bgcolor('black') turtle.color('white') turtle.hideturtle() turtle.speed(100) turtle.delay(0) turtle.tracer(0, 0) turtle.update() turtle.screensize(picture_size, picture_size) # Set up for the turtle commands for i in coordinates_dict: turtle.penup() # Picks up pen so the dots are not connected turtle.setx(coordinates_dict[i][0] * (picture_size / 2)) turtle.sety(coordinates_dict[i][1] * (picture_size / 2)) # Sets the coordinates base off the given size turtle.pendown() turtle.begin_fill() turtle.forward(2) turtle.left(90) turtle.forward(2) turtle.left(90) turtle.forward(2) turtle.end_fill()
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 interProfileLine(): fly(0, 200) t.seth(-115) t.circle(500, 24) t.setx(0) t.seth(-90) t.circle(468, 25.1)
def draw(mode=levy, count=1, baseStep=3, numIters=12): steps = mode.initialStep connectorAngle = mode.connectorAngle if count == 1: turtle.penup() turtle.pensize(2) turtle.speed(0) turtle.setx(mode.x) turtle.sety(mode.y) turtle.setheading(mode.initialStep[0][0]) turtle.pendown() draw(mode, count + 1, baseStep, numIters) else: if count <= numIters: newSteps = mode.nextStep(steps) for i in newSteps: steps.append(i) draw(mode, count + 1, baseStep, numIters) else: for step in steps: for i in step: turtle.setheading(i) turtle.forward(baseStep) if mode.connectorAngle: turtle.setheading(connectorAngle) turtle.forward(baseStep) connectorAngle += mode.deltaAngle
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 _go_to_point(c): """finds path to point and draws dot""" penup() setx(c[0]) sety(c[1]) pendown() dot(5, "blue")
def turtle_picta(self, full_id, res_frames): print() print("An image will now be printed for the secondary structures.") print("Closing the turtle window will close the analysis program.") input("Press enter to continue: ") space = full_id.index(' ') resnum = int(full_id[0:space]) # set length of segment per frame to appear in turtle screen t_width = 1 # make sure turtle screen can support width of all frames screen_x = int(t_width * res_frames * t_width + 500) screen_y = 500 turtle.screensize(screen_x, screen_y) turtle.up() turtle.setx(int(0.5 * -t_width * res_frames * t_width) + 5) turtle.sety(350 - 12 * resnum) turtle.down() turtle.speed('fastest') turtle.width(10) turtle.shape("square") with open(self.file_dir, "r") as f: for line in f: line = line.replace('\n', ' ').replace('\r', '') if line.startswith(full_id) == True: ind_let = self.letters.index(line[len(line) - 2]) turtle.color(self.colours[ind_let]) turtle.forward(t_width)
def grid(): a = turtle.color() turtle.color(gridColour) turtle.penup() turtle.goto(0-offsetX,0-offsetY) turtle.pendown() for h in getGridString(gridSizeY): turtle.forward(10*scale) turtle.left(90) for i in getGridString(gridSizeX): if i == "a": for j in "aaa": turtle.forward(10*scale) turtle.left(90) turtle.forward(20*scale) turtle.left(90) elif i =="b": for j in "aaa": turtle.forward(10*scale) turtle.left(90) turtle.setx(0-offsetX) turtle.sety(turtle.ycor() + 10*scale) if homeDot: turtle.penup() turtle.home() turtle.pendown() turtle.dot(5*scale)
def supersquare(posx, posy): turtle.penup() turtle.setx(posx) turtle.sety(posy) turtle.pendown() for x in xrange (5,100,5): square (x)
def drawBrick(): troodat = 1 rowa = 1 while troodat == 1: if rowa == 1: turtlesx = turtle.xcor() turtlesy = turtle.ycor() turtle.forward(100) turtle.left(90) turtle.forward(50) turtle.left(90) turtle.forward(100) turtle.left(90) turtle.forward(50) turtle.left(90) turtle.forward(100) turtle.update() if turtlesx >= 960: turtle.update() turtle.setx(-1010) turtle.sety(turtle.ycor() + 50) if turtlesy >= 0: break ''' for halfBrick in range(0,1):
def theOlympicRings(): # 绘制奥运五环 turtle.pensize(10) turtle.pencolor("blue") turtle.circle(100) turtle.up() turtle.setx(220) turtle.down() turtle.pencolor("black") turtle.circle(100) turtle.up() turtle.setx(440) turtle.down() turtle.pencolor("red") turtle.circle(100) turtle.up() turtle.goto(105, -105) turtle.down() turtle.pencolor("yellow") turtle.circle(100) turtle.up() turtle.goto(325, -105) turtle.down() turtle.pencolor("green") turtle.circle(100) turtle.done()
def getPosition(x, y): turtle.setx(x) turtle.sety(y) print(x, y)
def stars(): starx = turtle.xcor() colortup = (220,220,220) while turtle.ycor()>screen.window_height()/2/6: turtle.pencolor(colortup) starnum = random.randint(1,5)+1 starcount = 0 turtle.penup() while starcount <= starnum: startangle = random.randint(0,90) turtle.lt(startangle) starsize = random.randint(5,10) for i in range(5): turtle.fd(starsize) turtle.rt(720/5) turtle.rt(startangle) turtle.penup() turtle.setx(turtle.xcor()+random.randint(round(screen.window_width()/starnum)-50,round(screen.window_width()/starnum)+30)) turtle.pendown() starcount +=1 turtle.penup() turtle.sety(turtle.ycor()-50) turtle.setx(starx) turtle.pendown() updown = random.randint(200,255) colortup = (updown,updown,updown)
def main(max): """ Starts the whole process - Asks for input of number of raindrops - Starts the area with value of 0 - Sets the postition of the starting point at -250,-250 - turtle starts up - Sets turtle speed - defines areaOfRaindrops - starts the drawing of the square - Prints the calculation of the raindrops area """ numberOfRaindrops = int(input("Number of raindrops: ")) wrong_number(numberOfRaindrops) area = 0 t.up() t.setx((-boundary())) t.sety((-boundary())) t.speed(7) draw_Square() areaOfRaindrops = draw_circle(numberOfRaindrops, area) print("The total area of the raindrops is:" + str(areaOfRaindrops) + " square units") t.done()
def draw_circle(x,y,radius): turtle.penup() turtle.setx(x) turtle.sety(y) turtle.begin_fill() turtle.pendown() turtle.circle(radius) turtle.end_fill()
def init(): turtle.setworldcoordinates(-WINDOW_WIDTH / 2, -WINDOW_WIDTH / 2, WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2) turtle.up() turtle.setheading(0) turtle.hideturtle() turtle.title('Snakes') turtle.showturtle() turtle.setx(-225) turtle.speed(0)
def hola(): '''draws hola world message in cool green color''' turtle.setheading(0) pu() turtle.setx(-215) pd() draw_letters(True, "green", h, o, l, a) pu() turtle.setx(turtle.xcor() + 30) draw_letters(True, "green", w, o, r, l, d)
def init(x , y): """ :input: x and y corrdinate for setting intial/starting corrdinates :pre:(relative) pos (0,0), heading (east), up :post:(relative) pos (x,y), heading (east), up :return: None """ t.up() t.title('forest') t.setx(x) t.sety(y)
def main(): rd=int(input("Enter the recursion depth: ")) length=int(input('Enter the length of the square: ')) turtle.speed("fastest") turtle.penup() turtle.setx(-300) turtle.sety(-300) turtle.pendown() drawNestedSquare(rd,length) print('Total Distance travelled by the pointer: ',sum) input("Hit enter to exit...")
def placeX(self,x,y): turtle.up() tx=x*harsha ty=y*harsha turtle.setx(tx) turtle.sety(ty) turtle.down() turtle.goto(tx-harsha,ty-harsha) turtle.goto(tx-harsha,ty) turtle.goto(tx,ty-harsha) turtle.up() turtle.goto(-harsha,-harsha) turtle.down() return
def init(): """ sets the width of window and initialise parameters :return: """ t.setworldcoordinates(-WINDOW_WIDTH / 2, -WINDOW_WIDTH / 2, WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2) t.up() t.setheading(0) t.hideturtle() t.title('Forest') t.showturtle() t.setx(-225) t.speed(0)
def init(): """ :pre: pos (0,0), heading (east), up :post: pos (-180,0), heading (east), up :return: None """ turtle.up() x_cor = -180 y_cor = 0 turtle.setx(x_cor) turtle.sety(y_cor) print("Starting Position (" + str(x_cor) + "," + str(y_cor) + ")") turtle.setheading(0) turtle.title("Typography")
def checkpos(turtlelist): screen.tracer(0) for turtle in turtlelist: x = turtle.xcor() y = turtle.ycor() if x > 200: turtle.setx(-200) elif x < -200: turtle.setx(200) if y > 200: turtle.sety(-200) elif y < -200: turtle.sety(200) screen.tracer(1) return
def init_for_day(): """ Initialize for drawing in the day. (-WINDOW_WIDTH/2, -WINDOW_HEIGHT/2) is in the lower left and(WINDOW_WIDTH/2, WINDOW_HEIGHT/2) is in the upper right. : pre: (relative) pos (0,0), heading (east), up : post:(relative) pos (-500,-333.33), heading (east), up heading (east), up : return: None """ turtle.up() turtle.hideturtle() turtle.setx(-WINDOW_WIDTH/2) turtle.sety(-WINDOW_HEIGHT/3) turtle.setheading(0) turtle.showturtle()
def draw_circle(x,y,radius): """ A function that draws a circle centered at point (x,y) with a radius="param radius: :param x: :param y: :param radius: :return:None """ turtle.penup() turtle.setx(x+radius) turtle.sety(y) turtle.begin_fill() turtle.pendown() turtle.circle(radius) turtle.end_fill() return None
def __init__(self): for k in range(0,harsha*3,harsha): for j in range(0,harsha*3,harsha): #a=turtle.pos() turtle.sety(j) turtle.setx(k) for i in range(4): turtle.right(90) turtle.forward(harsha) #turtle.setx(k) turtle.up() turtle.setx(-harsha) turtle.sety(-harsha) turtle.down() self.ox=-harsha self.oy=-harsha
def init(): """ Initialize for drawing in the night. (-WINDOW_WIDTH/2, -WINDOW_HEIGHT/2) is in the lower left and(WINDOW_WIDTH/2, WINDOW_HEIGHT/2) is in the upper right. : pre: (relative) pos (0,0), heading (east), down : post:(relative) pos (-333.33,0), heading (east), up : return: None """ turtle.setworldcoordinates(-WINDOW_WIDTH / 2, -WINDOW_HEIGHT / 2, WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2) turtle.up() turtle.hideturtle() turtle.setx(-WINDOW_WIDTH / 3) #turtle.setheading(0) turtle.showturtle()
def hello(): '''draws hello world message in rainbow colors''' turtle.setheading(0) pu() turtle.setx(-265) pd() draw_letters(True, "red", h) draw_letters(True, "dark orange", e) draw_letters(True, "yellow", l) draw_letters(True, "green", l) draw_letters(True, "blue", o) pu() turtle.setx(turtle.xcor() + 30) draw_letters(True, "blue", w) draw_letters(True, "blue violet", o) draw_letters(True, "violet", r) draw_letters(True, "pink", l) draw_letters(True, "red", d)
def city_circle(city): turtle.penup() turtle.setx(city.xcoord) turtle.sety(city.ycoord) if city.getpop() > 0 and city.getpop() < 90001: turtle.setx(turtle.xcor() + 2) turtle.pendown() turtle.circle(2) turtle.penup() turtle.setx(turtle.xcor() - 2) if city.getpop() > 90000: turtle.setx(turtle.xcor() + 3) turtle.pendown() turtle.begin_fill() turtle.circle(3) turtle.end_fill() turtle.penup() turtle.setx(turtle.xcor() - 3)
def draw_line(x,y,heading,length): """ A function that draws a line start at point (x,y) in the direction param:heading for distance param:length. :param x: :param y: :param heading: :param length: :return: None """ turtle.penup() turtle.setx(x) turtle.sety(y) turtle.pendown() turtle.setheading(0) turtle.left(heading) turtle.forward(length) return None
def grelha_2(dim,lado): """Desenha uma grelha dim x dim em que cada célula tem de lado lado.""" turtle.color("gray") tam = (dim*lado) x = -tam//2 y = tam//2 turtle.penup() turtle.goto(x,y) for lin in range(dim): # Desenha linha de quadrados for col in range(dim): turtle.pendown() quadrado(lado) turtle.penup() turtle.setx(turtle.xcor() + lado) # reposiciona turtle.penup() turtle.setposition(x, turtle.ycor()-lado) turtle.hideturtle()
def joonistaLipp(riik, lipud=lipud): värvid = lipud[riik] turtle.pendown() for värv in värvid: turtle.begin_fill() turtle.fillcolor(värv) turtle.forward(100) turtle.right(90) turtle.forward(20) turtle.right(90) turtle.forward(100) turtle.right(90) turtle.forward(20) turtle.end_fill() turtle.sety(turtle.ycor()-20) turtle.right(90) turtle.penup() turtle.sety(turtle.ycor()+60) turtle.setx(turtle.xcor()+110)
def draw_flag(height): tt.penup() # assign parameters defined from # https://en.wikipedia.org/wiki/Flag_of_the_United_States A = height B,C = 1.9*A, (7.0/13.0)*A D = 2.0*B/5.0 E = C/10.0 G = D/12.0 L = A/13.0 K = 4.0*L/5.0 # draw the bottom 6 stripes for color in ['red','white']*3: draw_rectangle(B, L, color) tt.sety(tt.ycor()+L) # draw the top left blue rectangle draw_rectangle(D, C, 'blue') # draw the top right 7 stripes tt.setx(tt.xcor()+D) for color in ['red','white']*3: draw_rectangle(B-D, L, color) tt.sety(tt.ycor()+L) draw_rectangle(B-D, L, 'red') tt.sety(tt.ycor()+L) # draw the 50 stars tt.setx(G) tt.sety(tt.ycor()-E) nums_star = [6,5]*4 nums_star.append(6) for nstar in nums_star: if (nstar == 5): tt.setx(tt.xcor()+G) for i in range(nstar): draw_star(K, 'white') tt.setx(tt.xcor()+2.0*G) tt.setx(G) tt.sety(tt.ycor()-E)
def main(): x=int(input('Enter the number of trees: ')) house=input('Is there a House in the forest (y/n)? ') StartPos() findmax=sketch(x,house) input('Night is done, press enter for the day') turtle.clearscreen() turtle.penup() turtle.setx(-150) turtle.sety(-150) turtle.pendown() total=WoodQuantity(findmax) """ Adding the wood obtained from the trunks and the house built during the night """ dayTime(total+341.4) showSun() print('Day is done, house is built, ') input('Press ENTER to quit')
def view(self): import turtle coords = [ref.image_coord_mm for ref in self.reflections] x, y = zip(*coords) min_x, max_x = min(x), max(x) min_y, max_y = min(y), max(y) low = min(min_x, min_y) high = max(max_x, max_y) turtle.title("Reflections from " + self.reflections_filename) turtle.setworldcoordinates(low, low, high, high) turtle.pen(speed=0,pensize=2) turtle.hideturtle() for ref in self.reflections: (x, y) = ref.image_coord_mm turtle.penup() turtle.setx(x) turtle.sety(y) turtle.pendown() turtle.circle(1.0, steps=8) turtle.done()
def checkpos(turtlelist, screen): """ Takes a list of turtle objects and a Screen object. Sets the turtles to the opposite edge of the screen. """ screen.tracer(0) for turtle in turtlelist: turtle.penup() x = turtle.xcor() y = turtle.ycor() if x > 200: turtle.setx(-200) elif x < -200: turtle.setx(200) if y > 200: turtle.sety(-200) elif y < -200: turtle.sety(200) turtle.pendown() screen.tracer(1) return
def duzyKwadrat(dlBokMalKw): numPow = 1 wnd = turtle.Screen() wnd.colormode(255) turtle.fillcolor(255, 255, 0) turtle.pu() turtle.bk(225) turtle.lt(90) turtle.bk(225 - dlBokMalKw) turtle.pd() turtle.begin_fill() while(numPow <= 4): turtle.fd(450 - dlBokMalKw * 2 - 15) turtle.rt(90) numPow = numPow + 1 turtle.end_fill() turtle.pu() turtle.setx(0) turtle.sety(0) turtle.pd() turtle.rt(90)
def oczySowy(r, bokKw, bokMalKw, rMalegoKola): rKolaWOku = bokMalKw / 8 turtle.pu() turtle.rt(90) turtle.fd(r - rMalegoKola*3) turtle.rt(90) turtle.pd() elementSowy(r, bokMalKw, bokMalKw / 4) powrNaSrodekSowy(r, bokMalKw) turtle.lt(90) turtle.pu() turtle.fd(r*3) turtle.pd() turtle.lt(90) elementSowy(r, bokMalKw, bokMalKw / 4) powrNaSrodekSowy(r, bokMalKw) turtle.lt(180) turtle.fillcolor(209, 183, 255) turtle.begin_fill() turtle.circle(rMalegoKola) turtle.end_fill() turtle.lt(180) turtle.begin_fill() turtle.circle(rMalegoKola) turtle.end_fill() turtle.pu() turtle.rt(90) turtle.setx(0) turtle.sety(0) turtle.fd(r) turtle.lt(90) turtle.pd() turtle.begin_fill() turtle.circle(rMalegoKola) turtle.end_fill() turtle.lt(180) turtle.begin_fill() turtle.circle(rMalegoKola) turtle.end_fill()
def drawFrame(self, i, j, colour=None): if colour is not None: turtle.color("red") else: turtle.color("black") turtle.ht() turtle.up() turtle.tracer(10000,0) x = self.index_to_pixel(i, "x") y = self.index_to_pixel(j, "y") print("going to " + str(x) + " " + str(y)) turtle.setx(x) turtle.sety(y) turtle.down() turtle.forward(self.xside_box) turtle.left(90) turtle.forward(self.yside_box) turtle.left(90) turtle.forward(self.xside_box) turtle.left(90) turtle.forward(self.yside_box) turtle.left(90) turtle.update()
def gridlines(physics=False,xmin=-100,xmax=100): # Makes graph for window import turtle ymin = -(abs(xmin-xmax)/2.) ymax = abs(xmin-xmax/2.) turtle.setworldcoordinates(xmin,ymin,xmax,ymax) turtle.home() turtle.hideturtle() xadjust = 0 yadjust = 0 if physics: #physics window is fixed-size xadjust = -50 yadjust = -50 turtle.up() turtle.setx(xmin + xadjust) #starting x-axis turtle.sety(yadjust) turtle.down() turtle.setheading(0) xvals = xmin graph_range = 10 + 1 if physics: graph_range = 20 + 1 for x in range(graph_range): turtle.write(str(turtle.xcor()-xadjust)) #writing values for x axis turtle.forward(abs(xmin-xmax)/10.) #advancing along x axis xvals += abs(xmin-xmax)/10. turtle.update() turtle.setx(0 + xadjust) turtle.sety(0 + yadjust) turtle.sety(ymin + yadjust) #starting y-axis turtle.setheading(90) yvals = ymin for y in range(graph_range): turtle.write(str(turtle.ycor()-yadjust)) #writing values for y axis turtle.forward(abs(ymin-ymax)/10.) #advancing along y axis yvals += abs(ymin-ymax)/10. turtle.update() turtle.setx(0 + xadjust) turtle.setx(0 + yadjust) turtle.penup() return xadjust, yadjust return
import turtle radius = 90#eval(input("Enter a radius: ")) turtle.circle(radius) turtle.penup() turtle.setx(turtle.xcor()+(radius*2)) turtle.pendown() turtle.circle(radius) turtle.penup() turtle.sety(turtle.ycor()+(radius*2)) turtle.pendown() turtle.circle(radius) turtle.penup() turtle.setx(turtle.xcor()-(radius)*2) turtle.pendown() turtle.circle(radius) turtle.done()