def __init__(self, size=8): self.size = size self.scr = turtle.Screen() self.scr.title("Train tracks") self.turtle = turtle.Turtle() turtle.mode("standard") turtle.screensize(1000, 1000) self.screen_size = 1000 self.cell_size = self.screen_size / (size + 1) turtle.setworldcoordinates(0, 0, self.screen_size, self.screen_size) self.turtle.hideturtle() self.turtle.speed("fast") turtle.delay(0) turtle.tracer(0, 0) self.turtle.penup() self.layout = [] for row in range(size): col_list = [] for col in range(size): col_list.append(Cell(row, col, self.cell_size)) self.layout.append(col_list) self.start = 0 self.end = 0 self.move_count = 0 self.move_max = 1000000 self.col_count = [] self.row_count = [] self.col_perm = [] self.row_perm = []
def __init__(self): turtle.title('Phogo - CRM UAM') turtle.mode('logo') turtle.penup() #turtle.setx(turtle.screensize()[0] // 8) turtle.screensize(4000, 4000)
def Init(): global secHand, minHand, hurHand, printer # 重置Turtle指向北 turtle.mode("logo") # 建立三个表针Turtle并初始化 mkHand("secHand", 135) mkHand("minHand", 125) mkHand("hurHand", 90) secHand = turtle.Turtle() secHand.shape("secHand") minHand = turtle.Turtle() minHand.shape("minHand") hurHand = turtle.Turtle() hurHand.shape("hurHand") for hand in secHand, minHand, hurHand: hand.shapesize(1, 1, 3) hand.speed(0) # 建立输出文字Turtle printer = turtle.Turtle() # 隐藏画笔的turtle形状 printer.hideturtle() printer.penup()
def main(self,r1=.75,r2=.77,alpha1=35,alpha2=-35,phi1=0,phi2=0,w0=30,qq=.50,e=.40,min_const=0.0, n=10 ): turtle.title("Final Project: Computational Biology: Mesotonic") turtle.setup(1000,600,0,0) turtle.pendown() #turtle.left(90)#point straight up self.min_constant=min_const self.alpha1= alpha1 self.phi1= phi1 self.alpha2= alpha2 self.phi2=phi2; self.r1=r1 self.r2=r2 self.e=e self.qq=qq self.w0=w0 turtle.speed(0) turtle.mode("logo") string = "A(100,"+str(self.w0)+")" #"F(10)A(0)" l = LSystem() instructions=l.createLSystem(10,string,[1,1,1,1,1], meso=True) print (instructions) l.drawLsystem(instructions) return
def bake_pie(list): """call this to start pie_creation""" global length global remaining input=len(list) remaining=length= len(mn.file_string) canvas = turtle.Screen() canvas.title("pie") canvas.colormode(255) turtle.mode("logo") bill = turtle.Turtle() if input > 40: bill.speed(10) elif input>25: bill.speed(5) else: bill.speed(5) bill.setpos(0, -RADIUS) bill.right(90) bill.circle(RADIUS) ###above initiates our canvas ready to make the full circle for object in list: slice= (object[1]/length)*360 remaining -= object[1] pie_slice(bill,slice,object[0],(object[1]/length)) if remaining: slice=(remaining/length)*360 pie_slice(bill,slice,"other",(remaining/length)) turtle.done()
def Init(): global secHand, minHand, hurHand, printer # 重置Turtle指向北 turtle.mode("logo") # 建立三个表针Turtle并初始化 mkHand("secHand", 135) mkHand("minHand", 125) mkHand("hurHand", 90) secHand = turtle.Turtle() secHand.shape("secHand") minHand = turtle.Turtle() minHand.shape("minHand") hurHand = turtle.Turtle() hurHand.shape("hurHand") for hand in secHand, minHand, hurHand: hand.shapesize(1, 1, 3) hand.speed(0) # 建立输出文字Turtle printer = turtle.Turtle() # 隐藏画笔的turtle形状 # colors = ['red','orange','green','cyan','blue','purple'] # printer.pencolor(colors[random.randint(0,5)]) printer.hideturtle() printer.penup()
def _tscheme_prep(): global _turtle_screen_on if not _turtle_screen_on: _turtle_screen_on = True turtle.title("Scheme Turtles") turtle.mode('logo')
def __init__(self): turtle.penup() self.l_vessel = 50 # Metade do comprimento da embarcacao #first we initialize the turtle settings turtle.speed(0) turtle.mode('logo') turtle.setworldcoordinates(5000, 2000, 13000, 7000) turtle.setup() # turtle.screensize(4000, 4000, 'white') w_vessel = 5 # Metade da largura da embarcacao turtle.register_shape( 'vessel', ((0, self.l_vessel), (w_vessel, self.l_vessel / 2), (w_vessel, -self.l_vessel), (-w_vessel, -self.l_vessel), (-w_vessel, self.l_vessel / 2))) turtle.register_shape('rudder', ((-1, 0), (1, 0), (1, -10), (-1, -10))) turtle.degrees() # self.vessel = turtle.Turtle() self.vessel.shape('vessel') self.vessel.fillcolor('red') self.vessel.penup() self.rudder = turtle.Turtle() self.rudder.shape('rudder') self.rudder.fillcolor('green') self.rudder.penup() self.step_count = 0 self.steps_for_stamp = 30
def main(): turtle.mode("logo") turtle.tracer(False) turtle.hideturtle() init() draw_clock_time() turtle.done()
def draw_clock(): """画表盘""" # 让乌龟的朝向默认向上 turtle.reset() turtle.mode('logo') for i in range(60): skip(160) # 根据5格一个时钟 if i % 5 == 0: # 画时钟 turtle.pensize(7) turtle.forward(20) if i == 0: turtle.write(12, align='center', font=('Courier', 14, 'bold')) elif i == 25 or i == 30 or i == 35: skip(25) turtle.write(int(i / 5), align='center', font=('Courier', 14, 'bold')) skip(-25) else: turtle.write(int(i / 5), align='center', font=('Courier', 14, 'bold')) skip(-20) else: turtle.pensize(1) turtle.dot() skip(-160) turtle.right(6)
def init(): global sec_hand, min_hand, hur_hand, printer, printer2 turtle.setup(400, 400, 800, 400) # 窗体 turtle.screensize(300, 300, "pink") # 画布 turtle.mode('logo') mk_hand('sec_hand', 135) mk_hand('min_hand', 110) mk_hand('hur_hand', 90) sec_hand = Turtle() sec_hand.shape("sec_hand") min_hand = Turtle() min_hand.shape("min_hand") hur_hand = Turtle() hur_hand.shape("hur_hand") for hand in sec_hand, min_hand, hur_hand: hand.shapesize(1, 1, 3) hand.speed(0) printer = Turtle() printer.hideturtle() printer.penup() printer2 = Turtle() printer2.hideturtle() printer2.penup()
def __init__(self, width, height): self.width = width self.height = height self.dark = 'black' self.clear = 'white' self.margin = 10 self.scalingFactor = 10 screenEdge = 40 width = self.width * self.scalingFactor + screenEdge height = self.height * self.scalingFactor + screenEdge turtle.mode('world') turtle.bgcolor(self.clear) turtle.title("Default Screen") self.t = turtle.Turtle() self.t.hideturtle() self.t.tracer(0, 0) self.t.speed(10) self.t.pencolor(self.dark)
def start(): # 不显示绘制时钟的过程 turtle.tracer(False) turtle.mode('logo') createHand('second_hand', 150) createHand('minute_hand', 125) createHand('hour_hand', 85) # 秒, 分, 时 second_hand = turtle.Turtle() second_hand.shape('second_hand') minute_hand = turtle.Turtle() minute_hand.shape('minute_hand') hour_hand = turtle.Turtle() hour_hand.shape('hour_hand') for hand in [second_hand, minute_hand, hour_hand]: hand.shapesize(1, 1, 3) hand.speed(0) # 用于打印日期等文字 printer = turtle.Turtle() printer.hideturtle() printer.penup() createClock(160) # 开始显示轨迹 turtle.tracer(True) startTick(second_hand, minute_hand, hour_hand, printer) turtle.mainloop()
def main(args): # Create screen and turtle. screen = turtle.Screen() screen.title('Square Demo') screen_x, screen_y = screen.screensize() t = turtle.Turtle() # Uncomment to draw the graphics as quickly as possible. #t.speed(0) turtle.mode("logo") # Draw a set of nested squares, varying the color. # The squares are 10%, 20%, etc. of half the size of the canvas. length = (screen_y / 2) / 10 * 3 t.pensize(3) count = 0 c = getch() while c: if 'q' == c: break loop(t, int(c) * 5) c = getch()
def init(): tt.setup(*GlobalSetup.WINDOW_RESOLUTION) tt.mode("logo") tt.colormode(255) tt.title("Pandemic Simulation") tt.tracer(0, 0) tt.hideturtle()
def initialiseScreenAndTurtle(): screen = turtle.Screen() screen.reset screen.setworldcoordinates(0, 0, OX + 8 * BOX_X - 20, OY + 8 * BOX_Y - 20) turtle.mode("world") turtle.hideturtle() turtle.speed(SUPERFAST)
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 setup(): global sekundenzeiger, minutenzeiger, stundenzeiger, writer trt.mode("logo") zeichne_vollen_zeiger("sekundenzeiger", 125, 25) zeichne_vollen_zeiger("minutenzeiger", 130, 25) zeichne_vollen_zeiger("stundenzeiger", 90, 25) ziffernblatt(160) sekundenzeiger = trt.Turtle() sekundenzeiger.shape("sekundenzeiger") sekundenzeiger.color("gray20", "gray80") minutenzeiger = trt.Turtle() minutenzeiger.shape("minutenzeiger") minutenzeiger.color("blue1", "red1") stundenzeiger = trt.Turtle() stundenzeiger.shape("stundenzeiger") stundenzeiger.color("blue3", "red3") for hand in sekundenzeiger, minutenzeiger, stundenzeiger: hand.resizemode("user") hand.shapesize(1, 1, 3) hand.speed(0) trt.ht() writer = trt.Turtle() writer.ht() writer.pu() writer.bk(85)
def setup_turtle(self): turtle.setup(800,600) #myWin = turtle.Screen() turtle.colormode(255) turtle.mode("logo") self.turtle.speed(0) self.turtle.hideturtle()
def setup(bg): screen = turtle.Screen() screen.setup(width=720, height=360, startx=0, starty=0) screen.setworldcoordinates(-180, -90, 180, 90) turtle.mode('world') screen.bgpic(bg) return screen
def __init__(self): turtle.speed(0) turtle.mode('logo') turtle.setworldcoordinates(5000, 2000, 14000, 7000) turtle.degrees() turtle.penup() self.step_count = 0 self.steps_for_stamp = 10
def Init(): turtle.mode("logo") # hands global scnd, mnte, our, sx, sy, mx, my, hx, hy getHand("second") getHand("minute") getHand("hour") getHand("point") our = turtle.Turtle() our.shape("hour") our.color("#000000") our.fillcolor("#0000ff") mnte = turtle.Turtle() mnte.shape("minute") mnte.color("#000000") mnte.fillcolor("#00ff00") scnd = turtle.Turtle() scnd.shape("second") scnd.color("#000000") scnd.fillcolor("#ff0000") for hand in our, mnte, scnd: hand.penup() hand.speed(0) hand.goto(0, 230) # hand.pendown() hx = turtle.Turtle() hx.fillcolor("#aaaaff") hx.color("#aaaaff") hy = turtle.Turtle() hy.fillcolor("#aaaaff") hy.color("#aaaaff") mx = turtle.Turtle() mx.fillcolor("#aaffaa") mx.color("#aaffaa") my = turtle.Turtle() my.fillcolor("#aaffaa") my.color("#aaffaa") sx = turtle.Turtle() sx.fillcolor("#ffaaaa") sx.color("#ffaaaa") sy = turtle.Turtle() sy.fillcolor("#ffaaaa") sy.color("#ffaaaa") sx.pensize(6) sy.pensize(6) mx.pensize(9) my.pensize(9) hx.pensize(14) hy.pensize(14) for point in sx, sy, mx, my, hx, hy: point.shape("point") point.penup() point.hideturtle() # map SetupClock(250) turtle.hideturtle()
def initTurtle(windowWidth, windowHeight): turtle.mode("logo") turtle.color("blue") turtle.setup(windowWidth, windowHeight) # Start position at bottom centre of window turtle.up() turtle.setpos(0, -(windowHeight / 2)) turtle.down()
def setup(self): """ Basic initial setting """ tt.setup(self.width, self.height) tt.title("Dreamy cellar during pandemic") # tt.tracer(0, 0) tt.mode("logo") tt.colormode(255) tt.speed(10)
def execute_code(self): self.log.write('================Ejecutando maquina virtual==========================') turtle.mode("logo") while self.current_quadruple < len(self.quadruple_list): quadruple = self.quadruple_list[self.current_quadruple]; action = quadruple['operator'] self.options[action](self,quadruple) self.current_quadruple = self.current_quadruple + 1 self.log.write(" ================ Termina ejecucion de cuadruplos ==================")
def main(): inst = createLSystem(6, "X") # create the string t = turtle.Turtle() # create the turtle t.color("#FFF8DC") wn = turtle.Screen() wn.tracer(0) turtle.mode("logo") wn.bgcolor("#efccba") x = -350 y = 270 for i in range(10): t.up() t.setpos(x, y) t.down() drawLsystem(t, inst, 20, 5) # draw the picture t.setheading(0) x += 80 x = -340 y = 170 for i in range(7): t.up() t.setpos(x, y) t.down() drawLsystem(t, inst, 20, 10) # draw the picture t.setheading(0) x += 150 x = -250 y = -50 for i in range(4): t.up() t.setpos(x, y) t.down() drawLsystem(t, inst, 20, 20) # draw the picture t.setheading(0) x += 200 x = -300 y = -380 for i in range(4): t.up() t.setpos(x, y) t.down() drawLsystem(t, inst, 20, 30) # draw the picture t.setheading(0) x += 250 wn.exitonclick()
def main(): t = turtle.Turtle() turtle.mode("logo") myWin = turtle.Screen() t.up() t.backward(400) t.down() t.color("green") t.speed(10) tree(100, t) myWin.exitonclick()
def proud_turtle(): turtle.mode('logo') length = 250 height = 25 colors = ['violet', 'purple', 'blue', 'green', 'yellow', 'orange', 'red', 'brown', 'black'] for c in colors: draw_filled_rect(c, length, height) turtle.mainloop()
def plot_setup(): if not PLOT: return turtle.setup(width=PLOT_CANVAS_X, height=PLOT_CANVAS_Y, startx=PLOT_WINDOW_X, starty=PLOT_WINDOW_Y) turtle.mode("standard") turtle.setworldcoordinates( -TABLE_X_MAX*PLOT_MARGIN, -TABLE_Y_MAX*PLOT_MARGIN, TABLE_X_MAX*(1.+PLOT_MARGIN), TABLE_Y_MAX*(1.+PLOT_MARGIN) ) turtle.hideturtle() turtle.penup()
def LsystemCouleur(axiome,regles,niveau=1,distance=10,angle=90,position=(0,0),direction=90) : from LSysteme import screen,construire_chaine import turtle as tt tt.mode('world') tt.tracer(0) #on enlève les animations xpos=[] ypos=[] chaine= construire_chaine(axiome,regles,niveau) #on construit la chaine au niveau voulu motif = construire_chaine(axiome,regles,2) xpos,ypos = dessinerCouleur(chaine,motif,distance,angle,position,direction,xpos,ypos)#et on la dessine screen(xpos,ypos) #on affiche la fenêtre avec les bonnes coordonnées
def init(titre="", largeur=640, hauteur=480): """ Initialise l'environnement (titre et taille de la fenêtre) et place le robot au centre, en position levée, orienté vers le nord, tracé de couleur noire """ global __robot turtle.setup(largeur, hauteur) turtle.Screen() turtle.title(titre) turtle.mode('logo') __robot = turtle.Turtle() up() center() north() color("noir")
def main(): t.screensize(600, 700, 'Antiquewhite') #设置画布的宽高背景颜色 # t.setup(600,700) # 设置绘画窗口的宽度高度 t.title("分形树") t.mode('logo') #设置方向为正北 t.penup() #起笔 t.color('Saddlebrown') #设置树的颜色 t.pensize(5) #设置绘画笔的宽度 t.backward(250) #把起点放到底部 t.pendown() #下笔 tree_len = 360 #树干的初始长度 tree_angle = 60 #树干的角度 draw_tree(tree_len, tree_angle) t.exitonclick() #点击才关闭画画窗口
def __init__(self, n): turtle.mode("logo") james.speed(10) james.color("blue") james.pensize(10) james.pu() james.backward(300) james.pd() james.forward(100) james.pu() james.tracer(200) self.drawTree(n, 60, 0, -200, 0, 10) window.exitonclick()
def __init__(self, width, height, title): self.width = width self.height = height self.title = title self.game_running = False self.tick = None #function to call for each animation cycle turtle.title(title) #title for the window turtle.setup(width, height) #set window display turtle.hideturtle() #prevent turtle appearance turtle.tracer(False) #prevent turtle animation turtle.listen() #set window focus to the turtle window turtle.mode('logo') #set 0 direction as straight up turtle.penup() #don't draw anything
def main(args): # Create screen and turtle. screen = turtle.Screen() screen.title('Square Demo') screen_x, screen_y = screen.screensize() t = turtle.Turtle() turtle.mode("logo") # Draw a set of nested squares, varying the color. # The squares are 10%, 20%, etc. of half the size of the canvas. length = (screen_y / 2) / 10 * 3 t.pensize(3) loop(t, 20)
def draw(self): turtles = [turtle.Turtle()] turtle.mode('logo') turtles[0].up() if self.config['hideturtle']: turtles[0].ht() turtles[0].speed(0) turtles[0].sety(self.config['offy']) turtles[0].setx(self.config['offx']) turtles[0].down() for x in self.string: turtles = x.draw(turtles) raw_input('press return key to exit')
def main(): window = turtle.Screen() window.bgcolor("black") turtle.mode("logo") koopa = turtle.Turtle() koopa.shape("classic") koopa.color("#028482","#028482") koopa.speed(1000) # The board/background draw_triangle(koopa, (-300,-300), 600, 120, "#028482") # The actual Sierpinski Triangle sierpinski(koopa, (0, -300), 300, 3) window.exitonclick()
def reset(self): """ move turtle to 0, 0 Returns: self """ import turtle turtle.penup() turtle.home() turtle.pendown() self.origin = [0, 0] # turtle must be reset after every exitonclick # turtle head north and positive angles is clockwise turtle.mode('world') turtle.setheading(90) turtle.speed(0) # fastest turtle.hideturtle() turtle.tracer(0, 1) return self
def __init__(self, n): # The song which inspirates this. turtle.title("Some Nights") # Mode logo makes positive angles clockwise. turtle.mode("logo") # Set a dark color for the background. turtle.bgcolor("#2c3e50") # Set the fastest speed fun.speed(0) # Set a the branches' color. fun.color("#825a2c") fun.pensize(10) fun.pu() fun.backward(300) fun.pd() fun.forward(100) fun.pu() fun.tracer(200) self.drawTree(n, 60, 0, -200, 0, 10) fun.width(1) fun.penup() fun.goto(-150, 100) for i in range(0, 10): for j in range(0,10): # Set the color of the snowflakes fun.color("#ecf0f1") fun.pendown() self.drawSnowflake((i+j)%3+1,2) fun.penup() fun.setheading(90) fun.forward(30) fun.setheading(270) fun.forward(300) fun.setheading(180) fun.forward(50) window.exitonclick()
def Init(): global secHand, minHand, hurHand, printer #重置turtle指向北 turtle.mode("logo") #建立三个表针Turtle并初始化 mkHand("secHand", 135) mkHand("minHand", 125) mkHand("hurHand", 90) secHand = turtle.Turtle() secHand.shape("secHand") minHand = turtle.Turtle() minHand.shape("minHand") hurHand = turtle.Turtle() hurHand.shape("hurHand") for hand in secHand, minHand, hurHand: hand.shapesize(1, 1, 3) hand.speed(0) #建立输出文字 printer = turtle.Turtle() #隐藏画笔的turtle形状 printer.hideturtle() printer.penup()
import turtle screen = turtle.Screen() turtle.mode('world') turtle.hideturtle() turtle.tracer(1000) # Don't render until the end... for i in range(12): turtle.circle(50) turtle.rt(30) turtle.update() # ...now render print screen.getcanvas().postscript()
* Tools, and other libraries support """ # Basic Environment Setup # __future__ must be first in a python program! Needed for 2.6+ only. from __future__ import division, print_function # For sprites, pens, and the timer import turtle, time # Setup a Global time. __TIME = time.time() # Global answer variable __ANSWER = '' # Set a turbo mode checker __TURBO_ON = False # Create a 'Sprite' __SPRITE = turtle.Turtle() turtle.mode('logo') __SPRITE.up() __SPRTIE.speed(10) # Doesn't account for bigger snap stages. turtle.screensize(320, 480) def notImplemented(b): print(b + " has not been implemented.\n") ############################################################################### # MOTION BLOCKS # ############################################################################### """ The command blocks with dropdowns need functions: point-towards() -- at least we can probably do mouse-pointer
t.write(l.abc) t.color("black") for l in chain(self.x_lines, self.y_lines, self.d_lines): l.draw(t) if __name__ == '__main__': # Create screen and turtle. screen = turtle.Screen() screen.title('202 Demo') screen_x, screen_y = screen.screensize() # Uncomment to draw the graphics as quickly as possible. turtle.mode("standard") # Draw a set of nested squares, varying the color. # The squares are 10%, 20%, etc. of half the size of the canvas. m = Model(12) t0 = Translator(Point(-400, -300), 50) v0 = t0.translate_grid(m) v0.draw(turtle.Turtle()) c = getch() while c: if 'q' == c: break
def main(): display_help_window() 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 = LifeBoard(xsize // CELL_SIZE, 1 + ysize // CELL_SIZE) # Set up mouse bindings def toggle(x, y): cell_x = x // CELL_SIZE cell_y = y // CELL_SIZE if board.is_legal(cell_x, cell_y): board.toggle(cell_x, cell_y) board.display() turtle.onscreenclick(turtle.listen) turtle.onscreenclick(toggle) board.makeRandom() board.display() # Set up key bindings 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') # Set up keys for performing generation steps, either one-at-a-time or not. continuous = False def step_once(): nonlocal continuous continuous = False perform_step() def step_continuous(): nonlocal continuous continuous = True perform_step() def perform_step(): board.step() board.display() # In continuous mode, we set a timer to display another generation # after 25 millisenconds. if continuous: turtle.ontimer(perform_step, 25) turtle.onkey(step_once, 's') turtle.onkey(step_continuous, 'c') # Enter the Tk main loop turtle.listen() turtle.mainloop()
def main(): screen = turtle.Screen() turtle.mode('standard') xspan, yspan = screen.screensize() turtle.setworldcoordinates(0, 0, xspan, yspan) # makes the turtle invisible, improves drawing speed turtle.hideturtle() # fastest speed for the drawing turtle.speed('fastest') # no tracing within turtle, improves drawing speed turtle.tracer(0, 0) # turtle pen is off the canvas to start turtle.penup() board = Grid(xspan // SIZE, yspan // SIZE) def flip_state(x, y): x_cell = x // SIZE y_cell = y // SIZE board.flip_state(x_cell,y_cell) board.display() turtle.onscreenclick(turtle.listen) turtle.onscreenclick(flip_state) def clear_board(): board.clear_board() board.display() # binds function to the 'e' key turtle.onkey(clear_board, 'e') # binds function to the 'q' key turtle.onkey(sys.exit, 'q') continuous = False def step_once(): # allows for the rebinding of variables outside of the local scope nonlocal continuous continuous = False perform_step() def step_continuous(): nonlocal continuous continuous = True perform_step() def perform_step(): board.step() board.display() if continuous: # calls function in question after t milliseconds turtle.ontimer(perform_step, 25) # binds functions to the 's' and 'c' keys respectively turtle.onkey(step_once, 's') turtle.onkey(step_continuous, 'c') # prints out the coordinates (keys) of the current live cells def print_live(): board.print_keys() turtle.onkey(print_live, 'p') # draws a Glider in the upper left of the display def draw_glider(): board.glider() board.display() turtle.onkey(draw_glider, '1') # draws a Garden of Eden in the display def draw_garden(): board.garden() board.display() turtle.onkey(draw_garden, '2') # draws a Gosper Glider Gun in the display def draw_glider_gun(): board.glider_gun() board.display() turtle.onkey(draw_glider_gun, '3') # draws a Sparky in the display def draw_sparky(): board.sparky() board.display() turtle.onkey(draw_sparky, '4') # turtle listens for key events turtle.listen() # required last statement in a program using turtle graphics turtle.mainloop()
import turtle as t from math import pi, sin, cos # set the parameters for the tree trunk = 150; # trunk length alphaR = 45; # alphaL = 45; # ratioR = .6; # ratio of a branch to the next on the right ratioL = .6; # ratio of a branch to the next on the right runs = 14; # recursion depth # make sure that the turtle in facing the right direction # initial heading = north # positive angles are clockwise t.mode("logo") t.speed(0) t.hideturtle() t.tracer(10000, 1) # Recursively draw the tree. # Inputs: 'length': length of the branch being drawn # (included as an input so they can be aried with recusion depth) # 'alphaR': angle of turn on right branches # 'alphaL': angle of turn on left branches def drawTree(length, alphaR, alphaL, depth): if depth == 0: return t.forward(length)
def initialize(): """Initialize the turtle so that it is facing North with the pen up.""" turtle.mode("logo") turtle.pu() turtle.shape("turtle")
import turtle import re turtle.mode("logo") t = turtle.Turtle() t.ht() def draw (prodRule, rotate, length): location = [] heading = [] for i in prodRule: if i == "G": t.fd(length) if i == "F": t.fd(length) if i == "-": t.left(rotate) if i == "+": t.right(rotate) if i == "[": location.append(t.pos()) heading.append(t.heading()) if i == "]": t.penup() t.setpos(location.pop()) t.seth(heading.pop()) t.pendown() def generateProduction(initial, Frule, Grule, iteration): for i in range(0, iteration):
def run_turtle(var, start, rules, iters, angle, startdir=0): """Var, start, rules and iters, correspond to (V, w, P, n) of the l-system function. The distance moved is scaled down from size. The turtle starts facing startdir. Instructions are defined as the following: F, G: Draw forward M, N: Move forward (don't draw) [, ]: Push and pop angle and location +, -: Turn left and right by angle degrees Variables not described can be used as constants. """ # Initialization terry = turtle.Turtle() turtle.mode("world") # Coordinate system terry.pensize(1) terry.pencolor("blue") terry.speed(0) # Instant speed turtle.tracer(0, 0) # Don't draw anything yet (could change in future) turtle.setup(width=900, height=900, startx=None, starty=None) # Square pixels terry.hideturtle() dist = 1 positions = [] angles = [] bounds = [0, 0, 0, 0] # llx, lly, urx, ury instructions = l_system(var, start, rules, iters) print("First 50 instructions:\n", instructions[:50]) def update_bounds(bounds): coords = terry.position() bounds[0] = min(bounds[0], coords[0]) bounds[1] = min(bounds[1], coords[1]) bounds[2] = max(bounds[2], coords[0]) bounds[3] = max(bounds[3], coords[1]) # Run turtle terry.left(startdir) # Starting direction for instr in instructions: if instr in ('F', 'G'): terry.forward(dist) update_bounds(bounds) elif instr in ('M', 'N'): terry.penup() terry.forward(dist) terry.pendown() update_bounds(bounds) elif instr == '[': positions.append(terry.pos()) angles.append(terry.heading()) elif instr == ']': terry.penup() terry.goto(positions.pop()) terry.setheading(angles.pop()) terry.pendown() elif instr == '+': terry.left(angle) elif instr == '-': terry.right(angle) llx, lly, urx, ury = bounds width = urx - llx height = ury - lly if width > height: y_center = (ury + lly)/2 ury = y_center + width/2 lly = y_center - width/2 else: x_center = (urx + llx)/2 urx = x_center + height/2 llx = x_center - height/2 print("Bounds:", bounds) turtle.setworldcoordinates(llx, lly, urx, ury) # Redraw turtle.update() # Draw everything turtle.exitonclick()
def drawhangman(numberofguesses): wn = turtle.Screen() turtle.mode('logo') peter = turtle.Turtle() peter.hideturtle() peter.speed(10) def square(sidelength): # Draw square. for i in range(4): peter.forward(sidelength) peter.right(90) def drawline(turn, distance): # Draw a line. if turn < 0: peter.left(abs(turn)) elif turn > 0: peter.right(turn) peter.forward(distance) if turn < 0: peter.right(abs(turn)) elif turn > 0: peter.left(turn) def move(turn, distance): # Moving the pen. peter.penup() if turn < 0: peter.left(abs(turn)) elif turn > 0: peter.right(turn) peter.forward(distance) if turn < 0: peter.right(abs(turn)) elif turn > 0: peter.left(turn) peter.pendown() def drawgallows(): # Draw the gallows. move(-90, 150) move(180, 100) square(75) move(0, 75) move(90, 37.5) drawline(0,200) drawline(90, 150) drawline(180, 25) def drawhead(): # Draw the head. move(-90, 17.5) move(180, 35) square(35) def drawbody(): # Draw the body. move(90, 17.5) drawline(180, 75) def drawlleg(): drawline(225, 50) move(45, 50) def drawrleg(): drawline(135, 50) move(-45, 50) def drawlfoot(): move(225, 50) drawline(-45, 10) move(135, 10) move(45, 50) def drawrfoot(): move(135, 50) drawline(45, 10) move(-135, 10) move(-45, 50) move(0, 50) def drawlarm(): drawline(-45, 50) move(135, 50) def drawrarm(): drawline(45, 50) move(-135, 50) def drawkill(): move(0,25) move(-90, 17.5) drawline(45, 49) move(-90, 35) drawline(135, 49) if numberofguesses == 1: drawgallows() elif numberofguesses == 2: drawgallows() drawhead() elif numberofguesses == 3: drawgallows() drawhead() drawbody() elif numberofguesses == 4: drawgallows() drawhead() drawbody() drawlleg() elif numberofguesses == 5: drawgallows() drawhead() drawbody() drawlleg() drawrleg() elif numberofguesses == 6: drawgallows() drawhead() drawbody() drawlleg() drawrleg() drawlfoot() elif numberofguesses == 7: drawgallows() drawhead() drawbody() drawlleg() drawrleg() drawlfoot() drawrfoot() elif numberofguesses == 8: drawgallows() drawhead() drawbody() drawlleg() drawrleg() drawlfoot() drawrfoot() drawlarm() elif numberofguesses == 9: drawgallows() drawhead() drawbody() drawlleg() drawrleg() drawlfoot() drawrfoot() drawlarm() drawrarm() elif numberofguesses == 10: drawgallows() drawhead() drawbody() drawlleg() drawrleg() drawlfoot() drawrfoot() drawlarm() drawrarm() drawkill() wn.exitonclick()
def main(): display_help_window() scr = turtle.Screen() turtle.mode('standard') x, y = scr.screensize() turtle.setworldcoordinates(0, 0, x, y) turtle.hideturtle() turtle.speed('fastest') turtle.tracer(0, 0) turtle.penup() board = pantalla(x // tamanioCelula, 1 + y // tamanioCelula) def cambiar(x, y): cell_x = x // tamanioCelula cell_y = y // tamanioCelula board.cambiar(cell_x, cell_y) board.display() turtle.onscreenclick(turtle.listen) turtle.onscreenclick(cambiar) board.aleatorio() board.display() def borrar(): board.borrar() board.display() turtle.onkey(borrar, 'e') def aleatorio(): board.aleatorio() board.display() turtle.onkey(aleatorio, 'r') turtle.onkey(sys.exit, 'q') continuo = False def generacionSiguiente(): nonlocal continuo continuo = False generar() def continuo(): nonlocal continuo continuo = True generar() def generar(): board.generacion() board.display() if continuo: turtle.ontimer(generar, 25) turtle.onkey(generacionSiguiente, 's') turtle.onkey(continuo, 'c') turtle.listen() turtle.mainloop()
import turtle # Import turtle graphics. def drawBranch(size, angle): # Recursive function to draw a part of the tree. turtle.fd(size) if size>5: turtle.rt(angle/2) drawBranch(size*0.75, angle) turtle.lt(angle) drawBranch(size*0.75, angle) turtle.rt(angle/2) turtle.bk(size) # This is the main program. size=180 # Base element size for the tree. angle=60 # Angle between the branches. turtle.tracer(8,0) # Speed up the drawing...a lot. Replace 8 with 16 or 32 for even faster drawing. turtle.mode('logo') # Use LOGO language orientation: turtle faces upward. turtle.pu() # Pull up the pen to pre-position the turtle. turtle.bk(size*2) turtle.pd() # Then put the pen back down to draw. drawBranch(size, angle) # Draw the tree.