def lab11(): t1Init() drawLine() addKeys() addMouse() wn.listen() turtle.mainloop()
def main(): #-- creating class object and calling methods game = Game() game.print_items() game.draw_colors() game.draw_cover() turtle.mainloop() #-- creates the main loop for turtle screen
def start(): draw_board() #Player vs Bot(first) if opponent[0] == "B" and first[0] == "B": bot() turtle.onscreenclick(play) turtle.mainloop()
def lab11_2(): t1.penup() t1.setpos(coord[0]) t1.pendown() t1.setpos(coord[0][0],coord[1][1]) t1.setpos(coord[1]) t1.setpos(coord[1][0],coord[0][1]) t1.setpos(coord[0]) t1.penup() t1.setpos(point) t1.pendown() t1.circle(cr) t1.penup() t1.setpos(0,0) t1.pendown() t2.penup() t2.setpos(p1) t2.pendown() t2.setpos(p2) maze() addMouse() addkeys() addexit() wn.listen() turtle.mainloop()
def polygon_arc(t, length, n, angle): #t=turtle.Turtle() n1 = round((angle/360)*n) for i in range(n1): t.fd(length) t.lt(360/n) turtle.mainloop()
def mycircle(t,radius,sides): t.fd(radius) for i in range(sides): t.fd(radius*3/2) t.lt(360/sides) print(alice) turtle.mainloop()
def drawtree(root): def height(root): return 1 + max(height(root.left), height(root.right)) if root else -1 def jumpto(x, y): t.penup() t.goto(x, y) t.pendown() def draw(node, x, y, dx): if node: t.goto(x, y) jumpto(x, y - 20) t.write(node.val, align='center', font=('Arial', 12, 'normal')) draw(node.left, x - dx, y - 60, dx / 2) jumpto(x, y - 20) draw(node.right, x + dx, y - 60, dx / 2) import turtle t = turtle.Turtle() t.speed(0) turtle.delay(0) h = height(root) jumpto(0, 30 * h) draw(root, 0, 30 * h, 40 * h) t.hideturtle() turtle.mainloop()
def gamePlay(): import turtle global wn global t1 global coord global radius global cpos global line line=[(-450,-300),(-300,-300)] coord=[(350,-300),(450,-200)] radius=100 cpos=(0,-300) wn=turtle.Screen() wn.bgpic("myMaze.gif") t1=turtle.Turtle() setGame() t1.speed(7) t1.penup() t1.goto(-400,300) t1.pendown() t1.pencolor("Red") t1.write("Click or Input Keys") addKeys() addMouse() wn.listen() turtle.mainloop()
def main(): m = get_user_input() draw_grid(m) print "Click a square to toggle fill. \nTo switch the fill color press the spacebar." WN.onkey(new_fill, "space") WN.listen() turtle.mainloop()
def Moving(L1): for x in range(len(L1)): # Executes the turtle commands if "goto" in L1[x]: # If goto: L1[x] = L1[x].split("(") # Splits the line by "(" del L1[x][0] # Deletes the other end ")" L1[x] = L1[x][0][0:-1] # Stores each value of the list as only the coordinates L1[x] = L1[x].split(",") # Splits the coordinates by the comma between for y in range(len(L1[x])): L1[x][y] = int(L1[x][y]) # Converts the strings into integers turtle.pendown() # Pen down turtle.goto(int(L1[x][0]), int(L1[x][1])) # Sends the turtle to the x,y coordinates if "jumpto" in L1[x]: # If jumpto: L1[x] = L1[x].split("(") # Splits the line by "(" del L1[x][0] # Deletes the other end ")" L1[x] = L1[x][0][0:-1] # Stores each value of the list as only the coordinates L1[x] = L1[x].split(",") # Splits the coordinates by the comma between for z in range(len(L1[x])): L1[x][z] = int(L1[x][z]) # Converts the strings into integers turtle.penup() # Pen up turtle.goto(int(L1[x][0]), int(L1[x][1])) # Sends the turtle to the x,y coordinates if "color" in L1[x]: # If color turtle.color(random.random(), random.random(), random.random()) # Defines random color for turtle else: continue # If none of the above criteria is met, do nothing turtle.mainloop() # Keeps turtle on the screen
def play(self): cannon = LaserCannon() turtle.ontimer(self.add_alien,2000) turtle.listen() # Start the event loop. turtle.mainloop()
def main() : wn.listen() lab11_3() lab11_4() lab11_5() lab11_6() turtle.mainloop()
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 run(self, ticks=1000): # run for 1000 ticks self.done = False #self.screen.ontimer(self.print_fps, 1000) self.ticks = ticks self.screen.ontimer(self.tick, 33) mainloop()
def dessine(liste): """ Fonction qui ce charge de dessiner les courbes. """ # Si la liste reçu n'est pas vide. if liste != []: # Création de la fenètre turtle. t = turtle.Turtle() # On cache la tortue. t.hideturtle() # On met la vitesse max. t.speed(0) # On configure la taille de la fenètre. turtle.setup(width=650,height=650) # Création du repère. repère(t) # On compte le nombre de tour à faire. nb_tour = len(liste) # Boucle qui permet d'afficher les courbes. for n in range(nb_tour): e = liste[n] f = e[0] c = e[1] fonction(t,f,c) # Mainloop pour que la fenètre reste. turtle.mainloop()
def main(): # 打开/关闭龟动画,并为更新图纸设置延迟。 turtle.tracer(False) Init() SetupClock(160) turtle.tracer(True) Tick() turtle.mainloop()
def janelaFixar(self): """ Desc: Faz a janela de desenho não fechar Chame-a sempre após terminar os desenhos """ turtle.mainloop()
def mypolygon(t,sides,length): angle = 360 /sides t.fd(length/8) for i in range(sides): t.fd(length) t.lt(angle) print(alice) turtle.mainloop()
def game(): DecideTreasure(treasure2) wn.onkey(keyup,"Up") wn.onkey(keydown,"Down") wn.onkey(keyright,"Right") wn.onkey(keyleft,"Left") wn.listen() turtle.mainloop()
def lab11(): drawLine() drawRectangle() drawCircle() addKeys() addMouse() wn.listen() turtle.mainloop()
def gamePlay_Shape(): t1_set() Circle() Rectangle() Line() addKeys() wn.listen() turtle.mainloop()
def Game(): t1.home() t1.clear() draw(coord) addkeys() addMouse() wn.listen() turtle.mainloop()
def lab11(): Line() Rectangle() Circle() addkeys() addmouse() turtle.listen() turtle.mainloop()
def main(): print('testing...') #drawCircleTurtle(100, 100, 50) drawSpiralTurtle(0, 0, 5) turtle.mainloop()
def lab11(): t1.penup() t1.goto(100,100) Ractangle() t1.home() addkeys() addMouse() wn.listen() turtle.mainloop()
def polygon(t, length, n): try: for i in range(n): t.fd(length) t.lt(360 / n) print(t) turtle.mainloop() except Exception: print("Error!")
def test_drawman(): to_point() pen_down() for i in range(5): on_vector(0, 20) on_vector(-20, -20) pen_up() to_point() t.mainloop()
def square(t, length): try: for i in range(4): t.fd(length) t.lt(90) print(t) turtle.mainloop() except Exception: print("Error!")
def main(): # use sys.argv if needed print('generating spirograph...') # create parser descStr = """This program draws spirographs using the Turtle module. When run with no arguments, this program draws random spirographs. Terminology: R: radius of outer circle. r: radius of inner circle. l: ratio of hole distance to r. """ parser = argparse.ArgumentParser(description=descStr) # add expected arguments parser.add_argument('--sparams', nargs=3, dest='sparams', required=False, help="The three arguments in sparams: R, r, l.") # parse args args = parser.parse_args() # set to 80% screen width turtle.setup(width=0.8) # set cursor shape turtle.shape('turtle') # set title turtle.title("Spirographs!") # add key handler for saving images turtle.onkey(saveDrawing, "s") # start listening turtle.listen() # hide main turtle cursor turtle.hideturtle() # checks args and draw if args.sparams: params = [float(x) for x in args.sparams] # draw spirograph with given parameters # black by default col = (0.0, 0.0, 0.0) spiro = Spiro(0, 0, col, *params) spiro.draw() else: # create animator object spiroAnim = SpiroAnimator(4) # add key handler to toggle turtle cursor turtle.onkey(spiroAnim.toggleTurtles, "t") # add key handler to restart animation turtle.onkey(spiroAnim.restart, "space") # start turtle main loop turtle.mainloop()
def lab11(): ring() addkeys() addmouse() turtle.listen() turtle.mainloop() schoolLife() speech()
tur.fillcolor("skyblue") tur.left(10) tur.circle(600, 13) tur.circle(70, 150) tur.left(7) tur.circle(400, 27) tur.end_fill() tur.up() tur.goto(x=-150, y=-80) tur.setheading(180) tur.down() tur.begin_fill() tur.fillcolor('white') tur.circle(-600, 7) tur.right(78) tur.circle(-1000, 10) tur.right(10) tur.circle(-45, 108) tur.end_fill() tur.right(55) tur.fd(185) tur.up() tur.right(180) tur.fd(120) tur.width(0) tur.down() tur.left(45) tr.mainloop()
def main(): init() s(4, 500) turtle.mainloop()
#movement functions def Up(): Joah.setheading(90) Joah.forward(10) def Down(): Joah.setheading(270) Joah.forward(10) def Left(): Joah.setheading(180) Joah.forward(10) def Right(): Joah.setheading(0) Joah.forward(10) #-----events---------------- wn.onkeypress(Right, "Right") wn.onkeypress(Left, "Left") wn.onkeypress(Up, "Up") wn.onkeypress(Down, "Down") wn.onclick(next_arrow) wn.onclick(back_arrow) wn.listen() trtl.mainloop()
def draw(self): turtle.circle(self.a) #turtle.shapesize(3,5,1) turtle.fillcolor("white") turtle.mainloop()
import turtle as t #터틀이라는 것을 t로써 가져옴 이를통해 turtle이라고 통째로 안써도 됨 n = 60 # 원을 60번 그림 t.shape('turtle') #모양을 거북이로 변환시킴, 화살표등의 여러가지 있음 t.speed('fastest') # 거북이 속도를 가장 빠르게 설정 for i in range(n): t.circle(120) # 반지름이 120인 원을 그림 t.right(360 / n) t.mainloop() #프로그래밍을 실행하고 바로 끝나는걸 방지함 # t.shape('turtle') # t.speed('fastest') # 거북이 속도를 가장 빠르게 설정 # for i in range(600): # 300번 반복 # t.forward(i) # i만큼 앞으로 이동. 반복할 때마다 선이 길어짐 # t.right(90) t.mainloop()
def draw(self): turtle.shape("circle") turtle.shapesize(self.b, self.a,1) turtle.fillcolor("white") turtle.mainloop()
def main(interval): graph(t, interval) turtle.mainloop()
def square(t, length): for i in range(4): t.fd(length) t.lt(90) turtle.mainloop()
def show_pic(): screen = turtle.Screen() screen.bgpic('/home/student/static/dogpics/dog.png') turtle.mainloop()
boxes[8] = player[1] else: num_moves_made -= 1 elif (50 <= x <= 150 and -150 <= y <= -50): # Square 9 if (boxes[9] == 'empty'): player[0](55, -55) boxes[9] = player[1] else: num_moves_made -= 1 for i in range(8): if (boxes[win_ans[i][0]] == player[1] and boxes[win_ans[i][1]] == player[1] and boxes[win_ans[i][2]] == player[1]): winner = True rachel.penup() rachel.goto(-240, 160) rachel.pendown() rachel.write(player[1] + ' is the winner!!!', font=('Arial', 45, 'normal')) if ('empty' not in boxes.values() and winner == False): rachel.penup() rachel.goto(-145, 145) rachel.pendown() rachel.write('Draw!', font=('Arial', 30, 'normal')) turtle.onscreenclick(draw_symbol) turtle.mainloop() # Wait for user to close window
def main(self): turtle.mainloop()
def main(): turtle.tracer(False) update_date() turtle.mainloop()
def main(): t.onscreenclick(getPos) t.mainloop()
def square(t): t = turtle.Turtle() # 创建对象 for i in range(4): t.fd(100) t.lt(90) turtle.mainloop()
""" These lines are Python3 comments File: rectangle.py Programmer: Allen Tools Date: 01/19/2017 Course ID: LIS 4930 Python for Informatics Purpose: A function called square that takes a parameter called t which is turtle, it should draw a square. Version: 1.1 Changes: 1.0 -> 1.1 add a paramater, length argument modify the function to draw a rectangele """ import turtle bob = turtle.Turtle() # make a bob turtle print("bob is: ", bob) # show bob def square(t, length): # define a square function t.fd(100) t.lt(90) t.fd(length) t.lt(90) t.fd(100) t.lt(90) t.fd(length) square(bob, 20) # call the function with paramater bob turtle.mainloop() # keep the window open
start(pen, 190, -90) t = tree( [pen], 100, level, 0.1, [[ (45,0.7), (0,0.72), (-45,0.65) ]] ) return t # Hier 3 Baumgeneratoren: def main(): p = Turtle() p.ht() tracer(75,0) u = doit1(6, Turtle(undobuffersize=1)) s = doit2(7, Turtle(undobuffersize=1)) t = doit3(5, Turtle(undobuffersize=1)) a = clock() while True: done = 0 for b in u,s,t: try: b.__next__() except: done += 1 if done == 3: break tracer(1,10) b = clock() return "runtime: %.2f sec." % (b-a) if __name__ == '__main__': main() mainloop()
def demo(file, width=None): import turtle t = turtle.Turtle() a = TurtleSVG(file) a.render(t, width=width) turtle.mainloop()
import turtle window = turtle.Screen() #Crear el espacio para graficar cuadrado = turtle.Turtle() #aplicar la librer'ia turtle a la variable cuadrado for i in range( 1, 50 ): #iteracion para ir aumentando el tamano de la variable en forma de espiral cuadrada cuadrado.forward(i) cuadrado.right(90) turtle.mainloop() #evitar que se cierre la ventana
def polygon(n): """ dessine un polygone à n côtés""" for _ in range(n): turtle.forward(100) turtle.left(360 / n) turtle.mainloop()
def goD(): turtle.setheading(270) turtle.forward(step) def goL(): turtle.setheading(180) turtle.forward(step) turtle.reset() turtle.shape('turtle') turtle.bgcolor('#009944') turtle.turtlesize(2) turtle.pencolor('yellow') sp = int(turtle.numinput('Вопрос', 'Введите скорость: ', default=2)) step = 50 turtle.speed(sp) turtle.pendown() # Опускаем перо перо (начало рисования) turtle.onkey(goU, "Up") turtle.onkey(goR, "Right") turtle.onkey(goD, "Down") turtle.onkey(goL, "Left") turtle.listen() # Включить прослушивание событий turtle.penup() # Поднять перо (закончить рисовать) turtle.mainloop() # Задержать окно на экране
iss.setheading(90) lon = round(float(lon)) lat = round(float(lat)) iss.penup() iss.goto(lon, lat) ##My Location yellowlat = 47.6 yellowlon= -122.3 mylocation = turtle.Turtle() mylocation.penup() mylocation.color('yellow') mylocation.goto(yellowlon, yellowlat) mylocation.dot(5) mylocation.hideturtle() passiss = 'http://api.open-notify.org/iss-pass.json' passiss = passiss + '?lat=' + str(yellowlat) + '&lon=' + str(yellowlon) response = urllib.request.urlopen(passiss) result = json.loads(response.read().decode('utf-8')) over = result['response'][1]['risetime'] import time style = ('Arial', 6, 'bold') mylocation.write(time.ctime(over), font=style) turtle.mainloop() # <-- this line should ALWAYS be at the bottom of your script. It prevents the graphic from closing!!!
_L=40 _radian = math.radians(degree) _S = go() _H = _l * math.tan(_radian) def draw_triangle(pos_x, pos_y, lowerside, sameside, angle=40): tu.penup() tu.setx(pos_x) tu.sety(pos_y) tu.pendown() tu.right(angle) go(sameside, 360-angle) go(lowerside, angle) tu.forward(sameside) tu.right(angle) draw_triangle(0, 300, 50, math.cos(math.radians(40))) def tree_trunk(pos_x, pos_y, forward,width): tu.width(width) tu.pencolor('brown') tu.setx(pos_x) tu.sety(pos_y) tu.right(90) tu.forward(forward) tree_trunk(0,-70,80,20) tu.mainloop()
length = length of movement """ t.pu( ) # to command the Turtle pen up (before getting to the point of start the drawing) t.fd( length ) # to command the Turtle to do not draw, for certain length (distance of each flower) t.pd( ) # to command the Turtle pen down, starting the point of drawing (for this case is the center of each flower) bob = turtle.Turtle() # To Draw a sequence of three flowers, as assign in the book # 1st flower move(bob, -100) # tells the point to start for bob flower(bob, 7, 60.0, 60.0) # tells bob to draw 7 petals, 60 radius of arc, 60 angle of arc # 2nd flower move(bob, 100) flower(bob, 10, 40.0, 80.0) #3rd flower move(bob, 100) flower(bob, 20, 140.0, 20.0) # To hide the tutle bob.hideturtle() turtle.mainloop() # to 'kill' the tutle, saying that this is done
def main(): '''This is the starting function main() which defines several config of shapes and random configuration ''' scr = turtle.Screen() turtle.mode('standard') xsize, ysize = scr.screensize() turtle.setworldcoordinates(0, 0, xsize, ysize) turtle.hideturtle() turtle.speed('fastest') turtle.tracer(0, 0) turtle.penup() board = GameOfLife(xsize // CELL_SIZE, 1 + ysize // CELL_SIZE) prefer = turtle.textinput( "Select Configuration", "\n1.glider\n2.Small Exploder\n3.Exploder\n4.10 Cell Row\n5.Light Weight Spaceship\n6.Tumbler\n7.Random\n8.Customised" ) #print("\n1.glider\n2.Small Exploder\n3.Exploder\n4.10 Cell Row\n5.Light Weight Spaceship\n6.Tumbler\n7.Random") #prefer=int(input('Enter your preference:')) #print("You have preffered:",prefer) if prefer == '1': board.glider() elif prefer == '2': board.smallExploder() elif prefer == '3': board.Exploder() elif prefer == '4': board.tenCellRow() elif prefer == '5': board.lightWeightSpacehip() elif prefer == '6': board.tumbler() elif prefer == '7': board.makeRandom() elif prefer == '8': board.loadjsonParse() board.makeCustomised() board.display() # Continuous movement continuous = False def step_continuous(): nonlocal continuous continuous = True perform_step() def perform_step(): board.step() board.display() # Setting timer to display another generation # after 30 ms if continuous: turtle.ontimer(perform_step, 30) global count count += 1 print(count) turtle.ontimer(step_continuous) # Tk loop turtle.listen() turtle.mainloop() turtle.bye()
def circle(radius): bob_circle = turtle.Turtle() c = 2 * math.pi * radius n = int(c / 3) + 1 polygon(bob_circle, n, c / n) turtle.mainloop()
t2 = t.Pen() # 펜 기능을 t2에 부여 t2.shape('turtle') t2.color('red') t2.penup() # 펜을 듬 t2.goto(-200, 100) # 펜을 해당 좌표로 이동 t2.pendown() t2.begin_fill() t2.fillcolor('orange') t2.circle(25) # 반지름 기준으로 원을 그림 t2.end_fill() t3 = t.Pen() t3.shape('turtle') t3.shapesize(5) t3.color('blue') t3.penup() t3.goto(100, 100) t3.pendown() for i in range(5): t3.fd(100) t3.right(72) t4 = t.Pen() t4.shape('turtle') t4.penup() t4.goto(200, 100) t4.pendown() t4.circle(50, 200) # 반지름, 각도 t.mainloop() # 창 안 닫히고 놔둠
import turtle as t t.shape('turtle') t.forward(100) t.right(90) t.forward(100) t.rt(90) t.forward(100) t.rt(90) t.forward(100) t.mainloop()
def main(): unittest.main(verbosity=3) turtle.mainloop()
polyline(t, n, step_length, step_angle) t.rt(step_angle / 2) def circle(t, r): """Draws a circle with the given radius. t: Turtle r: radius """ arc(t, r, 360) # the following condition checks whether we are # running as a script, in which case run the test code, # or being imported, in which case don't. if __name__ == '__main__': bob = turtle.Turtle() # draw a circle centered on the origin radius = 100 bob.pu() bob.fd(radius) bob.lt(90) bob.pd() circle(bob, radius) # wait for the user to close the window turtle.mainloop()
lon = round(float(lon)) lat = round(float(lat)) iss.penup() iss.goto(lon,lat) ## My location yellowlat = 47.6 yellowlon = -122.3 mylocation = turtle.Turtle() mylocation.penup() mylocation.color('yellow') mylocation.goto(yellowlon, yellowlat) mylocation.dot(5) mylocation.hideturtle() passiss = 'http://api.open-notify.org/iss-pass.json' passiss = passiss + '?lat=' + str(yellowlat) + '&lon=' + str(yellowlon) response = urllib.request.urlopen(passiss) result = json.loads(response.read().decode('utf-8')) print(result) over = result['response'][1]['risetime'] style = ('Arial', 6, 'bold') mylocation.write(time.ctime(over), font=style) turtle.mainloop() # This should ALWAYS be at bottom to keep graphic from closing