def main(): global screen, red, green, blue screen = Screen() screen.delay(0) screen.setworldcoordinates(-1, -0.3, 3, 1.3) #red = ColorTurtle(0, .5) #green = ColorTurtle(1, .5) #blue = ColorTurtle(2, .5) setbgcolor() writer = Turtle() writer.ht() writer.pu() writer.goto(1, 0.3) #writer.write("DRAG!",align="center",font=("Arial",30,("bold","italic"))) #writer.write("我们毕业了!", align="center", font=("微软雅黑", 40, "bold")) writer.write("我们毕业了!", align="center", font=("宋体", 40, "bold")) writer.goto(1, 0.5) writer.write("我们毕业了!", align="center", font=("微软雅黑", 40, "bold")) writer.goto(1, 0.7) writer.write("我们毕业了!", align="center", font=("楷体", 40, "bold")) return "EVENTLOOP"
def main(self): global screen, red, green, blue screen = Screen() screen.delay(0) screen.setworldcoordinates(-1, -0.3, 3, 1.3) red = ColorTurtle(0, .5) green = ColorTurtle(1, .5) blue = ColorTurtle(2, .5) setbgcolor() writer = Turtle() writer.ht() writer.pu() writer.goto(1, 1.15) writer.write("DRAG!", align="center", font=("Arial", 30, ("bold", "italic"))) return "EVENTLOOP" if __name__ == "__main__": msg = main() print(msg)
def __init__(self, center, radius): """ (GraphicalCircle, tuple, int) -> GraphicalCircle Initializes a graphical circle object The circle is centered at the position <center>. The circle radius is set to the <radius> """ # Make a turtle graphics object to do the drawing. # Assign it to an instance variable the_turtle, # so other methods can access it self.the_turtle = Turtle() self.the_turtle.speed(0) # fastest turtle self.the_turtle.hideturtle() # hide turtle the_screen = Screen() # Create local screen object: Receive user input the_screen.delay(0) # trace drawing delay - slow the_screen.listen() # focus on keystrokes # Mouse click re-positions the circle the_screen.onclick(self.move) # Set mouse press handler - # Up cursor key calls the increases method to expand the circle the_screen.onkey(self.increase, 'Up') # Set "up" cursor key handler # Down cursor key calls the deecrease method to contract the circle the_screen.onkey(self.decrease, 'Down') # Set "Down" cursor key handler # Make a circle object # Assign it to an instance variable the_circle, # so other methods can access it self.the_circle = Circle(center, radius) mainloop() # Start event loop
def draw_maze(maze, scale, *, screen=None, tracer=False, delay=0, speed=0, updates=False, start_x=0, start_y=0): if screen is None: screen = Screen() width = scale * maze.width height = scale * maze.height original_tracer = screen.tracer() original_delay = screen.delay() screen.tracer(tracer) screen.delay(delay) turtle = RawTurtle(screen, visible=False) turtle.speed(speed) turtle.setpos(start_x, start_y) turtle.setheading(0) turtle.showturtle() x, y, dx, dy = 0, 0, 1, 0 while True: sx, sy = rotate_right(dx, dy) print(x, y, maze[x, y]) if maze[x, y][sx, sy]: if maze[x, y][rotate_left(sx, sy)]: print('a') turtle.forward(scale - 1) turtle.left(90) dx, dy = rotate_left(dx, dy) else: print('b') turtle.forward(scale) x, y = x + dx, y + dy else: print('c') turtle.right(90) turtle.forward(1) dx, dy = rotate_right(dx, dy) x, y = x + dx, y + dy if (x, y, dx, dy) == (0, 0, 1, 0): break screen.tracer(original_tracer) screen.delay(original_delay) screen.update() return screen
def __init__(self, center, radius): """ Initializes a graphical circle object. The circle is centered at the position specified by the center parameter. The circle's radius is set to the radius parameter. """ # Make a turtle graphics object to do the drawing. Assign it # to an instance variable so other methods can access it. self.turtle = Turtle() self.turtle.speed(0) # Make turtle's actions as fast as possible self.turtle.hideturtle() # Make the turtle invisible # Create a local Screen object to receive user input. screen = Screen() screen.delay(0) # Do not slowly trace drawing screen.listen() # Set focus for keystrokes # Mouse click repositions the circle screen.onclick(self.move) # Set mouse press handler # Up cursor key calls the increase method to expand the circle screen.onkey(self.increase, 'Up') # Set "up" cursor key handler # Down cursor key calls the decrease method to contract the circle screen.onkey(self.decrease, 'Down') # Set "down" cursor key handler # Make a circle object. Assign it to an instance variable so other methods # can access it. self.circle = Circle(center, radius) # Start the graphics environment. The local screen object # will exist until the user quits the program. screen.mainloop()
def main(): global screen, red, green, blue screen = Screen() screen.delay(0) screen.setworldcoordinates(-1, -0.3, 3, 1.3) red = ColorTurtle(0, 0.5) green = ColorTurtle(1, 0.5) blue = ColorTurtle(2, 0.5) setbgcolor() writer = Turtle() writer.ht() writer.pu() writer.goto(1, 1.15) writer.write('DRAG!', align='center', font=('Arial', 30, ('bold', 'italic'))) return 'EVENTLOOP'
def blank_image(self, l=None, w=None, bg=None, mode=None): if l is None: l = self.length if w is None: w = self.width if bg is None: bg = self.bg if mode is None: mode = self.mode screen = Screen() screen.setup(width=l, height=w, startx=0, starty=0) screen.screensize(l, w) screen.bgcolor(*bg) screen.colormode(mode) screen.delay(0) return screen
def main(): global screen, red, green, blue screen = Screen() screen.delay(0) screen.setworldcoordinates(-1, -0.3, 3, 1.3) red = ColorTurtle(0, .11111111) green = ColorTurtle(1, .884444) blue = ColorTurtle(2, .999454) setbgcolor() writer = Turtle() writer.ht() writer.pu() writer.goto(1,1.15) writer.write("EAT YOUR VEGTABLES!!!!!!!!!!!!!!!!!!!!!!!!!!!!",align="center",font=("Arial",30,("bold","italic"))) return "EVENTLOOP"
def main(): global screen, red, green, blue screen = Screen() screen.delay(0) screen.setworldcoordinates(-1, -0.3, 3, 1.3) red = ColorTurtle(0, .5) green = ColorTurtle(1, .5) blue = ColorTurtle(2, .5) setbgcolor() writer = Turtle() writer.ht() writer.pu() writer.goto(1,1.15) writer.write("Drag The Sliders To Change The Color!",align="center",font=("Arial",30,("bold","italic"))) return "ColorChanger"
def main(): global screen, red, green, blue screen = Screen() screen.delay(0) screen.setworldcoordinates(-1, -0.3, 3, 1.3) red = ColorTurtle(0, .5) green = ColorTurtle(1, .5) blue = ColorTurtle(2, .5) setbgcolor() writer = Turtle() writer.ht() writer.pu() writer.goto(1,1.15) writer.write("DRAG!",align="center",font=("Arial",30,("bold","italic"))) return "EVENTLOOP"
def main(): global screen, red, green, blue screen = Screen() screen.delay(0) screen.setworldcoordinates(-1, -0.3, 3, 1.3) screen.tracer(8,25) red = ColorTurtle(0, .5) green = ColorTurtle(1, .5) blue = ColorTurtle(2, .5) writer = Turtle() writer.ht() writer.pu() writer.goto(1,1.15) writer.write("DRAG!",align="center",font=("Arial",30,("bold","italic"))) return "EVENTLOOP"
def main(): global screen, red, green, blue screen = Screen() # 返回窗口工作区对象 screen.delay(0) # 绘图无延迟 screen.setworldcoordinates(-1, -0.3, 3, 1.3) red = ColorTurtle(0, .7) green = ColorTurtle(1, .3) blue = ColorTurtle(2, .6) setbgcolor() write = Turtle() write.hideturtle() write.up() write.goto(1, 1.15) write.write("Welcome to 小周 GAME!", align="center", font=("Arial", 30, ("bold", "italic")))
class ViewController: """This class is responsible for controlling the simulation and visualizing it.""" screen: Any pen: Turtle model: Model def __init__(self, model: Model): """Initialize the VC.""" self.model = model self.screen = Screen() self.screen.setup(constants.VIEW_WIDTH, constants.VIEW_HEIGHT) self.screen.tracer(0, 0) self.screen.delay(0) self.screen.title("Cluster Funk v2") self.pen = Turtle() self.pen.hideturtle() self.pen.speed(0) def start_simulation(self) -> None: """Call the first tick of the simulation and begin turtle gfx.""" self.tick() done() def tick(self) -> None: """Update the model state and redraw visualization.""" start_time = time_ns() // NS_TO_MS self.model.tick() self.pen.clear() for cell in self.model.population: self.pen.penup() self.pen.goto(cell.location.x, cell.location.y) self.pen.pendown() self.pen.color(cell.color()) self.pen.dot(constants.CELL_RADIUS) self.screen.update() if self.model.is_complete(): return else: end_time = time_ns() // NS_TO_MS next_tick = 30 - (end_time - start_time) if next_tick < 0: next_tick = 0 self.screen.ontimer(self.tick, next_tick)
def get_screen(): screen = Screen() screen.setup(*conf.SCREEN_SIZE) screen.bgcolor(conf.BACKGROUND) screen.tracer(conf.TRACER) screen.delay(conf.DELAY) screen.title(conf.TITLE) screen.speed = conf.SPEED screen.winheight = screen.window_height() * .95 screen.winwidth = screen.window_width() * .95 screen.width = screen.winwidth // 2 screen.height = screen.winheight // 2 screen.blockwidth = conf.BLOCK_WIDTH screen.increment = screen.blockheight = conf.BLOCK_HEIGHT screen.base = screen.height screen.start = -screen.width + screen.blockwidth screen.blocks = int(((screen.width * 2) - (screen.blockwidth * 2)) // (screen.blockwidth + 1)) screen.gradient = gradient(conf.GRADIENT, screen.blocks) return screen
def main(): try: global tela, ANGULO_SEGUNDO ANGULO_SEGUNDO = 360 / 60 tela = Screen() tela.title("Relógio") tela.tracer(0, 0) tela.bgcolor(0, 0, 0) tela.delay(0) tela.setup(700, 700) segundos = Ponteiro("segundos") minutos = Ponteiro("minutos") horas = Ponteiro("horas") clock = Relogio((segundos, minutos, horas)) clock.desenhar_numeros() clock.exibir_hora(True) except: pass
def run(): screen = Screen() screen.delay(0) blob = Blob() screen.onkey(lambda: blob.scale(1.1), '+') screen.onkey(lambda: blob.scale(0.9), '-') screen.onkey(lambda: blob.forward(), 'Up') screen.onkey(lambda: blob.backward(), 'Down') screen.onkey(lambda: blob.stepLeft(), 'a') screen.onkey(lambda: blob.stepRight(), 'd') screen.onkey(lambda: blob.rotate(1), 'Left') screen.onkey(lambda: blob.rotate(-1), 'Right') screen.onkey(lambda: blob.flip(), 'space') screen.listen() screen.mainloop()
def draw_graph(gr, screen): screen = Screen() screen.bgcolor("black") screen.delay(0) screen.colormode(255) topological_ordered = list( reversed(list(nx.algorithms.topological_sort(gr)))) for node in topological_ordered: data = node.data try: color = node.attrs['color'] except KeyError: color = (255, 0, 0) pen = Turtle() pen.hideturtle() pen.penup() pen.pencolor(*color) points = to_tups(data) pen.goto(*(points[0])) pen.pendown() for point in points[::-1]: pen.goto(*point) # print(color,point) screen.mainloop()
# spirograph # # 2015-09-07 -- first release # 2019-01-15 -- pensize 2, make default window fit 1024x768 display from turtle import Screen, Turtle from math import sin, cos, pi from time import sleep steps = 360 # level of detail or number of patterns in space s = Screen() s.setup(width=900, height=700, startx=0, starty=2) # TEK 4010 = 1024 x 780 l = s.window_height() / 4 - 10 s.bgcolor("black") s.delay(0) t = Turtle() t.hideturtle() t.pencolor("green") t.pensize(2) t.speed(0) j = 1 while True: t.goto(2 * l, 0) t.clear() i = 0 while i <= steps: angle = 2 * i * pi / steps
doubles = None DATABASE_NAME = 'system/stats.db' # # # Game states #### # 0 - choose game play # 50 - choose game type # 100 - choose game size # 150 - choose players # 200 - in game # window screen set up window = Screen() window.title("Table tennis scoreboard") window.bgcolor("black") window.setup(width=1024, height=600) window.delay(0) window.tracer(False) # turtle set up pen = Turtle() pen.speed(0) pen.color("white") pen.hideturtle() pen.penup() # definitions of game functions def database_update_singles(): global player2_id, player1_id, playerNames, match_duration, leftScore, rightScore conn = connect(DATABASE_NAME)
#LIBRERÍAS NECESARIAS PARA LA EJECUCIÓN DEL PROGRAMA from turtle import Screen, Turtle from math import sqrt import sys try: # CONFIGURACIÓN INICIAL DE LA VENTANA EMERGENTE CON SUS RESPECTIVAS PROPIEDADES pantalla = Screen() pantalla.setup(1020, 1025) pantalla.screensize(1000, 1000) pantalla.setworldcoordinates(-500, -500, 500, 500) pantalla.delay(0) #VALORES NECESARIOS PARA CADA UNO DE LOS CUERPOS x1 = -200 y1 = -200 velocidad_x1 = 0.1 velocidad_y1 = 0 m1 = 20 # VALORES NECESARIOS PARA EL SEGUNDO CUERPO x2 = 200 y2 = 200 velocidad_x2 = -0.1 velocidad_y2 = 0 m2 = 20 x3 = 300 y3 = 300 velocidad_x3 = 2.1 velocidad_y3 = 0
class MazeGraphics(object): def __init__(self, config): self.width = config.getValueAsInt("maze", "maze_size") self.height = config.getValueAsInt("maze", "maze_size") self.bg_color = config.getValue("maze", "bg_color") self.line_color = config.getValue("maze", "line_color") self.line_centroid_color = config.getValue("maze", "line_centroid_color") self.forward_centroid_color = config.getValue("maze", "forward_centroid_color") self.reverse_centroid_color = config.getValue("maze", "reverse_centroid_color") self.path_color = config.getValue("maze", "path_color") self.screen = Screen() self.setupTurtle(self.width, self.height) def setupTurtle(self, width, height): self.screen.tracer(False) self.screen.screensize(width, height) # some basic turtle settings self.screen.setworldcoordinates(-1, -1, width + 1, height + 1) self.screen.title("Random Turtle Maze") self.screen.bgcolor(self.bg_color) self.screen.delay(None) self.designer = Turtle(visible=False) def drawGrid(self): for i in xrange(0, self.width + 1): self.drawXLines(i, self.width, self.line_color) for i in xrange(0, self.height + 1): self.drawYLines(i, self.width, self.line_color) self.screen.update() def drawXLines(self, position, width, color): self.drawLines(position, 0, width, color, 90) def drawYLines(self, position, width, color): self.drawLines(0, position, width, color, 0) def drawLines(self, xPosition, yPosition, width, color, heading): self.designer.up() self.designer.setposition(xPosition, yPosition) self.designer.color(color) self.designer.down() self.designer.setheading(heading) self.designer.forward(width) self.designer.up() def drawCentroid(self, cell, color): """ Draw a centroid for animation purposes but then overwrite it. """ self.designer.setposition(cell.centroid) self.designer.dot(5, color) self.screen.update() self.designer.dot(5, self.bg_color) def removeWall(self, posx, posy, heading, color): """ We tear down walls to build the maze """ self.designer.up() self.designer.setposition(posx, posy) self.designer.down() self.designer.color(color) self.designer.setheading(heading) self.designer.forward(1) self.designer.up() self.screen.update() def drawPath(self, cell1, cell2): """ This draws a line for the solution as it's worked out. """ self.designer.setposition(cell1.centroid) self.designer.color(self.path_color) direction = self.getDirection(cell1, cell2) if direction == "N": self.designer.setheading(90) self.designer.down() self.designer.forward(1) self.designer.up() elif direction == "S": self.designer.setheading(270) self.designer.down() self.designer.forward(1) self.designer.up() elif direction == "W": self.designer.setheading(0) self.designer.down() self.designer.forward(1) self.designer.up() elif direction == "E": self.designer.setheading(0) self.designer.down() self.designer.backward(1) self.designer.up() self.drawCentroid(cell2, self.line_centroid_color) self.screen.update() def getDirection(self, currCell, nextCell): direction = None if nextCell.x < currCell.x: direction = "E" elif nextCell.x > currCell.x: direction = "W" elif nextCell.y < currCell.y: direction = "S" elif nextCell.y > currCell.y: direction = "N" return direction
class Tablero(): totalCeldas = 0 coords = {} #{1:[(),(),(),()],2:(),(),(),()} coordsSimple = {} #{(x,y):(f,c),(x,y):(f,c)} celdaOcupadaTablero = [ ] #Almacena las celdas ocupadas entre todos los jugadores en el tablero save_drawing = [] def __init__(self, lienzo, color='black', full=True, ancho_pantalla=810, alto_pantalla=430, visible=True, filas=3, celdas=3, alto_celda=20, ancho_celda=20, ejes=False, celdas_numeradas=False): self.widthScreen = ancho_pantalla self.heightScreen = alto_pantalla self.visible = visible self.alto = filas self.ancho = celdas self.alto_celda = alto_celda self.ancho_celda = ancho_celda self.t = Turtle() self.t.color(color) self.t.hideturtle() self.screen = Screen() self.screen.setup(self.widthScreen, self.heightScreen) self.screen.tracer(0, 0) self.screen.delay(0) self.malla(full=True) if celdas_numeradas == True: self.celdasNumeradas() self.paleta() self.lienzo(color=lienzo) if ejes == True: self.ejes() ############################################################################################ def go(self, x, y, down=True): self.t.up() self.t.goto(x, y) if down: self.t.down() ############################################################################################ def malla(self, x=0, y=0, full=False): """ Dibuja la cuadricula base. Si full=True la fila 1 comienza en la esquina sup iz de screen. Crea lista de coordenadas self.coords={FILA_1:(x,y),FILA_2:(x,y)} self.coordsSimple={(x,y):(1,2)} """ if full: x = self.widthScreen / -2 y = self.heightScreen / 2 self.ancho = int(self.widthScreen / self.ancho_celda) self.alto = int(self.heightScreen / self.alto_celda) self.go(x, y) #Va al punto de inicio, primera fila, primera celda for k in range(0, self.alto): # c calcula la coordenada de Y basada en la altura de la celda*fila c = (-k * self.alto_celda) + y self.go(x, c, down=self.visible) self.coords[k + 1] = [] for i in range(1, self.ancho + 1): self.celda(self.ancho_celda, self.alto_celda) #guardamos las coordenadas para cada celda #calcula el punto central de la celda basado en el ancho y alto de cada celda/2 xCor = ((self.ancho_celda * i) + x) - (self.ancho_celda / 2) yCor = c - (self.alto_celda / 2) self.coords[k + 1].append((xCor, yCor)) self.coordsSimple[(xCor, yCor)] = (k + 1, i) self.go((self.ancho_celda * i) + x, c, down=self.visible) def celda(self, ancho, alto): angulo = 360 self.totalCeldas += 1 #Lleva la cuenta de celdas dibujadas/veces llamado for i in range(1, 5): angulo -= 90 if i % 2 != 0: self.t.forward(ancho) self.t.seth(angulo) else: self.t.forward(alto) self.t.seth(angulo) ############################################################################################ def onclick(self): self.screen.onclick(lambda x, y: self.gestion(x, y)) ############################################################################################ def gestion(self, xClick, yClick): #Obtiene la coordenada central de la celda coordenadas_celda = self.getCelCoords(xClick, yClick) #Obtiene la coordenada simple(1,1) de esa celda coordenadas_celda_simple = self.coordsSimple[coordenadas_celda] #print('coordenada completa ',coordenadas_celda) print('coordenada simple ', coordenadas_celda_simple) color = 'green' if coordenadas_celda_simple[0] >= 3 and coordenadas_celda_simple[ 0] <= 19 and coordenadas_celda_simple[ 1] >= 3 and coordenadas_celda_simple[1] <= 38: self.celdaOcupadaTablero.append( (coordenadas_celda_simple[0], coordenadas_celda_simple[1], self.color)) self.relleno(coordenadas_celda) else: if coordenadas_celda_simple == (2, 7): self.color = 'red' elif coordenadas_celda_simple == (2, 9): self.color = 'blue' elif coordenadas_celda_simple == (2, 11): self.color = 'green' elif coordenadas_celda_simple == (2, 13): self.color = 'yellow' elif coordenadas_celda_simple == (2, 15): self.color = 'grey' elif coordenadas_celda_simple == (2, 17): self.color = 'purple' elif coordenadas_celda_simple == (20, 5): #DELETE print('delete') self.lienzo(color='beige') self.celdaOcupadaTablero = [] elif coordenadas_celda_simple == (20, 9): #SAVE print('save') file_name = self.screen.textinput('Save', 'Title:') outfile = open(file_name, 'wb') pickle.dump(self.celdaOcupadaTablero, outfile) outfile.close() elif coordenadas_celda_simple == (20, 13): #LOAD print('load') file_name = self.screen.textinput('Load', 'Title:') try: infile = open(file_name, 'rb') drawing = pickle.load(infile) infile.close() self.setDrawing(drawing) self.loadDrawing() except: print('Nombre no válido') #print(self.celdaOcupadaTablero) ############################################################################################ def getCoordsbySimple(self, f=0, c=0): for i in self.coordsSimple.items(): if i[1] == (f, c): return i[0] ############################################################################################ def getCelCoords(self, xClick, yClick): #devuelve las coordenadas de la celda respecto a las coordenadas del click #dicho de otra forma. Recibe las coordenadas del click y devuelve las coordenadas # de la celda for key in self.coords.keys(): count = 1 for celda in self.coords[key]: x = celda[0] y = celda[1] """ Calcula las cordenadas centrales de cada lado de la celda Luego compara las coordenadas del click y comprueba si están dentro de los extremos """ maxX = x + (self.ancho_celda / 2) minX = x - (self.ancho_celda / 2) maxY = y + (self.alto_celda / 2) minY = y - (self.alto_celda / 2) r = 0 if xClick < maxX and xClick > minX: r += 1 if yClick < maxY and yClick > minY: r += 1 if r == 2: return (x, y) else: count += 1 ############################################################################################ def lienzo(self, color='grey'): self.color = color for fila in self.coords.keys(): count = 0 if fila > 2 and fila < len(self.coords.keys()) - 1: for celda in self.coords[fila]: if count < len(self.coords[fila]) - 2 and count > 1: self.relleno(celda) count += 1 self.color = 'blue' ########################################################################################## def compruebaCeldaOcupada(self, celda=()): """ Devuelve cierto! si la celda=(x,y) se encuentra en el atributo de clase self.celdaOcupada """ if celda in self.celdaOcupadaTablero: return True else: return False ############################################################################################ def ejes(self, separacion=50): """ Dibuja ejes cartesianos de referencia """ self.t.color('black') self.go(self.widthScreen / -2, 0) self.t.forward(self.widthScreen) self.go(0, self.heightScreen / 2) self.t.seth(270) self.t.forward(self.heightScreen) for i in range(0, 4): self.go(0, 0) self.t.seth(90 * i) if i == 0 or i == 1: if i == 0: for i in range(1, int( (self.widthScreen / 2) / separacion)): self.t.forward(separacion) self.t.write('+' + str(separacion * i), font=("Arial", 5, "normal")) else: for i in range(1, int( (self.heightScreen / 2) / separacion)): self.t.forward(separacion) self.t.write('+' + str(separacion * i), font=("Arial", 5, "normal")) else: if i == 2: for i in range(1, int( (self.widthScreen / 2) / separacion)): self.t.forward(separacion) self.t.write('-' + str(separacion * i), font=("Arial", 5, "normal")) else: for i in range(1, int( (self.heightScreen / 2) / separacion)): self.t.forward(separacion) self.t.write('-' + str(separacion * i), font=("Arial", 5, "normal")) self.go(0, 0) self.t.seth(0) ############################################################################################ def celdasNumeradas(self): """ Muestra el numero de fila y celda en cada cuadro """ for coords in self.coordsSimple.keys(): self.go(coords[0], coords[1]) self.t.write(self.coordsSimple[coords]) ############################################################################################ def relleno(self, coordenadas): self.go(coordenadas[0], coordenadas[1] - (self.alto_celda / 2)) self.t.begin_fill() self.t.color(self.color) self.t.forward(self.ancho_celda / 2) self.t.seth(90) self.t.forward(self.alto_celda) self.t.seth(180) self.t.forward(self.ancho_celda) self.t.seth(270) self.t.forward(self.alto_celda) self.t.seth(0) self.t.forward(self.ancho_celda) self.t.end_fill() ############################################################################################ def paleta(self): choose = self.coords[2][1] self.go(x=choose[0], y=choose[1] - 5) self.t.write('Choose a colour') #DELETE choose = self.coords[20][1] self.go(x=choose[0], y=choose[1] - 5) self.t.write('Delete') self.color = 'black' button_delete = self.coords[20][4] self.relleno(button_delete) ################## #SAVE choose = self.coords[20][6] self.go(x=choose[0], y=choose[1] - 5) self.t.write('Save') self.color = 'black' button_save = self.coords[20][8] self.relleno(button_save) ################## #LOAD choose = self.coords[20][10] self.go(x=choose[0], y=choose[1] - 5) self.t.write('Load') self.color = 'black' button_save = self.coords[20][12] self.relleno(button_save) ################## self.color = 'red' rojo = self.coords[2][6] self.relleno(rojo) self.color = 'blue' azul = self.coords[2][8] self.relleno(azul) self.color = 'green' verde = self.coords[2][10] self.relleno(verde) self.color = 'yellow' amarillo = self.coords[2][12] self.relleno(amarillo) self.color = 'grey' gris = self.coords[2][14] self.relleno(gris) self.color = 'purple' morado = self.coords[2][16] self.relleno(morado) ############################################################################################ def loadDrawing(self): lista = self.celdaOcupadaTablero for celda in lista: self.color = celda[2] self.relleno(self.getCoordsbySimple(f=celda[0], c=celda[1])) ############################################################################################ def setDrawing(self, lista): for celda in lista: self.celdaOcupadaTablero.append(celda)
B = random.random() colors = tut.color(R, G, B) return colors tut.speed(2) tut.pensize(6) color() forward(50) write(" 7 AM") forward(50) write(" 9 AM") screen.delay(100) forward(50) write(" 11 AM") forward(50) write(" Wake Up") color() forward(50) write(" Listen Music | Refresh") color() forward(50) write(" Started Online Classes") color()
from turtle import Turtle, Screen import heroes import random tim = Turtle() tim.shape("turtle") tim.color("magenta2") cols = ["magenta2", "red", "orange", "green", "blue", "purple"] random.shuffle(cols) screen = Screen() screen.delay(0) tim.speed("fastest") # for i in range(36): # tim.circle(100) # tim.right(10) def turtle_draw(sides): for shape_sides in range(sides): tim.forward(100) tim.right(360 / float(sides)) screen.colormode(255) for i in range(500): # tCol = str(cols[random.randint(0, 5)]) # tim.color(tCol) side_a = min(255,int(255*abs(tim.pos()[0])/70)) side_b = min(255,int(255*abs(tim.pos()[1])/70)) if tim.pos()[0] >= 0:
(78, 113, 79), (136, 27, 19), (117, 30, 43), (184, 100, 86), (48, 58, 93), (172, 100, 115), (31, 48, 43), (102, 120, 168), (101, 155, 93), (214, 174, 190), (216, 180, 173), (65, 81, 28), (164, 208, 187), (177, 186, 214), (219, 207, 10), (48, 73, 62), (40, 74, 81), (179, 197, 201), (112, 132, 141) ] # Get painting grid parameters dot_size = int(input("dot size : ")) dot_spacing = int(input("dot spacing : ")) x_grid = int(input("x-axis number of dots : ")) y_grid = int(input("y-axis number of dots : ")) # Screen setup s = Screen() s.colormode(255) s.delay(0) # fast animation # The screensize() method sets the amount of area the turtle can roam, # but doesn't change the screen size (despite the name), just the scrollable area. # s.screensize(dot_spacing * (x_grid + 1), dot_spacing * (y_grid + 1)) s.setup(dot_spacing * (x_grid + 1), dot_spacing * (y_grid + 1)) s.setworldcoordinates(-dot_spacing, -dot_spacing, dot_spacing * x_grid, dot_spacing * y_grid) # print(s.screensize()) # Turtle setup t = Turtle() t.speed(0) # fastest turtle speed t.pu() # Draw dot pattern (10 x 10) for y in range(0, dot_spacing * y_grid, dot_spacing):
Dim['Y']['upper'] ] win.setworldcoordinates(D[0], D[1], D[2], D[3]) G = Grapher(Dim) ''' f = lambda x : sin(x) interval = (0,9,0.1) Region1 = singlaValueFun_numGen(f,interval) x_t = lambda t : cos(t) y_t = lambda t: 2*sin(t) interval = { 'lower' : 0, 'upper' : 2*pi, 'increment' : 0.1 } Region2 = ParametricEqu_numGen(x_t,y_t,interval) ''' r_theta = lambda theta: 3 * cos(2 * theta) interval = {'lower': 0, 'upper': 2 * pi, 'increment': 0.01} Region3 = PolarEqu_numGen(r_theta, interval) win.numinput("Poker", "Your stakes:", 1000, minval=10, maxval=10000) win.delay(5) G.plot(Region3) win.mainloop()
from turtle import Screen, Turtle from math import sqrt pantalla = Screen() pantalla.setup(1025, 1025) pantalla.screensize(1000, 1000) pantalla.setworldcoordinates(-500, -500, 500, 500) pantalla.delay() x1 = -200 y1 = -200 velocidad_x1 = 0.1 velocidad_y1 = 0 m1 = 20 x2 = 200 y2 = 200 velocidad_y2 = 0 velocidad_x2 = -0.1 m2 = 20 #from math import sqrt cuerpo1 = Turtle('circle') cuerpo1.color('red') cuerpo1.speed(0) cuerpo1.penup() cuerpo1.goto(x1, y1) cuerpo1.pendown()
from turtle import Screen, Turtle from math import sin, pi, cos pantalla = Screen() pantalla.title("seno y coseno!!") pantalla.setup(1025, 200) pantalla.screensize(1000, 175) # param(x1, y1, x2, y2) pantalla.setworldcoordinates(-2 * pi, -1, 2 * pi, 1) pantalla.delay(0) # Tiempo que transcurre entre 2 fotogramas # rayamos la cancha tortu = Turtle() tortu.pencolor("blue") tortu.hideturtle() tortu.penup() tortu.goto(-2 * pi, 0) tortu.pendown() tortu.goto(2 * pi, 0) tortu.penup() tortu.goto(0, -1) tortu.pendown() tortu.goto(0, 1) # dibujamos la curva tortuga = Turtle() tortuga.pencolor("green") tortuga.speed(0) tortuga.hideturtle()
counter = counter + 1 continue else: break print(counter) if counter == len(Block.images): messagebox.showinfo("恭喜,恭喜", "成功啦") Block.success_flag = True return True if __name__ == "__main__": cors = [(100, 100), (-100, -100), (-100, 100), (100, -100)] screen = Screen() screen.delay(20) screen.bgcolor("gray") redblock = Block('square', cors, 0, 3) redblock.shapesize(8, 8) redblock.color("red") orangeblock = Block('square', cors, 1, 2) orangeblock.shapesize(8, 8) orangeblock.color("orange") yellowblock = Block('square', cors, 2, 0) yellowblock.shapesize(8, 8) yellowblock.color("yellow") greenblock = Block('square', cors, 3, 1) greenblock.shapesize(8, 8)
def ejercicio141(): # CONFIGURACIÓN INICIAL DE LA VENTANA EMERGENTE CON SUS RESPECTIVAS PROPIEDADES pantalla = Screen() pantalla.setup(1020, 1025) pantalla.screensize(1000, 1000) pantalla.setworldcoordinates(-500, -500, 500, 500) pantalla.delay(0) # VALORES NECESARIOS PARA CADA UNO DE LOS CUERPOS x1 = -200 y1 = -200 velocidad_x1 = -0.1 velocidad_y1 = 0 m1 = 20 # VALORES NECESARIOS PARA EL SEGUNDO CUERPO x2 = 200 y2 = 200 velocidad_x2 = -0.1 velocidad_y2 = 0 m2 = 20 # CARACTERÍSTICAS RESPECTIVAS PARA EL PRIMER CUERPO cuerpo1 = Turtle('circle') cuerpo1.color('red') cuerpo1.speed(0) cuerpo1.penup() cuerpo1.goto(x1, y1) cuerpo1.pendown() # CARACTERÍSTICAS RESPECTIVAS PARA EL SEGUNDO CUERPO cuerpo2 = Turtle('circle') cuerpo2.color('blue') cuerpo2.speed(0) cuerpo2.penup() cuerpo2.goto(x2, y2) cuerpo2.pendown() # CICLO QUE PERMITE LA EJECUCIÓN DE LAS PROPIEDADES EN LA VENTANA EMERGENTE for t in range(10000): # PROPIEDAD PARA EL RADIO r = sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) # PROPIEDADES PARA SU RESPECTIVCA ACELERACIÓN aceleracion_x1 = m2 * (x2 - x1) / r ** 3 aceleracion_y1 = m2 * (y2 - y1) / r ** 3 aceleracion_x2 = m1 * (x1 - x2) / r ** 3 aceleracion_y2 = m1 * (y1 - y2) / r ** 3 # PROPIEDAD PARA SU RESPECTIVA VELOCIDAD velocidad_x1 += aceleracion_x1 velocidad_y1 += aceleracion_y1 velocidad_x2 += aceleracion_x2 velocidad_y2 += aceleracion_y2 # PROPIEDAD PARA LAS COORDENADAS x1 = velocidad_x1 y1 = velocidad_y1 x2 = velocidad_x2 y2 = velocidad_y2 # PROPIEDAD PARA LOS CUERPOS. cuerpo1.goto(x1, y1) cuerpo2.goto(x2, y2)