def dibujarLadrillo(tipo, numero): global xFila, yFila if tipo == "terminoLinea": yFila += 20 xFila = 80 elif tipo == "vacio": xFila += (numero)*80 else: for i in range (numero): x = Rectangle ((xFila,yFila),(xFila+80, yFila+20)) listaLadrillos.append(x) x.draw(v) if tipo == "tipoUno" : x.border = 0 listaLadrillosVidas.append(1) color = pickOne(getColorNames()) while color== "black": color = pickOne(getColorNames()) x.fill = Color (color) elif tipo == "tipoDos": listaLadrillosVidas.append(2) color = pickOne(getColorNames()) while color == "black": color = pickOne(getColorNames()) x.fill = Color (color) elif tipo == "tipoTres": listaLadrillosVidas.append(3) x.fill = Color("black") xFila += 80
def dibujarLadrillo(tipo, numero): global xFila, yFila if tipo == "terminoLinea": yFila += 20 xFila = 80 elif tipo == "vacio": xFila += (numero) * 80 else: for i in range(numero): x = Rectangle((xFila, yFila), (xFila + 80, yFila + 20)) listaLadrillos.append(x) x.draw(v) if tipo == "tipoUno": x.border = 0 listaLadrillosVidas.append(1) color = pickOne(getColorNames()) while color == "black": color = pickOne(getColorNames()) x.fill = Color(color) elif tipo == "tipoDos": listaLadrillosVidas.append(2) color = pickOne(getColorNames()) while color == "black": color = pickOne(getColorNames()) x.fill = Color(color) elif tipo == "tipoTres": listaLadrillosVidas.append(3) x.fill = Color("black") xFila += 80
def moveBugs(bugs): for bug in bugs: left = getColor(picture, bug.center.x - 2, bug.center.y).red right = getColor(picture, bug.center.x + 2, bug.center.y).red up = getColor(picture, bug.center.x, bug.center.y - 2).red down = getColor(picture, bug.center.x, bug.center.y + 2).red options = [] if left == max(left, right, up, down): options.append("left") if right == max(left, right, up, down): options.append("right") if up == max(left, right, up, down): options.append("up") if down == max(left, right, up, down): options.append("down") move = pickOne(options) if move == "left": bug.move(-2, 0) elif move == "right": bug.move(2, 0) elif move == "up": bug.move(0, -2) elif move == "down": bug.move(0, 2)
from Graphics import * from Myro import pickOne, randomNumber import math win = Window("Angry Blocks", 800, 300) win.mode = "physics" for x in range(5): for y in range(5 - x): #if y % 2 == 1: c = Rectangle((600 + y * 25 + x *10, 260 - x * 20), (600 + y * 25 + 20 + x * 10, 280 - x * 20)) #else: # c = Pie((600 + y * 25 + x *10, 260 - x * 20), 10, 0, 360) c.fill = Color(pickOne(getColorNames())) c.draw(win) c.bounce = 0 radius = 10 ball = Circle((50, 270), radius) ball.draw(win) #ball.mass = .5 ball.bounce = 0.5 ball.friction = 0.05 #ball.wrap = True ground = Rectangle((0, 281), (800, 310)) ground.bodyType = "static" ground.color = Color("green") ground.draw(win) ground.friction = 10.0 #ground.bounce = .4
from Graphics import * from Myro import random, getColorNames, pickOne win = Window() win.mode = "bitmap" while win.isRealized(): x1, y1, x2, y2 = [random() * 300 for i in range(4)] line = Line((x1, y1), (x2, y2)) line.color = Color(pickOne(getColorNames())) line.draw(win)
def verificarChoqueLadrillos(): global listaLadrillos, listaLadrillosVidas, direccion, puntos indice = 0 for ladrillo in listaLadrillos: condicionChoqueLadrilloArriba = (pelota.y == ladrillo.y - 20) and ( pelota.x >= ladrillo.x - ladrillo.width / 2) and ( pelota.x <= ladrillo.x + ladrillo.width / 2) and direccion["y"] == 1 condicionChoqueLadrilloLateral = ( (pelota.y >= ladrillo.y - ladrillo.height / 2) and (pelota.y <= ladrillo.y + ladrillo.height / 2)) and ( (pelota.x == ladrillo.x - (ladrillo.width + pelota.width) / 2) or (pelota.x == ladrillo.x + (ladrillo.width + pelota.width) / 2)) condicionChoqueLadrilloAbajo = (pelota.y == ladrillo.y + 20) and ( pelota.x >= ladrillo.x - ladrillo.width / 2) and ( pelota.x <= ladrillo.x + ladrillo.width / 2) and direccion["y"] == -1 condicionChoqueEsquinaSI = (pelota.x == ladrillo.x - 50) and ( pelota.y == ladrillo.y - 20) and (direccion["x"] > 0 and direccion["y"] > 0) condicionChoqueEsquinaSD = (pelota.x == ladrillo.x + 50) and ( pelota.y == ladrillo.y - 20) and (direccion["x"] < 0 and direccion["y"] > 0) condicionChoqueEsquinaII = (pelota.x == ladrillo.x - 50) and ( pelota.y == ladrillo.y + 20) and (direccion["x"] > 0 and direccion["y"] < 0) condicionChoqueEsquinaID = (pelota.x == ladrillo.x + 50) and ( pelota.y == ladrillo.y + 20) and (direccion["x"] < 0 and direccion["y"] < 0) condicionChoqueEsquina = condicionChoqueEsquinaSI or condicionChoqueEsquinaSD or condicionChoqueEsquinaII or condicionChoqueEsquinaID #Checar choque ladrillo arriba if condicionChoqueLadrilloArriba: #Checar vidas de ladrillo listaLadrillosVidas[indice] -= 1 if listaLadrillosVidas[indice] == 2: puntos += 50 color = pickOne(getColorNames()) while color == "black": color = pickOne(getColorNames()) listaLadrillos[indice].fill = Color(color) if listaLadrillosVidas[indice] == 1: puntos += 30 listaLadrillos[indice].border = 0 if listaLadrillosVidas[indice] == 0: puntos += 20 listaLadrillos[indice].undraw() listaLadrillos.remove(listaLadrillos[indice]) listaLadrillosVidas.remove(listaLadrillosVidas[indice]) direccion["y"] *= -1 break if condicionChoqueLadrilloAbajo: #Checar vidas de ladrillo listaLadrillosVidas[indice] -= 1 if listaLadrillosVidas[indice] == 2: puntos += 50 color = pickOne(getColorNames()) while color == "black": color = pickOne(getColorNames()) listaLadrillos[indice].fill = Color(color) if listaLadrillosVidas[indice] == 1: puntos += 30 listaLadrillos[indice].border = 0 if listaLadrillosVidas[indice] == 0: puntos += 20 listaLadrillos[indice].undraw() listaLadrillos.remove(listaLadrillos[indice]) listaLadrillosVidas.remove(listaLadrillosVidas[indice]) direccion["y"] *= -1 break #Checar choque lateral if condicionChoqueLadrilloLateral or condicionChoqueEsquina: #Checar vidas de ladrillo direccion["x"] *= -1 break indice += 1 txtPuntos.text = "Puntos: " + str(puntos)
left = Rectangle((650, 650), (680, 680)) left.bodyType = "static" left.color = Color("green") left.draw(win) #Crea el rectangulo de abajo x = 820 click = 0 for x in range(4): for y in range(4 - x): R = Rectangle((600 + y * 100 + x * 40, 260 - x * 80), (600 + y * 100 + 80 + x * 40, 280 - x * 80)) R.bodyType = "static" R.fill = Color(pickOne(getColorNames())) R.draw(win) R.bounce = 0 #son los rectantangulos enemigos de arriba def handleSpaceBar(win, event): points = 0 global x global click click += 1 y = 600 X = left.getX() Y = left.getY() c = Circle((X, Y), 8) c.fill = Color("red")
# Convert screen center from pixels to meters circlePosition = Vector2.Add(Vector2.Divide(screenCenter, MeterInPixels), Vector2(2 - .25 * i, -2.0 + i * .05)) # Create the circle fixture circle = CreateCircle(world, # world 47.0 / MeterInPixels, # ? 1.0, # mass circlePosition) # center circle.BodyType = BodyType.Dynamic # or # Give it some bounce and friction circle.Restitution = 0.8 circle.Friction = 0.5 sprite = Circle((150, 10), 47) sprite.color = Color(pickOne(["red", "blue", "green"])) sprite.draw(win) sprite.outline = Color("black") circles.append( (circle, sprite) ) # Ground # groundPosition = Vector2.Add(Vector2.Divide(screenCenter, MeterInPixels), Vector2(0, 7.25)) # Create the ground fixture groundBody = CreateRectangle(world, 512.0 / MeterInPixels, 64.0 / MeterInPixels, 1.0, # mass groundPosition)
def search(items, match): while not items.is_empty(): node = items.next() shape = g.getNode(str(node.item)) shape.fill = Color("pink") if node.item == match: return True items.append(*node.expand()) return False def reset_color(tree): node = g.getNode(str(tree.item)) node.fill = Color("white") if tree.left: reset_color(tree.left) if tree.right: reset_color(tree.right) tree = makeRandomTree(5) g = Graph() g.layout(treeToList(tree)) win = Window(1000, 300) g.draw(win, {"label": "Random Graph", "default_shape": "box", "line_type": "line"}) number = ask("What number do you want to search for?") while number: r = int(number) print(search(Stack([tree]), r)) r = pickOne(*rands) number = ask("What number do you want to search for?") reset_color(tree)
def verificarChoqueLadrillos(): global listaLadrillos, listaLadrillosVidas, direccion, puntos indice = 0 for ladrillo in listaLadrillos: condicionChoqueLadrilloArriba = (pelota.y == ladrillo.y - 20) and (pelota.x >= ladrillo.x - ladrillo.width/2) and (pelota.x <= ladrillo.x + ladrillo.width/2) and direccion["y"] == 1 condicionChoqueLadrilloLateral = ((pelota.y >= ladrillo.y - ladrillo.height/2) and (pelota.y <= ladrillo.y + ladrillo.height/2)) and ((pelota.x == ladrillo.x - (ladrillo.width + pelota.width)/2) or (pelota.x == ladrillo.x + (ladrillo.width + pelota.width)/2) ) condicionChoqueLadrilloAbajo = (pelota.y == ladrillo.y + 20) and (pelota.x >= ladrillo.x - ladrillo.width/2) and (pelota.x <= ladrillo.x + ladrillo.width/2) and direccion["y"] == -1 condicionChoqueEsquinaSI = (pelota.x == ladrillo.x - 50) and (pelota.y == ladrillo.y - 20) and (direccion["x"] > 0 and direccion["y"] > 0) condicionChoqueEsquinaSD = (pelota.x == ladrillo.x + 50) and (pelota.y == ladrillo.y - 20) and (direccion["x"] < 0 and direccion["y"] > 0) condicionChoqueEsquinaII = (pelota.x == ladrillo.x - 50) and (pelota.y == ladrillo.y + 20) and (direccion["x"] > 0 and direccion["y"] < 0) condicionChoqueEsquinaID = (pelota.x == ladrillo.x + 50) and (pelota.y == ladrillo.y + 20) and (direccion["x"] < 0 and direccion["y"] < 0) condicionChoqueEsquina = condicionChoqueEsquinaSI or condicionChoqueEsquinaSD or condicionChoqueEsquinaII or condicionChoqueEsquinaID #Checar choque ladrillo arriba if condicionChoqueLadrilloArriba: #Checar vidas de ladrillo listaLadrillosVidas [indice] -= 1 if listaLadrillosVidas [indice] == 2: puntos += 50 color = pickOne(getColorNames()) while color== "black": color = pickOne(getColorNames()) listaLadrillos[indice].fill = Color (color) if listaLadrillosVidas [indice] == 1: puntos += 30 listaLadrillos[indice].border = 0 if listaLadrillosVidas [indice] == 0 : puntos += 20 listaLadrillos[indice].undraw() listaLadrillos.remove (listaLadrillos[indice]) listaLadrillosVidas.remove (listaLadrillosVidas[indice]) direccion["y"] *= -1 break if condicionChoqueLadrilloAbajo: #Checar vidas de ladrillo listaLadrillosVidas [indice] -= 1 if listaLadrillosVidas [indice] == 2: puntos += 50 color = pickOne(getColorNames()) while color== "black": color = pickOne(getColorNames()) listaLadrillos[indice].fill = Color (color) if listaLadrillosVidas [indice] == 1: puntos += 30 listaLadrillos[indice].border = 0 if listaLadrillosVidas [indice] == 0 : puntos += 20 listaLadrillos[indice].undraw() listaLadrillos.remove (listaLadrillos[indice]) listaLadrillosVidas.remove (listaLadrillosVidas[indice]) direccion["y"] *= -1 break #Checar choque lateral if condicionChoqueLadrilloLateral or condicionChoqueEsquina: #Checar vidas de ladrillo direccion["x"] *= -1 break indice +=1 txtPuntos.text = "Puntos: " + str (puntos)