def setup(): turtle.hideturtle() turtle.tracer(1e3,0) turtle.left(90) turtle.penup() turtle.goto(0,-turtle.window_height()/2) turtle.pendown()
def set(): #set of parameters turtle.hideturtle() turtle.tracer(1e3,1) turtle.left(95) turtle.penup() turtle.goto(0,-turtle.window_height()/2) turtle.pendown()
def 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 init(): global totalWood global maxHeight trees = int(input("How many trees in your forest?")) house = input("Is there a house in the forest (y/n)?") turtle.penup() turtle.setposition(-330, -100) if(trees < 2 and house == "y"): print("we need atleast two trees for drawing house") turtle.done() else: position_of_house = random.randint(1, trees - 1) counter = 1 house_drawn = 0 while counter <= trees : if counter - 1 == position_of_house and house_drawn == 0: y = drawHouse(100) house_drawn = 1 totalWood = totalWood + y spaceBetween(counter, trees) else: type_of_tree = random.randint(1, 3) wood, height = drawTrees(type_of_tree) spaceBetween(counter, trees) totalWood = totalWood + wood counter = counter + 1 if height > maxHeight: maxHeight = height turtle.penup() draw_star(maxHeight) turtle.hideturtle() input("Press enter to exit")
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 main(argv): user_file = "" # User GetOpt to Pull File from Command Line try: opts, args = getopt.getopt(argv,"hi:",["ifile="]) except getopt.GetoptError: print("name-strip.py -i <input_file>") sys.exit(2) for opt, arg in opts: if opt in ("-h", "--help"): print("name-strip.py HELP\n\t-i <input_file>\t selects input file csv to interpret as map") sys.exit() elif opt in ("-i", "--ifile"): user_file = arg # Quit if no File Given if user_file == "": print("No file entered. Program terminating.") sys.exit() # Set Up CSV Reader mapReader = csv.reader(open(user_file, newline=''), delimiter=',', quotechar='|') # Iterate Through CSV for map_item in mapReader: #print("Map Item:", map_item) if map_item[0] == "c": create_city(map_item) else: create_road(map_item) turtle.hideturtle() turtle.done()
def viewer(dna): '''Display ORFs and GC content for dna.''' dna = dna.upper() # make everything upper case, just in case t = turtle.Turtle() turtle.setup(1440, 240) # make a long, thin window turtle.screensize(len(dna) * 6, 200) # make the canvas big enough to hold the sequence # scale coordinate system so one character fits at each point setworldcoordinates(turtle.getscreen(), 0, 0, len(dna), 6) turtle.hideturtle() t.speed(0) t.tracer(100) t.hideturtle() # Draw the sequence across the bottom of the window. t.up() for i in range(len(dna)): t.goto(i, 0) t.write(dna[i],font=("Helvetica",8,"normal")) # Draw bars for ORFs in forward reading frames 0, 1, 2. # Draw the bar for reading frame i at y = i + 1. t.width(5) # width of the pen for each bar for i in range(3): orf(dna, i, t) t.width(1) # reset the pen width gcFreq(dna, 20, t) # plot GC content over windows of size 20 turtle.exitonclick()
def Run(): #bounds nearRange = [0, 50] farRange = [50, 200] frusHL = 100 #Logic nearDist = random.uniform(nearRange[0], nearRange[1]) farDist = random.uniform(farRange[0], farRange[1]) d = frusHL * 2 an = nearDist af = farDist b = (d*d + af*af - an*an) / (2 * d) radius = math.sqrt(b*b + an*an) originY = -frusHL + b #text.insert('end', 'Origin: %d\n' % originY) #Render turtle.clear() turtle.hideturtle() turtle.tracer(0, 0) turtle.penup() turtle.goto(-farDist, frusHL) turtle.pendown() turtle.goto(-nearDist, -frusHL) turtle.goto(nearDist, -frusHL) turtle.goto(farDist, frusHL) turtle.goto(-farDist, frusHL) turtle.penup() DrawCircle(0, originY, radius); turtle.update()
def turtlePrint(board, width, height): turtle.hideturtle() turtle.speed(0) turtle.penup() turtle.goto(-210, -60) turtle.pendown() turtle.goto(20*width-210, -60) turtle.goto(20*width-210, 20*height-60) turtle.goto(-210, 20*height-60) turtle.goto(-210, -60) turtle.penup() for y in xrange(height): for x in xrange(width): turtle.penup() turtle.goto(20*x-200,20*y-50) turtle.pendown() if board[x][y] is 1: turtle.pencolor("green") turtle.dot(10) turtle.pencolor("black") elif board[x][y] is 2: turtle.dot(20) elif board[x][y] is 3: turtle.pencolor("red") turtle.dot(10) turtle.pencolor("black") elif board[x][y] is 8: turtle.pencolor("blue") turtle.dot() turtle.pencolor("black") turtle.exitonclick()
def drawBar(): turtle.penup() turtle.hideturtle() xAxis=-600 yAxis=-200 turtle.goto(xAxis,yAxis) turtle.color("green") turtle.fillcolor("green") failTurtle=turtle.Turtle() failTurtle.hideturtle() failTurtle.penup() failTurtle.goto(xAxis + 50,yAxis) failTurtle.color("red") failTurtle.fillcolor("red") drawAxis(xTurtle, False) drawAxis(yTurtle, True) yNoPassTurtle.hideturtle() yNoFailTurtle.hideturtle() for i in range(len(studentsYear)): studenPerYear = studentsYear[i] passNo=int(studenPerYear.passNum)*5 failNo=int(studenPerYear.failNum)*5 graphPlot(turtle,passNo,i,yNoPassTurtle,False, studenPerYear) graphPlot(failTurtle,failNo,i,yNoFailTurtle,True,studenPerYear) xAxis=xAxis+150 turtle.goto(xAxis,yAxis) failTurtle.goto(xAxis+50,yAxis)
def main(): depth = int(input("Enter depth(recursion) of tree:")) length = int(input("Enter total height of the tree:")) range_of_bushiness = 0 while range_of_bushiness == 0: bushiness = float(input("Enter bushiness ranging from 0.1 - 1.0 :")) if 0.1 <= bushiness <= 1.0: range_of_bushiness = 1 else: print("You entered the invalid value of bushiness please enter a valid value between 0.1 and 1.0") range_of_leafiness = 0 while range_of_leafiness == 0: leafiness = float(input("Enter leafiness ranging from 0.1 - 1.0 :")) if 0.1 <= leafiness <= 1.0: range_of_leafiness = 1 else: print("You entered the invalid value of leafiness, please enter a valid value between 0.1 and 1.0") init() drawTree(depth, length / 3, bushiness, leafiness) """turtle.done()""" turtle.hideturtle() input("Hit enter to close...")
def rysuj(): turtle.tracer(0, 0) # wylaczenie animacji co KROK, w celu przyspieszenia turtle.hideturtle() # ukrycie glowki zolwika turtle.penup() # podnosimy zolwia, zeby nie mazal nam linii podczas ruchu ostatnie_rysowanie = 0 # ile kropek temu zostal odrysowany rysunek for i in xrange(ILE_KROPEK): # losujemy wierzcholek do ktorego bedziemy zmierzac do = random.choice(WIERZCHOLKI) # bierzemy nasza aktualna pozycje teraz = turtle.position() # ustawiamy sie w polowie drogi do wierzcholka, ktorego wczesniej obralismy turtle.setpos(w_polowie_drogi(teraz, do)) # stawiamy kropke w nowym miejscu turtle.dot(1) ostatnie_rysowanie += 1 if ostatnie_rysowanie == OKRES_ODSWIEZENIA: # postawilismy na tyle duzo kropek, zeby odswiezyc rysunek turtle.update() ostatnie_rysowanie = 0 pozdrowienia() turtle.update()
def show(): turtle.hideturtle() turtle.speed(0) side = turtle.window_height()/7 grid(side) write(side) turtle.exitonclick()
def rectangle(length, width, x = 0, y = 0, color = 'black', fill = False): import turtle turtle.showturtle() turtle.penup() turtle.goto(x,y) turtle.color(color) turtle.pendown() if fill == True: turtle.begin_fill() turtle.forward(length) turtle.left(90) turtle.forward(width) turtle.left(90) turtle.forward(length) turtle.left(90) turtle.forward(width) turtle.end_fill() else: turtle.forward(length) turtle.left(90) turtle.forward(width) turtle.left(90) turtle.forward(length) turtle.left(90) turtle.forward(width) turtle.hideturtle()
def __init__(self, length=10, angle=90, colors=None, lsystem=None): import turtle self.length = length self.angle = angle if colors is None: self.colors = ['red', 'green', 'blue', 'orange', 'yellow', 'brown'] if lsystem is not None: self.lsystem(lsystem) # draw number self.ith_draw = 0 # origin of next draw self.origin = [0, 0] # bounding_box self._box = 0, 0, 0, 0 # turtle head north and positive angles is clockwise turtle.mode('world') turtle.setheading(90) turtle.speed(0) # fastest turtle.hideturtle() turtle.tracer(0, 1) # set pencolor self.pencolor()
def drawBoard(b): #set up window t.setup(600,600) t.bgcolor("dark green") #turtle settings t.hideturtle() t.speed(0) num=len(b) side=600/num xcod=-300 ycod=-300 for x in b: for y in x: if(y> 0): drawsquare(xcod,ycod,side,'black') if(y< 0): drawsquare(xcod,ycod,side,'white') if(y==0): drawsquare(xcod,ycod,side,'dark green') xcod=xcod+side xcod=-300 ycod=ycod+side
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 main(): """ Call various function for drawing various English character and space between them. :pre: (relative) pos (X,Y), heading (east), up :post: (relative) pos (X+26/5*length+,Y), heading (east), up :return: None """ length = int(input("Enter the font size(for best fit on screen give 50): ")) init() drawC(length) drawSpace(length / 5, 0) drawO(length) drawSpace(length / 5, 0) drawL(length) drawSpace(length / 5, 0) drawD(length) drawSpace(length / 5, 0) drawP(length) drawSpace(length / 5, 0) drawL(length) drawSpace(length / 5, 0) drawA(length) drawSpace(length / 5, 0) drawY(length) drawSpace(length / 5, 0) drawS(length) turtle.hideturtle() # drawO(length) input("press enter to close...")
def main(): turtle.setup(800, 350, 200, 200) turtle.penup() turtle.fd(-300) turtle.pensize(5) drawDate(datetime.datetime.now().strftime('%Y%m%d')) turtle.hideturtle()
def initialize_plot(self, positions): self.positions = positions self.minX = minX = min(x for x,y in positions.values()) maxX = max(x for x,y in positions.values()) minY = min(y for x,y in positions.values()) self.maxY = maxY = max(y for x,y in positions.values()) ts = turtle.getscreen() if ts.window_width > ts.window_height: max_size = ts.window_height() else: max_size = ts.window_width() self.width, self.height = max_size, max_size turtle.setworldcoordinates(minX-5,minY-5,maxX+5,maxY+5) turtle.setup(width=self.width, height=self.height) turtle.speed("fastest") # important! turtle is intolerably slow otherwise turtle.tracer(False) # This too: rendering the 'turtle' wastes time turtle.hideturtle() turtle.penup() self.colors = ["#d9684c","#3d658e","#b5c810","#ffb160","#bd42b3","#0eab6c","#1228da","#60f2b7" ] for color in self.colors: s = turtle.Shape("compound") poly1 = ((0,0),(self.cell_size,0),(self.cell_size,-self.cell_size),(0,-self.cell_size)) s.addcomponent(poly1, color, "#000000") turtle.register_shape(color, s) s = turtle.Shape("compound") poly1 = ((0,0),(self.cell_size,0),(self.cell_size,-self.cell_size),(0,-self.cell_size)) s.addcomponent(poly1, "#000000", "#000000") turtle.register_shape("uncolored", s)
def main(): board_ac=[10,2,3,4,5,6,7,8,9] turtle.screensize(300,300) turtle.hideturtle() go_to(0,0,0) board() #players() win=0 n_jogada=0 player1=input('Player 1:\t') player2=input('Player 2:\t') while win!=1: n_jogada += 1 if check(board_ac) == True: if (-1)**n_jogada == -1: win=1 print(player2, 'Ganhou!') else: win=1 print(player1, 'Ganhou!') else: player_turn(n_jogada, board_ac) turtle.exitonclick()
def setup(): turtle.hideturtle() turtle.tracer(1e3,0) turtle.left(90) turtle.penup() turtle.goto(-100,-100) turtle.pendown()
def plot(self, node1, node2, debug=False): """Plots wires and intersection points with python turtle""" tu.setup(width=800, height=800, startx=0, starty=0) tu.setworldcoordinates(-self.lav, -self.lav, self.sample_dimension+self.lav, self.sample_dimension+self.lav) tu.speed(0) tu.hideturtle() for i in self.index: if debug: time.sleep(2) # Debug only tu.penup() tu.goto(self.startcoords[i][0], self.startcoords[i][1]) tu.pendown() tu.goto(self.endcoords[i][0], self.endcoords[i][1]) tu.penup() if self.list_of_nodes is None: intersect = self.intersections(noprint=True) else: intersect = self.list_of_nodes tu.goto(intersect[node1][0], intersect[node1][1]) tu.dot(10, "blue") tu.goto(intersect[node2][0], intersect[node2][1]) tu.dot(10, "blue") for i in intersect: tu.goto(i[0], i[1]) tu.dot(4, "red") tu.done() return "Plot complete"
def show_turtle(turtle, x): """Do you want to see the turtle?""" if show_turtle == 'yes': turtle.showturtle() else: turtle.hideturtle()
def drawSootSprite(N, R): # reset direction turtle.reset() # draw star drawStar(N, R) # draw body turtle.dot(0.8*2*R) # draw right eyeball turtle.fd(0.2*R) turtle.dot(0.3*R, 'white') # draw right pupil turtle.pu() turtle.bk(0.1*R) turtle.pd() turtle.dot(0.05*R) turtle.pu() # centre turtle.setpos(0, 0) # draw left eyeball turtle.bk(0.2*R) turtle.pd() turtle.dot(0.3*R, 'white') # draw left pupil turtle.pu() turtle.fd(0.1*R) turtle.pd() turtle.dot(0.05*R) turtle.hideturtle()
def turtleProgram(): import turtle import random global length turtle.title("CPSC 1301 Assignment 4 MBowen") #Makes the title of the graphic box turtle.speed(0) #Makes the turtle go rather fast for x in range(1,(numHex+1)): #For loop for creating the hexagons, and filling them up turtle.color(random.random(),random.random(),random.random()) #Defines a random color turtle.begin_fill() turtle.forward(length) turtle.left(60) turtle.forward(length) turtle.left(60) turtle.forward(length) turtle.left(60) turtle.forward(length) turtle.left(60) turtle.forward(length) turtle.left(60) turtle.forward(length) turtle.left(60) turtle.end_fill() turtle.left(2160/(numHex)) length = length - (length/numHex) #Shrinks the hexagons by a small ratio in order to create a more impressive shape turtle.penup() turtle.goto(5*length1/2, 0) #Sends turtle to a blank spot turtle.color("Black") turtle.hideturtle() turtle.write("You have drawn %d hexagons in this pattern." %numHex) #Captions the turtle graphic turtle.mainloop()
def tree(theta_one, theta_two, branchLen, divide_one, divide_two, tt, pen, color_one, color_two): # set attribute tt.pensize(pen) # base case if branchLen < divide_two: return # pick colors for drawing select_color(tt, branchLen, divide_one, divide_two, color_one, color_two) # recursion starts from here tt.forward(branchLen) tt.right(theta_one) tree(theta_one, theta_two, branchLen*0.75, divide_one, divide_two, tt, pen * 0.8, color_one, color_two) tt.left(theta_one + theta_two) tree(theta_one, theta_two, branchLen*0.65, divide_one, divide_two, tt, pen * 0.8, color_one, color_two) tt.right(theta_two) # call second time to prevent over-coloring select_color(tt, branchLen, divide_one, divide_two, color_one, color_two) # return to instance tt.backward(branchLen) turtle.hideturtle()
def printwin(turtle): turtle.stamp() turtle.hideturtle() turtle.penup() turtle.goto(0,0) turtle.color("green") turtle.write("You Win!",font=("Arial",30), align = "center")
def triangle(): #Creates first triangle turtle.hideturtle() turtle.forward(200) turtle.left(120) turtle.forward(200) turtle.left(120) turtle.forward(200)
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() turtle.hideturtle()
def draw(op, name): # background, speed and hide pen while draw turtle.bgcolor('black') turtle.speed('fastest') turtle.hideturtle() if op == 1: for x in range(180): turtle.pencolor(colorss[x % 2]) turtle.width(x / 100 + 1) turtle.forward(x) turtle.right(80) elif op == 2: for x in range(100): turtle.pencolor(colorss[x % 2]) turtle.width(x / 100 + 1) turtle.forward(x) turtle.left(170) elif op == 3: for angle in range(0, 360, 2): turtle.penup() turtle.home() turtle.pendown() turtle.setheading(angle) while turtle.distance(0, 0) < MAX_DISTANCE: turtle.pencolor(colorss[angle % 2]) angle = randrange(-MAX_ANGLE, MAX_ANGLE + 1) turtle.right(angle) turtle.forward(50) elif op == 4: for x in range(100): turtle.width(x / 100 + 1) for y in range(20): turtle.pencolor(colorss[x % 2]) turtle.forward(0.5 + 10 + y) turtle.left(77 / 9) turtle.left(77) elif op == 5: for x in range(180): turtle.width(x / 100 + 1) for y in range(6): turtle.pencolor(colorss[x % 2]) turtle.forward(x / 6) turtle.left(40) turtle.left(100) # turtle.dot(6) elif op == 6: for x in range(200): turtle.pencolor(colorss[x % 2]) turtle.forward(x * 2) turtle.right(121) elif op == 7: size = 1 for x in range(50): for y in range(4): turtle.pencolor(colorss[x % 2]) turtle.forward(size + y - 1) turtle.right(90) size += 1 turtle.right(10) elif op == 8: for x in range(360): turtle.pencolor(colorss[x % 2]) turtle.forward(x) turtle.right(91) # convert draw in image img_canvas = turtle.getscreen().getcanvas() save_as_png(img_canvas, name) # wait user close the draw turtle.done()
def main(): turtle.setup(width=600, height=500) turtle.reset() turtle.hideturtle() turtle.speed(0) turtle.bgcolor('black') c = 0 x = 0 colors = [ #reddish colors (1.00, 0.00, 0.00), (1.00, 0.03, 0.00), (1.00, 0.05, 0.00), (1.00, 0.07, 0.00), (1.00, 0.10, 0.00), (1.00, 0.12, 0.00), (1.00, 0.15, 0.00), (1.00, 0.17, 0.00), (1.00, 0.20, 0.00), (1.00, 0.23, 0.00), (1.00, 0.25, 0.00), (1.00, 0.28, 0.00), (1.00, 0.30, 0.00), (1.00, 0.33, 0.00), (1.00, 0.35, 0.00), (1.00, 0.38, 0.00), (1.00, 0.40, 0.00), (1.00, 0.42, 0.00), (1.00, 0.45, 0.00), (1.00, 0.47, 0.00), #orangey colors (1.00, 0.50, 0.00), (1.00, 0.53, 0.00), (1.00, 0.55, 0.00), (1.00, 0.57, 0.00), (1.00, 0.60, 0.00), (1.00, 0.62, 0.00), (1.00, 0.65, 0.00), (1.00, 0.68, 0.00), (1.00, 0.70, 0.00), (1.00, 0.72, 0.00), (1.00, 0.75, 0.00), (1.00, 0.78, 0.00), (1.00, 0.80, 0.00), (1.00, 0.82, 0.00), (1.00, 0.85, 0.00), (1.00, 0.88, 0.00), (1.00, 0.90, 0.00), (1.00, 0.93, 0.00), (1.00, 0.95, 0.00), (1.00, 0.97, 0.00), #yellowy colors (1.00, 1.00, 0.00), (0.95, 1.00, 0.00), (0.90, 1.00, 0.00), (0.85, 1.00, 0.00), (0.80, 1.00, 0.00), (0.75, 1.00, 0.00), (0.70, 1.00, 0.00), (0.65, 1.00, 0.00), (0.60, 1.00, 0.00), (0.55, 1.00, 0.00), (0.50, 1.00, 0.00), (0.45, 1.00, 0.00), (0.40, 1.00, 0.00), (0.35, 1.00, 0.00), (0.30, 1.00, 0.00), (0.25, 1.00, 0.00), (0.20, 1.00, 0.00), (0.15, 1.00, 0.00), (0.10, 1.00, 0.00), (0.05, 1.00, 0.00), #greenish colors (0.00, 1.00, 0.00), (0.00, 0.95, 0.05), (0.00, 0.90, 0.10), (0.00, 0.85, 0.15), (0.00, 0.80, 0.20), (0.00, 0.75, 0.25), (0.00, 0.70, 0.30), (0.00, 0.65, 0.35), (0.00, 0.60, 0.40), (0.00, 0.55, 0.45), (0.00, 0.50, 0.50), (0.00, 0.45, 0.55), (0.00, 0.40, 0.60), (0.00, 0.35, 0.65), (0.00, 0.30, 0.70), (0.00, 0.25, 0.75), (0.00, 0.20, 0.80), (0.00, 0.15, 0.85), (0.00, 0.10, 0.90), (0.00, 0.05, 0.95), #blueish colors (0.00, 0.00, 1.00), (0.05, 0.00, 1.00), (0.10, 0.00, 1.00), (0.15, 0.00, 1.00), (0.20, 0.00, 1.00), (0.25, 0.00, 1.00), (0.30, 0.00, 1.00), (0.35, 0.00, 1.00), (0.40, 0.00, 1.00), (0.45, 0.00, 1.00), (0.50, 0.00, 1.00), (0.55, 0.00, 1.00), (0.60, 0.00, 1.00), (0.65, 0.00, 1.00), (0.70, 0.00, 1.00), (0.75, 0.00, 1.00), (0.80, 0.00, 1.00), (0.85, 0.00, 1.00), (0.90, 0.00, 1.00), (0.95, 0.00, 1.00) ] while x < 1000: idx = int(c) color = colors[idx] turtle.color(color) turtle.forward(x) turtle.right(98) x = x + 1 c = c + 0.1 turtle.exitonclick()
def anaProgram(): yardým_penceresini_göster() ekran = turtle.Screen() turtle.mode ('standard') xebat, yebat = ekran.screensize() turtle.setworldcoordinates (0, 0, xebat, yebat) turtle.hideturtle() # Kalem okunu gizler... turtle.speed ('fastest') turtle.tracer (0, 0) turtle.penup() # Bölümlerde çift "//" kullaným, sonucu tamsayý yapar; yoksa float hatasý oluþur... pano = HayatPanosu (xebat // HÜCRE_EBATI, yebat // HÜCRE_EBATI) # Kurucuyu çaðýrýr... # Fare'yle hücre týklamasýný geçerlileyelim... def geçerlile (x, y): # HayatPanosu sýnýfý geçerlile(..) metodunu esgeçer... hücre_x = x // HÜCRE_EBATI hücre_y = y // HÜCRE_EBATI if pano.geçerli_mi (hücre_x, hücre_y): pano.geçerlile (hücre_x, hücre_y) # HayatPanosu geçerlile(..) fonksiyonunu çaðýrýr... pano.göster() turtle.onscreenclick (turtle.listen) # Pano týklamasý dinleyiciye duyarlý... turtle.onscreenclick (geçerlile) # Týklama önce dahili geçerlile(..) fonksiyonunu çaðýrýr... pano.panoyuGeliþigüzelDoldur() pano.göster() # Menü harf tuþlarýný kuralým... def panoyuTamamenSil(): pano.panoyuTamamenSil() # Aslýnda öncelikle durum set içeriklerini silip sonra boþ ekraný gösteriyor... pano.göster() turtle.onkey (panoyuTamamenSil, 's') def panoyuGeliþigüzelDoldur(): pano.panoyuGeliþigüzelDoldur() pano.göster() turtle.onkey (panoyuGeliþigüzelDoldur, 'g') turtle.onkey (sys.exit, 'k') # "ç" ile basmadan çýkýyor... # Menü harfleriyle tek adým veya daimi adýmla ilerlemeyi kuralým... devamlý = False def tek_adým(): nonlocal devamlý devamlý = False adýmý_iþlet() def daimi_adým(): nonlocal devamlý devamlý = True adýmý_iþlet() def adýmý_iþlet(): pano.adýmla() pano.göster() # "devamlý"da 25 milisaniyede birsonraki adýma geçer... if devamlý: turtle.ontimer (adýmý_iþlet, 25) turtle.onkey (tek_adým, 't') turtle.onkey (daimi_adým, 'd') # Tk sýnýfý mainloop() metodunu çaðýralým... turtle.listen() turtle.mainloop()
def main(): drawChessboard(-260, -20, -120, 120) # Draw first chess board drawChessboard(20, 260, -120, 120) # Draw second chess board turtle.hideturtle() turtle.done()
def game_over(): caterpillar.color('blue') leaf.color('blue') t.penup() t.hideturtle() t.write('GAME OVER!', align='center', font=('Aerial', 30, 'normal'))
def txt(): t1 = (x, y) t2 = (x + 12, y - 12) penSize = 5 t.screensize(400, 400, "#fff") t.pensize(penSize) t.pencolor("#ff0000") t.speed(10) t.hideturtle() # 点、 t.up() t.goto(t1) t.down() # 移动,画线 t.goto(t2) # 横 - x1 = x - 18 y1 = y - 22 t3 = (x1, y1) t4 = (x1 + 60, y1) t.up() t.goto(t3) t.down() t.goto(t4) # 点、、 x2 = x1 + 16 y2 = y1 - 10 t5 = (x2, y2) t6 = (x2 + 8, y2 - 16) t7 = (x2 + 26, y2) t8 = (x2 + 18, y2 - 18) t.up() t.goto(t5) t.down() t.goto(t6) t.up() t.goto(t7) t.down() t.goto(t8) # 长横- x3 = x1 - 15 y3 = y2 - 24 t9 = (x3, y3) t10 = (x3 + 90, y3) t.up() t.goto(t9) t.down() t.goto(t10) # 横 - x4 = x3 + 10 y4 = y3 - 22 t11 = (x4, y4) t12 = (x4 + 70, y4) t.up() t.goto(t11) t.down() t.goto(t12) # 竖 | x5 = x + 12 y5 = y3 t13 = (x5, y5) t14 = (x5, y5 - 90) t.up() t.goto(t13) t.down() t.goto(t14) # 勾 x6 = x5 y6 = y5 - 90 t15 = (x6 - 12, y6 + 10) t.goto(t15) # 点、、 x7 = x6 - 12 y7 = y5 - 40 t16 = (x7, y7) t17 = (x7 - 8, y7 - 20) t.up() t.goto(t16) t.down() t.goto(t17) t18 = (x7 + 24, y7 - 5) t19 = (x7 + 30, y7 - 16) t.up() t.goto(t18) t.down() t.goto(t19) # 撇 x8 = x + 100 y8 = y - 10 t20 = (x8, y8) t21 = (x8 - 32, y8 - 20) t.up() t.goto(t20) t.down() t.goto(t21) # 撇 t22 = (x8 - 40, y8 - 135) t.goto(t22) # 横 x9 = x3 + 100 y9 = y3 - 8 t23 = (x9, y9) t24 = (x9 + 50, y9) t.up() t.goto(t23) t.down() t.goto(t24) # 竖 x10 = x9 + 24 y10 = y9 t25 = (x10, y10) t26 = (x10, y10 - 80) t.up() t.goto(t25) t.down() t.goto(t26) nian() kuai() le() t.done()
turtle.color("black") for j in range(-120, 90, 60): for i in range(-120, 120, 60): turtle.penup() turtle.goto(i, j) turtle.pendown() # Draw a small rectangle turtle.begin_fill() for k in range(4): turtle.forward(30) # Draw a line turtle.left(90) # Turn left 90 degrees turtle.end_fill() for j in range(-90, 120, 60): for i in range(-90, 120, 60): turtle.penup() turtle.goto(i, j) turtle.pendown() # Draw a small rectangle turtle.begin_fill() for k in range(4): turtle.forward(30) # Draw a line turtle.left(90) # Turn left 90 degrees turtle.end_fill() turtle.hideturtle() turtle.done()
end_fill() right(90) pencolor("brown") forward(105) right(90) penup() forward(20) right(90) pendown() forward(280) left(180) forward(20) left(90) pencolor("green") color("green") begin_fill() circle(20) end_fill() right(90) pencolor("brown") forward(260) right(90) pencolor("black") forward(200) right(180) forward(500) hideturtle() exitonclick()
import turtle # importing our graphical library import math #importing our mathematical function library turtle.speed(10) # Set speed of drawing turtle.hideturtle() # Disable default turtle object s = turtle.Screen() # Create a graphic window s.bgcolor("black") # Set background color turtle.pencolor("red") # Set drawing pen color s.title("Tree Fractal By Smaranjit Ghose") # Set Title turtle.left(90) def tree_fractal(d, angle): ''' The function to draw the Tree Fractal ''' if d > 5: turtle.forward(d) turtle.right(angle) tree_fractal(d / math.sqrt(2), angle) turtle.left(2 * angle) tree_fractal(d / math.sqrt(2), angle) turtle.right(angle) turtle.backward(d) tree_fractal(100, 20)
def draw(self): turtle.setup(666, 400) turtle.bgcolor("black") # turtle.bgpic("logo.JPG") turtle.hideturtle() turtle.speed(10) turtle.penup() turtle.goto(-200, 50) turtle.pendown() turtle.pensize(self.pythonSize) turtle.seth(-40) for i in range(self.len): turtle.color(self.colors[i]) turtle.circle(self.rad, self.angle) turtle.circle(-self.rad, self.angle) turtle.color("purple") turtle.circle(self.rad, self.angle / 2) turtle.fd(self.rad) turtle.circle(self.neckRad + 1, 180) turtle.fd(self.rad * 2 / 3) # turtle.write(s, font=(“font-name”, font_size, ”font_type”)) turtle.penup() turtle.goto(-60, -60) turtle.color("pink") turtle.pendown() turtle.write("让我们吃着小龙虾", align="left", font=("Courier", 20, "bold")) time.sleep(1) turtle.penup() turtle.goto(-60, -80) turtle.pendown() turtle.write("看着屏幕", align="left", font=("Courier", 20, "bold")) time.sleep(1) turtle.penup() turtle.goto(-60, -100) turtle.pendown() turtle.write("享受这大千世界与开源不求回报的礼物", align="left", font=("Courier", 20, "bold")) time.sleep(1) turtle.penup() turtle.goto(-60, -120) turtle.pendown() turtle.write("Forever don't forget the day,", align="left", font=("Courier", 20, "bold")) time.sleep(1.5) turtle.penup() turtle.goto(-60, -140) turtle.pendown() turtle.write("that someone told you excitedly!", align="left", font=("Courier", 20, "bold")) time.sleep(1.5) turtle.penup() turtle.goto(-60, -160) turtle.pendown() turtle.write("we needn't rewhell!", align="left", font=("Courier", 20, "bold")) time.sleep(2)
import turtle as t from random import randint, random def draw_star(points, size, col, x, y): t.penup() t.goto(x, y) t.pendown() angle = 180 - (180 / points) t.color(col) t.begin_fill() for i in range(points): t.forward(size) t.right(angle) t.end_fill() def aa(x,y): draw_star(5, 150, 'yellow', 0, 0) #Основной код t.hideturtle() t.Screen().bgcolor('dark blue') draw_star(5, 50, 'yellow', 0, 0) while True: ranPts = randint(2, 5) * 2 + 1 ranSize = randint(10, 50) ranCol = (random(), random(), random()) ranX = randint(-350, 300) ranY = randint(-250, 250) draw_star(ranPts, ranSize, ranCol, ranX, ranY)
from ufo import * import turtle as tr import random tr.tracer(0) tr.hideturtle() tr.bgcolor('blue') colors = ['green', 'blue', 'pink', 'orange', 'red', 'black', 'brown', 'yellow'] lst_ufo = [] tr.showturtle() response = tr.numinput('Ответ', 'Введите желаемое кол-во тарелок:') if response == None: pass else: for i in range(int(response)): lst_ufo.append( Ufo('Пришелец-' + str(i), random.randint(-600, 600), random.randint(-600, 600), random.randint(30, 300), colors[random.randint(0, 7)], random.randint(3, 10), random.randint(2, 8))) while True: for i in range(len(lst_ufo)): lst_ufo[i].show() lst_ufo[i].move() tr.update() tr.clear() tr.listen()
def drawSVG(filename, w_color): global first SVGFile = open(filename, 'r') SVG = BeautifulSoup(SVGFile.read(), 'lxml') Height = float(SVG.svg.attrs['height'][0:-2]) Width = float(SVG.svg.attrs['width'][0:-2]) transform(SVG.g.attrs['transform']) if first: te.setup(height=Height, width=Width) te.setworldcoordinates(-Width / 2, 300, Width - Width / 2, -Height + 300) first = False te.tracer(100) te.pensize(1) te.speed(Speed) te.penup() te.color(w_color) for i in SVG.find_all('path'): attr = i.attrs['d'].replace('\n', ' ') f = readPathAttrD(attr) lastI = '' for i in f: if i == 'M': te.end_fill() Moveto(f.__next__() * scale[0], f.__next__() * scale[1]) te.begin_fill() elif i == 'm': te.end_fill() Moveto_r(f.__next__() * scale[0], f.__next__() * scale[1]) te.begin_fill() elif i == 'C': Curveto(f.__next__() * scale[0], f.__next__() * scale[1], f.__next__() * scale[0], f.__next__() * scale[1], f.__next__() * scale[0], f.__next__() * scale[1]) lastI = i elif i == 'c': Curveto_r(f.__next__() * scale[0], f.__next__() * scale[1], f.__next__() * scale[0], f.__next__() * scale[1], f.__next__() * scale[0], f.__next__() * scale[1]) lastI = i elif i == 'L': Lineto(f.__next__() * scale[0], f.__next__() * scale[1]) elif i == 'l': Lineto_r(f.__next__() * scale[0], f.__next__() * scale[1]) lastI = i elif lastI == 'C': Curveto(i * scale[0], f.__next__() * scale[1], f.__next__() * scale[0], f.__next__() * scale[1], f.__next__() * scale[0], f.__next__() * scale[1]) elif lastI == 'c': Curveto_r(i * scale[0], f.__next__() * scale[1], f.__next__() * scale[0], f.__next__() * scale[1], f.__next__() * scale[0], f.__next__() * scale[1]) elif lastI == 'L': Lineto(i * scale[0], f.__next__() * scale[1]) elif lastI == 'l': Lineto_r(i * scale[0], f.__next__() * scale[1]) te.penup() te.hideturtle() te.update() SVGFile.close()
def tscheme_hideturtle(): """Make turtle visible.""" _tscheme_prep() turtle.hideturtle()
def main(): display_help_window() scr = turtle.Screen() turtle.colormode('standard') xsize, ysize = scr.screensize() turtle.setworldcoordinates(0, 0, xsize, ysize) turtle.hideturtle() turtle.speed('fastest') turtle.tracer(0, 0) turtle.penup() board = LifeBoard(xsize // CELL_SIZE, 1 + ysize // CELL_SIZE) def toggle(x, y): cellx = x // CELL_SIZE celly = y // CELL_SIZE if board.is_legal(cellx, celly): board.toggle(cellx, celly) board.display() turtle.onscreenclick(turtle.listen) turtle.onscreenclick(toggle) board.makeRandom() board.display() def erase(): board.erase() board.display() turtle.onkey(erase, 'e') def makeRandom(): board.makeRandom() board.display() turtle.onkey(makeRandom, 'r') turtle.onkey(sys.exit, 'q') continuous = False def step_once(): nonlocal continuous #continuous variable but a new one not the same scope continuous = False perform_step() def step_continuous(): nonlocal continuous continuous = True perform_step() def perform_step(): board.step() board.display() if continuous: turtle.ontimer(perform_step, 1) turtle.onkey(step_once, 's') turtle.onkey(step_continuous, 'c') def up_size(): global CELL_SIZE CELL_SIZE += 1 makeRandom() def down_size(): global CELL_SIZE CELL_SIZE -= 1 makeRandom() turtle.onkey(up_size, '+') turtle.onkey(down_size, '-') turtle.listen() turtle.mainloop()
def main(): turtle.tracer(0, 0) turtle.hideturtle() turtle.onscreenclick(clickhandler) draw_board(the_board) turtle.mainloop()
def main(): turtle.hideturtle() line(TOP_X, TOP_Y, BASE_LEFT_X, BASE_LEFT_Y, 'red') line(TOP_X, TOP_Y, BASE_RIGHT_X, BASE_RIGHT_Y, 'blue') line(BASE_LEFT_X, BASE_LEFT_Y, BASE_RIGHT_X, BASE_RIGHT_Y, 'green')
CubicBezier(189.06+123.21j, 194.73+123.2j, 199.46+122.31j, 202.17+121.33j) CubicBezier(202.17+121.33j, 205.88+119.99j, 207.1+118.82j, 207.83+117.83j) CubicBezier(207.83+117.83j, 209.97+114.95j, 210.09+112.31j, 210.33+109.67j) Arc(214.333+118j, 24.017+24.017j, 0.0, False, True, 220.833+123.5j) CubicBezier(220.83+123.5j, 224.18+127.56j, 225.37+131.75j, 225.83+134j) CubicBezier(229.74+108.64j, 231.31+111.13j, 232.56+113.58j, 234.04+116.88j) CubicBezier(234.04+116.88j, 236.73+122.84j, 237.71+124.25j, 237.71+128.56j) Arc(228.833+80j, 177.697+177.697j, 0.0, False, True, 229.833+106.833j) CubicBezier(229.83+106.83j, 229.47+116.41j, 227.19+126.65j, 225.83+134j) CubicBezier(210.54+95.84j, 212.02+97.63j, 211.91+97.35j, 213.33+100.5j) CubicBezier(213.33+100.5j, 216.81+108.21j, 215.05+115.52j, 214.33+118j) CubicBezier(75.45+164.64j, 72.5+166.33j, 72.43+166.24j, 71.64+169.25j) CubicBezier(71.64+169.25j, 70.31+174.33j, 73.78+183.75j, 75.67+186.62j) CubicBezier(75.67+186.62j, 79.2+191.96j, 81.88+195.12j, 86.72+198.81j) CubicBezier(260.67+159.33j, 263.5+158.56j, 264.41+159.28j, 266.16+161.25j) CubicBezier(266.16+161.25j, 269.06+164.53j, 269.72+178.72j, 266.83+186j) CubicBezier(266.83+186j, 262.68+196.49j, 256.99+199.81j, 253.5+201.49j) CubicBezier(117.72+125.25j, 115.69+112.81j, 117+91.69j, 121.33+82.75j) CubicBezier(121.33+82.75j, 124.64+75.93j, 125.91+74.12j, 129.35+70.73j) # 脖子 Arc(143.667+258.333j, 481.666+481.666j, 0.0, False, False, 155+293j) CubicBezier(155+293j, 160.07+306.73j, 165.92+321.02j, 171.31+332.5j) CubicBezier(207.38+266j, 201.7+273.24j, 193.78+284.27j, 188+294.5j) CubicBezier(188+294.5j, 180.5+307.77j, 174.86+321.91j, 171.31+332.5j) Line(145.07+263.14j, 152.62+256.5j) Line(152.62+256.5j, 152.62+242.67j) Line(204.07+270.18j, 192.38+256.62j) Line(192.38+256.62j, 192.38+240.44j) tur.hideturtle() # 隐藏乌龟图标 tur.update()
def dibujarcalculadora(): """ Descrripcion: Prcedimiento que dibuja la calculadora Entradas: Ninguna Sañida: Dibujo en el mundo de la tortuga la calculadora """ turtle.reset() turtle.hideturtle() turtle.speed(0) #Dibujar Parte exterior turtle.penup() turtle.color("dark blue") turtle.pencolor("white") turtle.begin_fill() turtle.goto(0,-200) turtle.pendown() turtle.pensize(3) turtle.forward(150) turtle.left(90) turtle.forward(400) turtle.left(90) turtle.forward(300) turtle.left(90) turtle.forward(400) turtle.left(90) turtle.forward(150) turtle.end_fill() #Dibuja el Display turtle.penup() turtle.goto(0,120) turtle.color("mediumaquamarine") turtle.pencolor("white") turtle.begin_fill() turtle.pendown() turtle.pensize(2) turtle.forward(120) turtle.left(90) turtle.forward(50) turtle.left(90) turtle.forward(235) turtle.left(90) turtle.forward(50) turtle.left(90) turtle.forward(120) turtle.left(90) turtle.end_fill() #Dibujar Botones turtle.color("white") dibujarBoton("√",-115,100) dibujarBoton("CE",-55,100) dibujarBoton("%",70,100) dibujarBoton("/",7,100) dibujarBoton(7,-115,45) dibujarBoton(8,-55,45) dibujarBoton("X",70,45) dibujarBoton(9,7,45) dibujarBoton(4,-115,-10) dibujarBoton(5,-55,-10) dibujarBoton("-",70,-10) dibujarBoton(6,7,-10) dibujarBoton(1,-115,-65) dibujarBoton(2,-55,-65) dibujarBoton("+",70,-65) dibujarBoton(3,7,-65) dibujarBoton(0,-115,-120) dibujarBoton(".",-55,-120) dibujarBoton("=",70,-120) turtle.end_fill() turtle.penup() turtle.goto(-100,120) turtle.setheading(0)
# SpaceWare by @TokyoEdTech # Part III : Getting started # Game Object / Broder / Boundary Checking import os import random import turtle turtle.speed(0) # Set the animations sepeed to the maximum turtle.bgcolor('black') # Change the background color turtle.hideturtle() # hide the default turtle turtle.setundobuffer(1) # This saves memory turtle.tracer(1) # This speeds up drawing turtle.register_shape('fishtank.gif') class Sprite(turtle.Turtle): def __init__(self, spriteshape, color, startx, starty): turtle.Turtle.__init__(self, shape=spriteshape) #self.shape(spriteshape) self.speed(0) self.penup() self.color(color) self.goto(startx, starty) self.speed = 1 def move(self): self.fd(self.speed) # Boundary detection
turtle.penup() # stop showing pen # tall vertical line for stem of 'P' turtle.goto(-50, 250) # move pen to left, middle arc of circle turtle.pendown() # ready to draw turtle.right(90) # point pen downwards turtle.forward(200) # draw stem of 'P' turtle.penup() # stop showing pen # Top horizontal line of 'T' turtle.goto(60, 300) # move pen to near top of 'P', but spaced to the right turtle.setheading(0) # face rightward turtle.pendown() # ready to draw turtle.forward(200) # draw horizontal line, top of 'T' to the right turtle.penup() # stop showing pen # Middle Vertical line of 'T' turtle.goto(160, 300) # Move pen to middle of top of 'T' turtle.setheading(270) # point down turtle.pendown() # ready to draw turtle.forward(250) # draw vertical line, middle of 'T', going down turtle.penup() # stop showing pen turtle.write(' PT is for Paul Thayer, Good-bye!') turtle.hideturtle() # hide turtle to see initials clearly print("End of turtle lab to draw my initials.") # Paste your output for parts 1, 2, and 3 below:
y = step * n for i in range(8): x = step * i turtle.penup() turtle.goto(x, y) turtle.pendown() turtle.begin_fill() turtle.color("black" if (i + n) % 2 == 0 else "white") turtle.setheading(0) turtle.forward(step) turtle.left(90) turtle.forward(step) turtle.left(90) turtle.forward(step) turtle.left(90) turtle.forward(step) turtle.end_fill() # Draw the outer frame turtle.penup() turtle.goto(0, 0) turtle.color("black") turtle.pendown() turtle.goto(SIDE, 0) turtle.goto(SIDE, SIDE) turtle.goto(0, SIDE) turtle.goto(0, 0) turtle.hideturtle() # Hide the turtle turtle.done() # Don't close the turtle graphics window