def run(main_screen, man): setup(man, main_screen) main_game.clear((255,255,255),main_screen) pos = [0,0] player = img.img((100,100),pos,"screenshot.jpeg") player.draw(main_screen) place = [random.randint(0,400),random.randint(0,400)] apple = img.img((100,100),(place[0],place[1]),"apple.jpg") apple.draw(main_screen) points = 0 while True: ev = pygame.event.poll() pygame.display.flip() if (apple.pic.collidepoint(pos)): points+=1 place = [random.randint(0,400),random.randint(0,400)] apple = update(main_screen, pos, place, points) if ev.type == pygame.KEYDOWN: if ev.key == pygame.K_DOWN: pos[1] = pos[1]+15 update(main_screen, pos, place, points) if ev.key == pygame.K_UP: pos[1] = pos[1]-15 update(main_screen, pos, place, points) if ev.key == pygame.K_LEFT: pos[0] = pos[0]-15 update(main_screen, pos, place, points) if ev.key == pygame.K_RIGHT: pos[0] = pos[0]+15 update(main_screen, pos, place, points)
def setup(man, main_screen): main_game.clear((255,255,255),main_screen) man.pic_hair = img.img(man.hair_list[man.hair][1],man.hair_list[man.hair][2],man.hair_list[man.hair][0]) man.pic_hair.draw(main_screen) man.pic_mouth = img.img((100,80),(200,300),man.mouth_list[man.mouth]) man.pic_mouth.draw(main_screen) man.pic_nose = img.img((60,50),(220,240),man.nose_list[man.nose]) man.pic_nose.draw(main_screen) man.pic_eyes = img.img((140,50),(180,170),man.eyes_list[man.eye]) man.pic_eyes.draw(main_screen) pygame.image.save(main_screen, "screenshot.jpeg")
def update(main_screen, pos, place, points): main_game.clear((255,255,255),main_screen) apple = img.img((100,100),(place[0],place[1]),"apple.jpg") apple.location = place apple.draw(main_screen) player = img.img((100,100),pos,"screenshot.jpeg") player.draw(main_screen) f = buttons.button((170,65),(325,435),(255,151,153)) f.draw(main_screen) g = label.Label((333,440),(70,70),(232,23,61), "None" , 45, str(points) + " points") g.draw(main_screen) return apple
def luminance_img(i): """ Transforms a RGB image to a L image using luminance """ mat = img.matrix(i) matlum = [[rgb_to_lum(p) for p in F] for F in mat] return img.img(matlum, 'L')
def split_digit(imag): """ Reotrna una tupla amb la imatge del primer nombre retallat seguida de la resta de la imatge >>> split_digit(("1", [[255,255,0,255,255,0,0,0,255],[255,0,0,255,255,255,255,255,255],[255,255,0,255,255,0,0,0,255],[255,255,0,255,255,0,0,0,255]])) (('1', [[255, 0], [0, 0], [255, 0], [255, 0]]), ('1', [[255, 255, 0, 0, 0, 255], [255, 255, 255, 255, 255, 255], [255, 255, 0, 0, 0, 255], [255, 255, 0, 0, 0, 255]])) """ matrix = img.matrix(imag) if (img.format(img.img(matrix)) != "1"): #Nomes pot ser blanci negre raise Exception("The format must be black and white") start = findBlack( matrix) #Troba on comenca el nombre (columna de pixels negres) if ( start == None ): #Si no es troba pixels negres es retornara una imatge nula, ja que no hi ha cap mes nombre per retallar return img.null() finish = findWhite( matrix, start ) #Troba on acaba el nombre, es a dir a la columna abans d'on nomes hi ha una columna blanca croppedNumber = img.subimg( imag, start, 0, finish - start, len(matrix) ) #Retalla el nombre --> Des don comenca el nombre, amb l'amplada que te = Final - comencament endCropped = img.subimg(imag, finish + 1, 0, len(matrix[0]) - finish + 1, len(matrix)) #La resta del nombre return (croppedNumber, endCropped ) #Retorna la tupla amb el nombre retallat i la resta
def rgb_to_bn(i): L = luminance_img(i) H = histogram(L) discr = get_threshold(H) matl = img.matrix(L) matbw = [[(0 if greyval < discr else 255) for greyval in f] for f in matl] # bw_mean(BW) return img.img(matbw, '1')
def readLearningDataset(learning): for digit in range(10): for fileNumber in range(1000): if os.path.isfile( os.path.join( '/media/salozhor/42A074B5A074B0D1/CurseV2/learn', str(digit) + str(fileNumber) + '.png')): image = img(digit, fileNumber, img.LEARN) image.open() learning.append(image)
def read_rgb(nomf): """ Donat un nom de fitxer corresponent a una imatge RGB la llegeix i torna la imatge corresponent """ image = Image.open(nomf) pix = image.load() X = image.size[0] Y = image.size[1] data = [[pix[x, y] for x in range(X)] for y in range(Y)] return img.img(data, 'RGB')
def read_bn(nomf): """ Donat un nom d'arxiu corresponent a una imatge en blanc i negre, retorna la matriu d'imatge. Cada pixel serà 0 o 255. """ image = Image.open(nomf).convert('1') pix = image.load() X = image.size[0] Y = image.size[1] data = [[pix[x, y] for x in range(X)] for y in range(Y)] return img.img(data, '1')
def resize_img(self, filename): surface = pygame.image.load(filename).convert() orig_width = float(surface.get_width()) orig_height = float(surface.get_height()) # figure out scale scale_width = 1 + ((1280 - orig_width) / orig_width) scale_height = 1 + ((720 - orig_height) / orig_height) offset_x = 0 offset_y = 0 if scale_height > scale_width: surface = pygame.transform.scale(surface, (int(orig_width * scale_height), int(orig_height * scale_height))) offset_x = int(((orig_width * scale_height) - 1280) / 2) else: surface = pygame.transform.scale(surface, (int(orig_width * scale_width), int(orig_height * scale_width))) offset_y = int(((orig_height * scale_width) - 720) / 2) i = img.img(offset_x, offset_y, surface) self.queue.put(i)
def main(): #creacion de objetos para el programa bg = background.background(settings.pantalla,"02.png",alpha = True, posicion = settings.screen_center) barra = img.img(settings.pantalla,"001.png",posicion=settings.screen_center) #control de los textos l0 = text.text(settings.pantalla,color = (255,255,255),nombre = "COOPBL.ttf",tamano = settings.text_tamano_1,posicion = (40,405),linea = u"Voz que parece familiar") l1 = text.text_anim_01(settings.pantalla,nombre = "ARLRDBD.ttf",tamano = settings.text_tamano_1,velocidad = settings.text_speed_1,color = (255,255,255), posicion = (25,455), linea = u"Marcelo Salas!") l2 = text.text_anim_01(settings.pantalla,nombre = "ARLRDBD.ttf",tamano = settings.text_tamano_1,velocidad = settings.text_speed_1,color = (255,255,255), posicion = (25,495), linea = u"Activaste mi carta trampa!") l3 = text.text_anim_01(settings.pantalla,nombre = "ARLRDBD.ttf",tamano = settings.text_tamano_1,velocidad = settings.text_speed_1,color = (255,255,255), posicion = (25,535), linea = "") lista = [l0,l1,l2,l3] parrafo = text.group_text(lista) #marcelo marcelo = sprites.personaje(settings.pantalla,posicion = (-300,450)) marcelo.add("marcelo.png") marcelo.add("marcelo01.png") x2 = pygame.transform.scale2x(marcelo.imagenes[0]) marcelo.imagenes[0] = x2 x3 = pygame.transform.scale2x(marcelo.imagenes[1]) marcelo.imagenes[1] = x3 marcelo.current(1) marcelo.anim_01((150,450),180) #marmota marmota = sprites.personaje(settings.pantalla,posicion = (1000,450)) marmota.add("marmota.png") marmota.add("marmota01.png") bgmusic = bgm.bgm("004.mp3") running = True #acciones de uso unico bgmusic.play() #bucle principal while running: #variables que se comprueban cada bucle #lista de los eventos que se ejecutaron for evento in pygame.event.get(): if evento.type == pygame.KEYDOWN: if evento.key == pygame.K_z: marmota.end_anim_01() marcelo.end_anim_01() if not(parrafo.renderizado): for linea in lista: linea.velocidad = 5000 if parrafo.renderizado: parrafo.contador += 1 if evento.type == pygame.KEYUP: if evento.key == pygame.K_z: for linea in lista: linea.velocidad = settings.text_speed_1 if evento.type == pygame.QUIT: running = False #manejo de textos if parrafo.renderizado and parrafo.contador == 2: parrafo.void() marcelo.anim_01((150,450),180) marcelo.current(0) marmota.current(1) #modificamos los textos l0.line(u"Marcelo") l1.line(u"No veo ni mierdas, podrías prender la luz?") if parrafo.renderizado and parrafo.contador == 4: parrafo.void() marcelo.current(1) marmota.current(0) #modificamos textos l0.line(u"Voz que parece familiar") bg = background.background(settings.pantalla,"03.jpg",alpha = False, posicion = settings.screen_center) l1.line(u"En este lugar no hay luz, solo hay Divinas Comedias! ") if parrafo.renderizado and parrafo.contador == 6: parrafo.void() marcelo.current(0) marmota.current(1) #modificamos textos l0.line(u"Marcelo") l1.line(u"Quien eres?") if parrafo.renderizado and parrafo.contador == 8: parrafo.void() marmota.anim_01((600,450),320) marmota.current(0) marcelo.current(1) #modificamos textos l0.line(u"Jesucristo") l1.line(u"Creías que Jesucristo era una buena persona?") l2.line(u"Jesucristo es de la Policía de Investigaciones!") l3.line(u"Cagaste culiao!") if parrafo.renderizado and parrafo.contador == 10: parrafo.void() #modificamos textos l0.line(u"Jesucristo") l1.line(u"Soy de la PDI! Quedaste arrestado por ") l2.line(u"contrabando y compra de transgénicos ") l3.line(u"ilegales!") if parrafo.renderizado and parrafo.contador == 12: parrafo.void() marcelo.current(0) marmota.current(1) #modificamos textos l0.line(u"Marcelo") l1.line(u"NOOOOOOOOOOOOOO ") if parrafo.renderizado and parrafo.contador == 14: parrafo.void() marmota.current(0) marcelo.current(1) #modificamos textos l0.line(u"Jesucristo") l1.line(u"Ajkajakjak y el weon se la cree ajajkakjakjk ") l2.line(u"Solo te tendí una trampa para transformarte ") l3.line(u"en Dante Allighieri ") if parrafo.renderizado and parrafo.contador == 16: parrafo.void() marcelo.current(0) marmota.current(1) #modificamos textos l0.line(u"Marcelo") l1.line(u"Ah, de pana igual") if parrafo.renderizado and parrafo.contador == 18: parrafo.void() marcelo.current(1) marmota.current(0) #modificamos textos l0.line(u"Jesucristo") l1.line(u"Si, ser Allighieri es entrete") #paso a la siguiente pantalla if parrafo.contador == 20: running = False s5.main() #actualizacion de objetos en pantalla bg.update() marcelo.update() marmota.update() barra.update() parrafo.update() if not(running): bgmusic.stop() #actualizamos la pantalla if running: pygame.display.flip() settings.reloj.tick(60)
def draw(self, choose_screen): clear((255,255,255),choose_screen) #self.pic_face = img.img((300,600),(90,0),"boyheads2.jpeg") #self.pic_face.draw(choose_screen) self.pic_hair = img.img(self.hair_list[self.hair][1],self.hair_list[self.hair][2],self.hair_list[self.hair][0]) self.pic_hair.draw(choose_screen) self.pic_mouth = img.img((100,80),(200,300),self.mouth_list[self.mouth]) self.pic_mouth.draw(choose_screen) self.pic_nose = img.img((60,50),(220,240),self.nose_list[self.nose]) self.pic_nose.draw(choose_screen) self.pic_eyes = img.img((140,50),(180,170),self.eyes_list[self.eye]) self.pic_eyes.draw(choose_screen) next1 = img.img((50,50),(420,70),"next.png") next1.draw(choose_screen) pre1 = img.img((50,50),(40,70),"pre.png") pre1.draw(choose_screen) next2 = img.img((50,50),(420,160),"next.png") next2.draw(choose_screen) pre2 = img.img((50,50),(40,160),"pre.png") pre2.draw(choose_screen) next3 = img.img((50,50),(420,220),"next.png") next3.draw(choose_screen) pre3 = img.img((50,50),(40,220),"pre.png") pre3.draw(choose_screen) next4 = img.img((50,50),(420,320),"next.png") next4.draw(choose_screen) pre4 = img.img((50,50),(40,320),"pre.png") pre4.draw(choose_screen) f = buttons.button((170,65),(325,435),(255,151,153)) f.draw(choose_screen) g = label.Label((333,440),(70,70),(232,23,61), "None" , 45, "Play Again") g.draw(choose_screen) f2 = buttons.button((170,65),(0,435),(255,151,153)) f2.draw(choose_screen) g2 = label.Label((10,440),(70,70),(232,23,61), "None" , 45, "Play game") g2.draw(choose_screen) pygame.display.flip()
def main(): #creacion de objetos para el programa bg = background.background(settings.pantalla, "01.png", alpha=True, posicion=settings.screen_center) barra = img.img(settings.pantalla, "001.png", posicion=settings.screen_center) #control de los textos l0 = text.text(settings.pantalla, color=(255, 255, 255), nombre="COOPBL.ttf", tamano=settings.text_tamano_1, posicion=(40, 405), linea=u"Marcelo") l1 = text.text_anim_01(settings.pantalla, nombre="ARLRDBD.ttf", tamano=settings.text_tamano_1, velocidad=settings.text_speed_1, color=(255, 255, 255), posicion=(25, 455), linea=u"Puta, y ahora como chucha voy a permutar ") l2 = text.text_anim_01(settings.pantalla, nombre="ARLRDBD.ttf", tamano=settings.text_tamano_1, velocidad=settings.text_speed_1, color=(255, 255, 255), posicion=(25, 495), linea=u"transgénicos...") l3 = text.text_anim_01(settings.pantalla, nombre="ARLRDBD.ttf", tamano=settings.text_tamano_1, velocidad=settings.text_speed_1, color=(255, 255, 255), posicion=(25, 535), linea="") lista = [l1, l2, l3] #marcelo marcelo = sprites.personaje(settings.pantalla, posicion=(-300, 450)) marcelo.add("marcelo.png") marcelo.add("marcelo01.png") x2 = pygame.transform.scale2x(marcelo.imagenes[0]) marcelo.imagenes[0] = x2 x3 = pygame.transform.scale2x(marcelo.imagenes[1]) marcelo.imagenes[1] = x3 marcelo.current(0) marcelo.anim_01((150, 450), 180) #marmota marmota = sprites.personaje(settings.pantalla, posicion=(1000, 450)) marmota.add("marmota.png") marmota.add("marmota01.png") #utiles indicador = 0 mouse = cursor.cursor() bgmusic = bgm.bgm("003.mp3") running = True #acciones de uso unico bgmusic.play(inicio=2.0) #bucle principal while running: #variables que se comprueban cada bucle #lista de los eventos que se ejecutaron for evento in pygame.event.get(): if evento.type == pygame.KEYDOWN: if evento.key == pygame.K_z: marcelo.end_anim_01() marmota.end_anim_01() if not (l3.renderizado): for linea in lista: linea.velocidad = 5000 else: indicador += 1 if evento.type == pygame.KEYUP: if evento.key == pygame.K_z: for linea in lista: if indicador == 16: break linea.velocidad = settings.text_speed_1 if evento.type == pygame.QUIT: running = False #manejo de textos if indicador == 1: indicador += 1 marcelo.current(1) marmota.current(0) #modificamos textos l0.line(u"Voz Sexona") lista[0].void_line( u"Solo tienes que viajar hacia el mar Atlántico") lista[1].void_line("") lista[2].void_line("") if indicador == 3: indicador += 1 marcelo.current(0) marmota.current(1) #modificamos textos l0.line(u"Marcelo") lista[0].void_line(u"Ohh! Pero que sorpresa!") lista[1].void_line("") lista[2].void_line("") if indicador == 5: indicador += 1 marmota.anim_01((600, 450), 180) #modificamos los textos l0.line(u"Marcelo") lista[0].void_line( u"Es una marmota sexona índica magnética leedora ") lista[1].void_line(u"de mentes transversales impulsadas hacia el ") lista[2].void_line(u"infinito y lo desconocido!") if indicador == 7: indicador += 1 marcelo.current(1) marmota.current(0) #modificamos los textos l0.line(u"Marmota Sexona") lista[0].void_line(u"No tienes porque sorpenderte hijo mio") lista[1].void() lista[2].void() if indicador == 9: indicador += 1 marcelo.current(0) marmota.current(1) #modificamos los textos l0.line(u"Marcelo") lista[0].void_line(u"Dame una buena razón para no sorpenderme") lista[1].void() lista[2].void() if indicador == 11: indicador += 1 marcelo.current(1) marmota.current(0) #modificamos los textos l0.line(u"Jesucristo") lista[0].void_line( u"Lo que pasa es que soy Jesucristo, pero se me") lista[1].void_line(u"perdió mi gorro y tengo que ir a buscarlo") lista[2].void_line(u"") if indicador == 13: indicador += 1 marmota.anim_01((1000, -200), 60) #modificamos los textos l0.line(u"Jesucristo") lista[0].void_line(u"así que chaoo chaoo nos vemos, no olviden") lista[1].void_line( u"rendirme culto y subscribirse a la iglesia católica,") lista[2].void_line(u"soy Jesucristo y te deseo buenas noches.") if indicador == 15: indicador += 1 marcelo.current(0) marmota.current(1) #modificamos textos l0.line(u"Marcelo") lista[0].velocidad = 2 lista[0].void_line(u". . .") if lista[0].renderizado: lista[0].velocidad = settings.text_speed_1 lista[1].void() lista[2].void() #termino de la pantalla if indicador == 17: running = False s3.main() #actualizacion de objetos en pantalla bg.update() mouse.update() marcelo.update() marmota.update() barra.update() l0.update() text.texto_lista_update(lista) if not (running): bgmusic.stop() #actualizamos la pantalla if running: pygame.display.flip() settings.reloj.tick(60)
def img_get(): url = db.condition_select('img_locate', 'where live = 0') for li in url: img.img(li[1], li[0], li[3])
def run(choose_screen, boolean): if (boolean): man = male.male() man.draw(choose_screen) next1 = img.img((50,50),(420,70),"next.png") next1.draw(choose_screen) pre1 = img.img((50,50),(40,70),"pre.png") pre1.draw(choose_screen) next2 = img.img((50,50),(420,160),"next.png") next2.draw(choose_screen) pre2 = img.img((50,50),(40,160),"pre.png") pre2.draw(choose_screen) next3 = img.img((50,50),(420,220),"next.png") next3.draw(choose_screen) pre3 = img.img((50,50),(40,220),"pre.png") pre3.draw(choose_screen) next4 = img.img((50,50),(420,320),"next.png") next4.draw(choose_screen) pre4 = img.img((50,50),(40,320),"pre.png") pre4.draw(choose_screen) f = buttons.button((170,65),(325,435),(255,151,153)) f.draw(choose_screen) g = label.Label((333,440),(70,70),(232,23,61), "None" , 45, "Play Again") g.draw(choose_screen) f2 = buttons.button((170,65),(0,435),(255,151,153)) f2.draw(choose_screen) g2 = label.Label((10,440),(70,70),(232,23,61), "None" , 45, "Play game") g2.draw(choose_screen) pygame.display.flip() else: man = female.female() man.draw(choose_screen) next1 = img.img((50,50),(420,70),"next.png") next1.draw(choose_screen) pre1 = img.img((50,50),(40,70),"pre.png") pre1.draw(choose_screen) next2 = img.img((50,50),(420,160),"next.png") next2.draw(choose_screen) pre2 = img.img((50,50),(40,160),"pre.png") pre2.draw(choose_screen) next3 = img.img((50,50),(420,220),"next.png") next3.draw(choose_screen) pre3 = img.img((50,50),(40,220),"pre.png") pre3.draw(choose_screen) next4 = img.img((50,50),(420,320),"next.png") next4.draw(choose_screen) pre4 = img.img((50,50),(40,320),"pre.png") pre4.draw(choose_screen) f = buttons.button((170,65),(325,435),(255,151,153)) f.draw(choose_screen) g = label.Label((333,440),(70,70),(232,23,61), "None" , 45, "Play Again") g.draw(choose_screen) f2 = buttons.button((170,65),(0,435),(255,151,153)) f2.draw(choose_screen) g2 = label.Label((10,440),(70,70),(232,23,61), "None" , 45, "Play game") g2.draw(choose_screen) pygame.display.flip() while True: ev = pygame.event.poll() #CODE... pygame.display.flip() if ev.type == pygame.MOUSEBUTTONDOWN: x, y = ev.pos if f.rec.collidepoint(x,y): clear((255,255,255), choose_screen) main_game.run(choose_screen) if f2.rec.collidepoint(x,y): clear((255,255,255), choose_screen) game.run(choose_screen, man) if next1.pic.collidepoint(x,y): man.change_hair(1) man.draw(choose_screen) if pre1.pic.collidepoint(x,y): man.change_hair(-1) man.draw(choose_screen) if next2.pic.collidepoint(x,y): man.change_eye(1) man.draw(choose_screen) if pre2.pic.collidepoint(x,y): man.change_eye(-1) man.draw(choose_screen) if next3.pic.collidepoint(x,y): man.change_nose(1) man.draw(choose_screen) if pre3.pic.collidepoint(x,y): man.change_nose(-1) man.draw(choose_screen) if next4.pic.collidepoint(x,y): man.change_mouth(1) man.draw(choose_screen) if pre4.pic.collidepoint(x,y): man.change_mouth(-1) man.draw(choose_screen)