示例#1
0
文件: main.py 项目: kwarwp/jean
class Museu:
    CUR = None
    def __init__(self):
        self.nome = ""
        [PAREDES.update({"{}_SUL".format(sala[:2]): imagem}) for sala, imagem in PAREDES.items() if "OESTE" in sala]
        museu = {"sala_{}".format(indice): Sala(
            *[PAREDES["C{}_{}".format(indice, rumo)] for rumo in RUMOS], nome="sala_{}".format(indice))
        for indice in range(10)}
        mapa = [[museu["sala_{}".format((j+i) %10)] for i in range(4)] for j in range(0, 16, 4)]
        Labirinto.m(mapa)
        self.corrente = entrada = museu["sala_0"].norte
        topo = "Este é o código inicial para se construir a primeira cena. Cria-se uma referência à uma imagem na internet"+\
        "e atribui-se à Cena"
        Cena.vai = self.vai

        self.cod = Codigo(cena=entrada, topo=topo, codigo=CODE_0, style=dict(width=400, height="250px", left=500, top=100))
        entrada.vai()
        Museu.CUR = self
    def instrumenta(self, cena):
        self.cod.entra(cena)
        VAI(self)
        # Cena.vai = VAI
    def vai(self):
        Museu.CUR.instrumenta(self)
        Cena.vai = VAI
        self.vai()
示例#2
0
 def __init__(self,
              codigo="",
              topo="",
              cena=INVENTARIO,
              img="",
              vai=None,
              style=NS):
     style.update({"height": "550px"})
     Code.__init__(self,
                   codigo=codigo,
                   topo=topo,
                   cena=cena,
                   img=img,
                   vai=vai,
                   style=style)
     a = html.A("×",
                href="#",
                style=dict(position="absolute",
                           top="0px",
                           right="10px",
                           fontSize="30px",
                           fontWeight="bold"))
     a.onclick = self._close
     self.elt <= a
     self._close()
     self._area.style.overflow = "scroll"
     self._area.style.height = "400px"
     self.elt.style.maxHeight = "550px"
示例#3
0
 def __init__(self, jogo=None, pagina=None):
     self.livro = Cena(LIVRO)
     self.texto_da_pagina_do_livro = Codigo(codigo="",
                                            topo=TEXTO,
                                            style=dict(left=440,
                                                       top=20,
                                                       width=380))
     self.texto_da_pagina_do_livro.entra(self.livro)
     self.livro.vai()
示例#4
0
def natureza():
    fundo = Cena(FUNDO)
    colmeia = Elemento(COLMEIA,
                       tit="colmeia",
                       drag=False,
                       x=50,
                       y=140,
                       w=300,
                       h=500,
                       drop="abelha",
                       cena=fundo)

    def reposiciona_abelha(sid, x, y):
        sid.style.left = x
        sid.style.top = y

    abelha = Elemento(ABELHA,
                      tit="abelha",
                      drag=True,
                      x=610,
                      y=140,
                      w=80,
                      h=90,
                      drop="",
                      cena=fundo)

    MENSAGENS = [fundo, "tendi", "tamu junto"],
    STYLE = dict(width=400, heigth="250px", left=500, top=100)
    [Codigo(cena=a, topo=b, codigo=c, style=STYLE) for a, b, c in MENSAGENS]

    colmeia.doit_drop = reposiciona_abelha
    fundo.vai()
示例#5
0
 def __init__(self,
              codigo="",
              topo="",
              cena=INVENTARIO,
              img="",
              vai=None,
              style=NS):
     Code.__init__(self,
                   codigo=codigo,
                   topo=topo,
                   cena=cena,
                   img=img,
                   vai=vai,
                   style=style)
     a = html.A("×",
                href="#",
                style=dict(position="absolute",
                           top="0px",
                           right="10px",
                           fontSize="30px",
                           fontWeight="bold"))
     a.onclick = self._close
     self.elt <= a
示例#6
0
文件: main.py 项目: kwarwp/ada
    def __cria(self):
        def _vai_tutorial():
            try:
                cti().vai()
            except:
                from amanda.main import CenaTutorialInterativo as cti
                cti().vai()

        volta_tut = Cena(vai=_vai_tutorial)
        self.cena_t = Cena(cretaceo_l, volta_tut, volta_tut, volta_tut)
        codigo = Codigo(cena=self.cena_t,
                        topo=TOPO,
                        codigo=COD,
                        style=dict(left=300))
        return self
示例#7
0
文件: main.py 项目: kwarwp/ada
def qualquernome():

    cena1 = Cena(img=entrada)
    elemento1 = Codigo(img=pixacao,
                       style=dict(
                           left=0,
                           top=95,
                           height='505px',
                           width=250,
                           bottom=20,
                       ))
    elemento2 = Elemento(img=portao,
                         style=dict(left=215,
                                    top=0,
                                    height='600px',
                                    width=575,
                                    bottom=0))
    lago = Cena(img=lagodastartarugas)
    elemento1.entra(cena1)
    elemento2.entra(cena1)
    txtcena1 = Texto(cena1, "O portao esta trancado")
    elemento2.vai = txtcena1.vai
    elemento1.vai = lago.vai
    cena1.vai()
示例#8
0
文件: main.py 项目: kwarwp/vera
 def __init__(self):
     super().__init__(CENA_PARQUE)
     self.coisas = {}
     parque = self  # Cena(CENA_PARQUE)
     INVENTARIO.inicia()
     participante = input("diga seu nome")
     score(carta=participante, _level=0)
     #INVENTARIO.elt.html = "PARQUE"
     nome = Codigo(codigo="", topo="PARQUE", style=dict(left=250, top=220, width=100, height="60px"))
     nome.entra(parque)
     Crianca(parque, tit="gosto de bicho", x=60, y=300, gosta="coelho passarinho")
     Crianca(parque, tit="gosto de esportes", x=150, y=300, gosta="bola peteca")
     Crianca(parque, tit="gosto de passear", x=270, y=300, gosta="") 
     Crianca(parque, tit="gosto de frutas", x=400, y=300, gosta="maçã laranja") 
     Crianca(parque, tit="gosto de calçado", x=480, y=300, gosta="tenis galocha")
     Fruta(parque, x=30, y=90)
     Fruta(parque, tit="laranja", imagem=LARANJA, x=330, y=60)
     Esportes(parque, x=100, y=150)
     Esportes(parque, tit="peteca", imagem=PETECA, x=500, y=35) 
     Bicho(parque, x=150, y=80)
     Bicho(parque, tit="passarinho", imagem=PASSARINHO, x=400, y=60)
     Calcado(parque, x=450, y=100) 
     Calcado(parque, tit="galocha", imagem=GALOCHA, x=200, y=50) 
     parque.vai()
示例#9
0
    def __init__(self):
        self.cavernatesouro = cavernatesouro = Cena(CAVERNATESOURO)
        codigo = Codigo("", "", cena=cavernatesouro, style=dict(x=400, y=300))
        tesouro = Elemento(TESOURO, x=245, y=200, w=700, h=400)
        tesouro.vai = lambda *_: tesouro.entra(cavernatesouro)

        def troca(*_):
            cavernatesouro.meio = tesouro

        codigo = Texto(
            cavernatesouro,
            "Opa!! Você achou o tesouro!!",
            "Mas, cuidado: ao decidir pegar o tesouro, seu amigo não poderá ser salvo",
            style=dict(x=400, y=300),
            foi=troca)
        cavernatesouro.meio = codigo
示例#10
0
def teste():
    fundo = Cena(FUNDO)
    background = Elemento(BACKG, tit = "background", drag= False,
        x = 0, y = 0, w = 800 , h = 600, drop= "Mova-me",
        cena= fundo)
    def reposiciona_figura(sid, x, y):
        sid.style.left = x
        sid.style.top = y
        
    seta = Elemento(SETA, tit = "Mova-me", drag=True,
        x = 310, y = 160, w = 80, h = 90, drop="",
        cena=fundo)
        
    MENSAGENS=[fundo, "<p><center><strong><big>WELCOME TO DRAG and DROP!<big></center><br><center><small> Mexe a seta ai, Moçe!!</small></center></p><br><center><small>Vamos para o que interessa: Como implementar?</small></center><br> ",  """


VAR1 = 'https://i.imgur.com/vb4zrA0.jpg'
VAR2 = 'https://trabalhodigitalinfo.files.wordpress.com/2016/01/seta-vermelha-2png.png'
VAR3 = "https://imagens.simplo7.net/static/2497/sku/thumb_tricoline-100-algodao-lisa-tricoline-100-algodao-lisa-branca-1474467553683.jpg"

def movimento():
    camada1 = Cena(VAR3)
    camada2 = Elemento(VAR1, tit = "segunda camada", drag= False,
        x = 0, y = 0, w = 800 , h = 600, drop= "Mova-me",
        cena= camada1)
        
    def reposiciona_figura(sid, x, y):
        sid.style.left = x
        sid.style.top = y
        
    movel = Elemento(VAR2, tit = "Mova-me", drag=True,
        x = 310, y = 160, w = 80, h = 90, drop="",
    cena=camada1)
    camada2.doit_drop = reposiciona_figura
    camada1.vai()

movimento() """],
    STYLE = dict(width=700,heigth="500px",left=500,top=100)
    c=[Codigo(cena = a,topo = b ,codigo= c, style= STYLE) for a, b , c in MENSAGENS]
    Codigo=c[0]
    Codigo._area.style.overflow="scroll"
    Codigo._area.style.height="250px"
    
    background.doit_drop = reposiciona_figura
    fundo.vai()
示例#11
0
文件: main.py 项目: kwarwp/jean
    def __init__(self):
        C_SUL = C1_SUL
        C2_SUL = C1_LESTE
        sala_0 = Sala(R_NORTE, R_LESTE, R_SUL, R_OESTE)
        sala_1 = Sala(C1_NORTE, C1_LESTE, C_SUL, C1_OESTE)
        sala_2 = Sala(C2_NORTE, C2_LESTE, C2_SUL, C2_OESTE)
        sala_3 = Sala(C3_NORTE, C3_LESTE, C3_SUL, C3_OESTE)
        sala_4 = Sala(C4_NORTE, C4_LESTE, C4_SUL, C4_OESTE)
        sala_5 = Sala(C5_NORTE, C5_LESTE, C5_SUL, C5_OESTE)
        sala_6 = Sala(C6_NORTE, C6_LESTE, C6_SUL, C6_OESTE)
        sala_7 = Sala(C7_NORTE, C7_LESTE, C7_SUL, C7_OESTE)
        sala_8 = Sala(C8_NORTE, C8_LESTE, C8_SUL, C8_OESTE)
        sala_9 = Sala(C9_NORTE, C9_LESTE, C9_SUL, C9_OESTE)
        sala_A = Sala(CA_NORTE, CA_LESTE, CA_SUL, CA_OESTE)
        sala_B = Sala(CB_NORTE, CB_LESTE, CB_SUL, CB_OESTE)
        sala_C = Sala(CC_NORTE, CC_LESTE, CC_SUL, CC_OESTE)
        sala_D = Sala(CD_NORTE, CD_LESTE, CD_SUL, CD_OESTE)
        sala_E = Sala(CE_NORTE, CE_LESTE, CE_SUL, CE_OESTE)
        Labirinto(sala_0, sala_1, sala_2, sala_3, sala_4)
        Labirinto(sala_4, sala_5, sala_6, sala_7, sala_8)
        Labirinto(sala_8, sala_9, sala_A, sala_B, sala_C)
        Labirinto(sala_C, sala_D, sala_E, sala_0, sala_1)
        sala_0.norte.vai()

        MENSAGENS = [
            [
                sala_0.norte,
                "primeiramente para usar a função labirinto do vitollino precisa ter definido as salas,"
                "depois se usa a função labirinto para 5 salas, ex: labirinto(salaA, sala B, sala C, salaD, sala E),"
                "sempre conectando uma sala a outra, exemplo: labirinto(sala E, salaF,salaG,salaH,salaI)",
                """   
       ficando assim: Labirinto(sala A, sala B, sala C, sala D, sala E) 
"""
            ],
            [sala_1.norte, "Hello", "if True:print('ooi')"],
            [sala_1.leste, "bonju", "if True:print(':)')"],
            [sala_1.oeste, "Buenos dias", "if True:print('oi')"],
            [sala_1.sul, "como vai?", "if True:print('oi')"],
            [sala_2.norte, "Bora lá?", "if True:print('oi')"],
        ]
        STYLE = dict(width=500, heigth="3000px", left=500, top=100)
        [
            Codigo(cena=a, topo=b, codigo=c, style=STYLE)
            for a, b, c in MENSAGENS
        ]
示例#12
0
文件: main.py 项目: kwarwp/jean
    def __init__(self):
        C_SUL = C1_SUL
        C2_SUL = C1_LESTE
        C6_SUL = C6_OESTE
        sala_0 = Sala(R_NORTE, R_LESTE, R_OESTE)
        sala_1 = Sala(C1_NORTE, C1_LESTE, C_SUL, C1_OESTE)
        sala_2 = Sala(C2_NORTE, C2_LESTE, C2_SUL, C2_OESTE)
        sala_3 = Sala(C3_NORTE, C3_LESTE, C3_SUL, C3_OESTE)
        sala_4 = Sala(C4_NORTE, C4_LESTE, C4_SUL, C4_OESTE)
        sala_5 = Sala(C5_NORTE, C5_LESTE, C5_SUL, C5_OESTE)
        sala_6 = Sala(C6_NORTE, C6_LESTE, C6_SUL, C6_OESTE)
        sala_7 = Sala(C7_NORTE, C7_LESTE, C7_SUL, C7_OESTE)
        sala_9 = Sala(C9_NORTE, C9_LESTE, C9_OESTE, C9_SUL)
        sala_A = Sala(CA_NORTE, CA_LESTE, CA_SUL, CA_OESTE)
        sala_B = Sala(CB_NORTE, CB_LESTE, CB_SUL, CB_OESTE)
        sala_C = Sala(CC_NORTE, CC_LESTE, CC_OESTE)
        sala_D = Sala(CD_NORTE, CD_LESTE, CD_SUL, CD_OESTE)
        # TEM DOIS SUL DA C9 QUE NA VERDADE ERA PARA SER C8
        sala_0.norte.meio = sala_9.norte
        sala_0.leste.meio = sala_1.norte
        sala_1.oeste.meio = sala_2.norte
        sala_2.norte.meio = sala_A.norte
        sala_A.norte.meio = sala_3.norte
        sala_A.sul.meio = sala_1.leste
        sala_3.norte.meio = sala_4.norte
        sala_3.sul.meio = sala_A.sul
        sala_4.oeste.meio = sala_5.norte
        sala_4.sul.meio = sala_3.sul
        sala_5.leste.meio = sala_6.norte
        sala_5.oeste.meio = sala_C.norte
        sala_5.sul.meio = sala_4.leste
        sala_C.norte.meio = sala_D.norte
        sala_D.norte.meio = sala_7.norte
        sala_6.leste.meio = sala_B.norte
        sala_B.sul.meio = sala_6.oeste
        sala_7.norte.meio = sala_9.norte
        sala_9.leste.meio = sala_7.sul
        sala_7.leste.meio = sala_D.sul

        ex1 = Codigo(topo="oi",
                     style=dict(left=100, top=100, width=100, heigth="100px"))
        ex.entra(sala_0)

        #sala_0.norte.vai = sala_1.norte.vai()
        sala_0.norte.vai()
示例#13
0
文件: main.py 项目: kwarwp/jean
    def __init__(self):
        C_SUL = C1_SUL
        C2_SUL = C1_LESTE
        sala_0 = Sala(R_NORTE, R_LESTE, R_SUL, R_OESTE)
        sala_1 = Sala(C1_NORTE, C1_LESTE, C_SUL, C1_OESTE)
        sala_2 = Sala(C2_NORTE, C2_LESTE, C2_SUL, C2_OESTE)
        sala_3 = Sala(C3_NORTE, C3_LESTE, C3_SUL, C3_OESTE)
        sala_4 = Sala(C4_NORTE, C4_LESTE, C4_SUL, C4_OESTE)
        sala_5 = Sala(C5_NORTE, C5_LESTE, C5_SUL, C5_OESTE)
        sala_6 = Sala(C6_NORTE, C6_LESTE, C6_SUL, C6_OESTE)
        sala_7 = Sala(C7_NORTE, C7_LESTE, C7_SUL, C7_OESTE)
        sala_8 = Sala(C8_NORTE, C8_LESTE, C8_SUL, C8_OESTE)
        sala_9 = Sala(C9_NORTE, C9_LESTE, C9_SUL, C9_OESTE)
        sala_A = Sala(CA_NORTE, CA_LESTE, CA_SUL, CA_OESTE)
        sala_B = Sala(CB_NORTE, CB_LESTE, CB_SUL, CB_OESTE)
        sala_C = Sala(CC_NORTE, CC_LESTE, CC_SUL, CC_OESTE)
        sala_D = Sala(CD_NORTE, CD_LESTE, CD_SUL, CD_OESTE)
        sala_E = Sala(CE_NORTE, CE_LESTE, CE_SUL, CE_OESTE)
        # TEM DOIS SUL DA C9 QUE NA VERDADE ERA PARA SER C8
        sala_0.norte.meio = sala_9.leste
        sala_0.leste.meio = sala_1.norte
        sala_1.oeste.meio = sala_2.norte
        sala_1.sul.meio = sala_0.oeste
        sala_2.norte.meio = sala_A.norte
        sala_A.norte.meio = sala_3.norte
        sala_A.sul.meio = sala_1.leste
        sala_3.norte.meio = sala_4.norte
        sala_3.sul.meio = sala_A.sul
        sala_4.oeste.meio = sala_5.norte
        sala_4.sul.meio = sala_3.sul
        sala_5.leste.meio = sala_6.norte
        sala_5.oeste.meio = sala_C.norte
        sala_5.sul.meio = sala_4.leste
        sala_6.sul.meio = sala_5.oeste
        sala_C.norte.meio = sala_D.norte
        sala_C.sul.meio = sala_5.leste
        sala_D.norte.meio = sala_7.norte
        sala_D.sul.meio = sala_C.sul
        sala_D.norte.meio = sala_E.norte
        sala_6.leste.meio = sala_B.norte
        sala_B.sul.meio = sala_6.oeste
        sala_7.leste.meio = sala_8.norte
        sala_7.sul.meio = sala_E.leste
        sala_8.leste.meio = sala_9.norte
        sala_8.sul.meio = sala_7.oeste
        sala_9.sul.meio = sala_8.sul
        sala_9.oeste.meio = sala_0.sul
        sala_9.sul.meio = sala_8.oeste
        sala_E.oeste.meio = sala_7.norte
        sala_E.sul.meio = sala_D.sul

        #sala_0.norte.vai = sala_1.norte.vai()
        sala_0.norte.vai()
        # cod = Codigo(cena=sala_0.norte ,topo= "ola", codigo = "if True:print('oi')",style = dict(width=400,heigth="250px",left=500,top=100))
        # cod = Codigo(cena=sala_1.norte, topo = "hello",codigo = "if True:print('ooi')",style = dict(width=400,heigth="250px",left=500,top=100))
        # cod = Codigo(cena=sala_1.leste, topo = "Bonju",codigo = "if True:print('ooi')",style = dict(width=400,heigth="250px",left=500,top=100))
        # cod = Codigo(cena=sala_1.oeste, topo = "Buenos dias",codigo = "if True:print('ooi')",style = dict(width=400,heigth="250px",left=500,top=100))
        # cod =Codigo(cena=sala_1.sul, topo = "como vai?",codigo = "if True:print('ooi')",style = dict(width=400,heigth="250px",left=500,top=100))

        MENSAGENS = [
            [sala_0.norte, "tendi", "tamu junto"],
            [sala_1.norte, "Hello", "if True:print('ooi')"],
            [sala_1.leste, "bonju", "if True:print(':)')"],
            [sala_1.oeste, "Buenos dias", "if True:print('oi')"],
            [sala_1.sul, "como vai?", "if True:print('oi')"],
            [sala_2.norte, "Bora lá?", "if True:print('oi')"],
            [sala_2.leste, "vamos?", "if True:print('oi')"],
            [sala_2.oeste, "lest go", "if True:print('oi')"],
            [sala_2.sul, "vamonos", "if True:print('oi')"],
            [sala_3.norte, "como estas?", "if True:print('oi')"],
            [sala_3.leste, "e o dia?", "if True:print('oi')"],
            [sala_3.oeste, "ta calor?", "if True:print('oi')"],
            [sala_3.sul, "quanto graus está agora?", "if True:print('oi')"],
            [sala_4.norte, "hey", "if True:print('oi')"],
            [sala_4.leste, "parabéns", "if True:print('oi')"],
            [sala_4.oeste, "você chegou até aqui!", "if True:print('oi')"],
            [sala_4.sul, "tenha muito orgulho de vc", "if True:print('oi')"],
            [
                sala_5.norte, "temos que comemorara pequenas vitórias",
                "if True:print('oi')"
            ], [sala_5.leste, "está indo muito bem", "if True:print('oi')"],
            [
                sala_5.oeste, "tudo que fizer coloque amor",
                "if True:print('oi')"
            ], [sala_5.sul, "se ame", "if True:print('oi')"],
            [sala_6.norte, "se cuide", "if True:print('oi')"],
            [sala_6.leste, "hoje o dia esta lindo", "if True:print('oi')"],
            [
                sala_6.oeste, "deixe a chuva lavar a alma",
                "if True:print('oi')"
            ], [sala_6.sul, "hasta la vista", "if True:print('oi')"],
            [sala_7.norte, " you say goodbye", "if True:print('oi')"],
            [sala_7.leste, "and say Hello", "if True:print('oi')"],
            [
                sala_7.oeste,
                "Para inserir um Elemento à cena é preciso escolher uma imagem e  importar o Elemento do Vitollino. Em seguida, ajustar as dimensões da imagem e seu posicionamento. Por fim, dar o comando para o Elemento aparecer na sala desejada. Código:",
                """from _spy.vitollino.main import Elemento
pedra = Elemento(img=PEDRA, tit="Pedra", 
style=dict(left=40, top=380, width=200, height="150px"))
pedra.entra(sala_7.oeste)
pedra.vai 
"""
            ], [sala_7.sul, "vc é capaz", "if True:print('oi')"],
            [sala_8.norte, "don't worry", "if True:print('oi')"],
            [sala_8.leste, "vc é capaz", "if True:print('oi')"],
            [sala_8.oeste, " be free", "if True:print('oi')"],
            [sala_8.sul, "está quase acabando", "if True:print('oi')"],
            [
                sala_9.norte, "você esta vencendo seus medos",
                "if True:print('oi')"
            ], [sala_9.leste, "está se superando", "if True:print('oi')"],
            [sala_9.oeste, "respire", "if True:print('oi')"],
            [sala_9.sul, "comemore, pois vc venceu", "if True:print('oi')"],
            [sala_A.norte, "tudo vai bem", "if True:print('oi')"],
            [sala_A.leste, "não desista", "if True:print('oi')"],
            [sala_A.oeste, "não é tão complicado", "if True:print('oi')"],
            [sala_A.sul, "avai sim", "if True:print('oi')"],
            [sala_B.norte, "tudo vai bem", "if True:print('oi')"],
            [sala_B.leste, "não desista", "if True:print('oi')"],
            [sala_B.oeste, "não é tão complicado", "if True:print('oi')"],
            [sala_B.sul, "avai sim", "if True:print('oi')"],
            [sala_C.norte, "tudo vai bem", "if True:print('oi')"],
            [sala_C.leste, "não desista", "if True:print('oi')"],
            [sala_C.oeste, "não é tão complicado", "if True:print('oi')"],
            [sala_C.sul, "avai sim", "if True:print('oi')"],
            [sala_D.norte, "tudo vai bem", "if True:print('oi')"],
            [sala_D.leste, "não desista", "if True:print('oi')"],
            [sala_D.oeste, "não é tão complicado", "if True:print('oi')"],
            [sala_D.sul, "avai sim", "if True:print('oi')"],
            [sala_E.norte, "tudo vai bem", "if True:print('oi')"],
            [sala_E.leste, "não desista", "if True:print('oi')"],
            [sala_E.oeste, "não é tão complicado", "if True:print('oi')"],
            [sala_E.sul, "avai sim", "if True:print('oi')"]
        ]
        STYLE = dict(width=400, heigth="250px", left=500, top=100)
        [
            Codigo(cena=a, topo=b, codigo=c, style=STYLE)
            for a, b, c in MENSAGENS
        ]

        pedra = Elemento(img=PEDRA,
                         tit="Pedra",
                         style=dict(left=40,
                                    top=380,
                                    width=200,
                                    height="150px"))
        pedra.entra(sala_7.oeste)
        pedra.vai
示例#14
0
 def resposta(self, *_):
     self.codigo = c = Codigo("\n".join(self.results))
     c.entra(self.cena)
     c.x, c.y, c.w = 50, 50, 600
示例#15
0
    def __init__(self, img, **kwargs):
        super().__init__(img, **kwargs)
        outer = self
        style = self.elt.style
        self.position = self.x, self.y
        self.results = []
        self.codigo = c = Codigo("\n".join(self.results))
        c.x, c.y, c.w = -2000, 50, 600

        class Noop:
            def __init__(self):
                self.outer = outer

            def update_style(self, styler, new_style, delta=None):
                cur_style = dict(outer.style)
                '''
                        point = Point(outer.alvo.style.left, outer.alvo.style.top)
                        delta = delta if delta else Point(outer.alvo.style.width, outer.alvo.style.minHeight)
                        print("delta.x, delta.y", outer.elt.style.left, outer.elt.style.top, delta.x, delta.y)
                        cur_style.update(cursor=styler, left=point.x, top=point.y, width=delta.x, height=delta.y, **new_style)

                        '''
                cur_style.update(cursor=styler, **new_style)
                #cur_style["min-height"] = "{}px".format(delta.y)
                return cur_style

            def change(self, ev):
                pass

            def nextst(self, ev):
                ev.target.style = self.update_style("move", _PATTERN.BCROSS)
                outer.x, outer.y = outer.position
                outer.tit = "next move"
                #alert("next move")
                outer.current = outer.move
                outer.results.append(
                    Cursor.ELM_FORMAT.format(outer.x, outer.y, outer.w,
                                             outer.h))

            def mouse_over(self, ev):
                ev.target.style.cursor = "default"

            def mouse_down(self, ev):
                outer.ponto = Point(ev.x, ev.y)
                outer.cursor = outer.current
                pass

            def mouse_move(self, ev):
                pass

            def mouse_up(self, _):
                outer.cursor = outer.noop
                #st = self.outer.elt.style
                #width_, height_, left_, top_ = st.width, st.minHeight, st.left, st.top
                #self.outer.elt.title = CURSOR_ELEMENT.format(left_, top_, width_, height_)
                outer.tit = CURSOR_ELEMENT.format(outer.x, outer.y, outer.w,
                                                  outer.h)

        class Move(Noop):
            def mouse_move(self, ev):
                # delta = Point(int(alvo.style.left.rstrip("px")), int(alvo.style.top.rstrip("px"))) \
                delta = Point(outer.x, outer.y) + Point(ev.x,
                                                        ev.y) - outer.ponto

                outer.x, outer.y = delta
                outer.position = delta
                #outer.elt.left, outer.elt.top = delta
                outer.ponto = Point(ev.x, ev.y)

            def mouse_over(self, ev):
                ev.target.style.cursor = "move"

            def nextst(self, ev):
                #print("next resize")
                ev.target.style = self.update_style("grab", _PATTERN.BOKEH)
                outer.x, outer.y = outer.position
                outer.tit = "next resize"
                #alert("next resize")
                outer.current = outer.resize

        class Resize(Noop):
            def mouse_move(self, ev):
                #delta = Point(int(outer.elt.style.width.rstrip("px")), int(outer.elt.style.minHeight.rstrip("px"))) \
                #        + Point(ev.x, ev.y) - outer.ponto
                delta = Point(outer.w, outer.h) + Point(ev.x,
                                                        ev.y) - outer.ponto
                outer.w, outer.h = delta  #.px()
                # alvo.style = self.update_style("default", {}, delta)
                # outer.elt.style = self.update_style("default", PATTERN.BOKEH, delta)
                # print("mouse_move", alvo.style.minHeight, delta)
                outer.ponto = Point(ev.x, ev.y)

            def mouse_over(self, ev):
                ev.target.sutyle.cursor = "grab"

            def nextst(self, ev):
                #print("next noop")
                ev.target.style = self.update_style("default", _PATTERN.STARRY)
                outer.x, outer.y = outer.position
                #alert("next noop")
                outer.current = outer.noop

        def next_state(ev):
            # self.state.append(self.state.pop(0))
            #alert(ev.x, self.current)
            self.current.nextst(ev)

        def _mouse_down(ev):
            return self.cursor.mouse_down(ev)

        def _mouse_up(ev):
            return self.cursor.mouse_up(ev)

        def _mouse_move(ev):
            return self.cursor.mouse_move(ev)

        def _mouse_over(ev):
            return self.cursor.mouse_over(ev)

        def _strip_kind(dm):
            kinds = "px %".split()
            kind = [k for k in kinds if isinstance(dm, str) and (k in dm)]
            # dm = str(dm) if isinstance(dm, int) else dm if isinstance(dm, str) else "0"
            return int(dm.rstrip(kind[0])) if kind else int(dm) if dm else 0

        #self.noop, self.move, self.resize = self.state = [Noop(), Move(), Resize()]
        self.noop, self.move, self.resize = [Noop(), Move(), Resize()]
        self.cursor = self.noop
        self.current = self.move
        style = dict(**ISTYLE)
        dims = [self.y, self.h, self.x, self.w]
        #print("dim left, top = ", dims)
        #dims = [_strip_kind(dm) for dm in dims]
        top, height, left, width = dims
        left, top = left + width // 2 - 30, top + height // 2 - 30
        cstyle = CURSOR_STYLE
        cstyle = cstyle.format(width, height, height, left, top)
        style.update(**_PATTERN.STARRY)
        self.style = style
        #self.elt = html.DIV(Id="__cursor__", style=style, title="")
        #self.elt.ID, self.elt.style, self.elt.title = "__cursor__", style, ""

        #self.cena <= self.elt
        #self.cena.elt.html = ""
        #self.cena.elt <= self.elt
        #print("elt = ", self.elt.Id)
        self.elt.onclick = next_state
        self.elt.onmousedown = _mouse_down
        self.elt.onmouseup = _mouse_up
        self.elt.onmousemove = _mouse_move
        self.elt.onmouseover = _mouse_over
示例#16
0
文件: main.py 项目: kwarwp/jean
    def __init__(self):
        C_SUL = C1_SUL
        C2_SUL = C1_LESTE
        sala_0 = Sala(R_NORTE, R_LESTE, R_SUL, R_OESTE)
        sala_1 = Sala(C1_NORTE, C1_LESTE, C_SUL, C1_OESTE)
        sala_2 = Sala(C2_NORTE, C2_LESTE, C2_SUL, C2_OESTE)
        sala_3 = Sala(C3_NORTE, C3_LESTE, C3_SUL, C3_OESTE)
        sala_4 = Sala(C4_NORTE, C4_LESTE, C4_SUL, C4_OESTE)
        sala_5 = Sala(C5_NORTE, C5_LESTE, C5_SUL, C5_OESTE)
        sala_6 = Sala(C6_NORTE, C6_LESTE, C6_SUL, C6_OESTE)
        sala_7 = Sala(C7_NORTE, C7_LESTE, C7_SUL, C7_OESTE)
        sala_8 = Sala(C8_NORTE, C8_LESTE, C8_SUL, C8_OESTE)
        sala_9 = Sala(C9_NORTE, C9_LESTE, C9_SUL, C9_OESTE)
        sala_A = Sala(CA_NORTE, CA_LESTE, CA_SUL, CA_OESTE)
        sala_B = Sala(CB_NORTE, CB_LESTE, CB_SUL, CB_OESTE)
        sala_C = Sala(CC_NORTE, CC_LESTE, CC_SUL, CC_OESTE)
        sala_D = Sala(CD_NORTE, CD_LESTE, CD_SUL, CD_OESTE)
        sala_E = Sala(CE_NORTE, CE_LESTE, CE_SUL, CE_OESTE)
        # TEM DOIS SUL DA C9 QUE NA VERDADE ERA PARA SER C8
        sala_0.norte.meio = sala_9.leste
        sala_0.leste.meio = sala_1.norte
        sala_1.oeste.meio = sala_2.norte
        sala_1.sul.meio = sala_0.oeste
        sala_2.norte.meio = sala_A.norte
        sala_A.norte.meio = sala_3.norte
        sala_A.sul.meio = sala_1.leste
        sala_3.norte.meio = sala_4.norte
        sala_3.sul.meio = sala_A.sul
        sala_4.oeste.meio = sala_5.norte
        sala_4.sul.meio = sala_3.sul
        sala_5.leste.meio = sala_6.norte
        sala_5.oeste.meio = sala_C.norte
        sala_5.sul.meio = sala_4.leste
        sala_6.sul.meio = sala_5.oeste
        sala_C.norte.meio = sala_D.norte
        sala_C.sul.meio = sala_5.leste
        sala_D.norte.meio = sala_7.norte
        sala_D.sul.meio = sala_C.sul
        sala_D.norte.meio = sala_E.norte
        sala_6.leste.meio = sala_B.norte
        sala_B.sul.meio = sala_6.oeste
        sala_7.leste.meio = sala_8.norte
        sala_7.sul.meio = sala_E.leste
        sala_8.leste.meio = sala_9.norte
        sala_8.sul.meio = sala_7.oeste
        sala_9.sul.meio = sala_8.sul
        sala_9.oeste.meio = sala_0.sul
        sala_9.sul.meio = sala_8.oeste
        sala_E.oeste.meio = sala_7.norte
        sala_E.sul.meio = sala_D.sul

        #sala_0.norte.vai = sala_1.norte.vai()
        sala_0.norte.vai()
        # cod = Codigo(cena=sala_0.norte ,topo= "ola", codigo = "if True:print('oi')",style = dict(width=400,heigth="250px",left=500,top=100))
        # cod = Codigo(cena=sala_1.norte, topo = "hello",codigo = "if True:print('ooi')",style = dict(width=400,heigth="250px",left=500,top=100))
        # cod = Codigo(cena=sala_1.leste, topo = "Bonju",codigo = "if True:print('ooi')",style = dict(width=400,heigth="250px",left=500,top=100))
        # cod = Codigo(cena=sala_1.oeste, topo = "Buenos dias",codigo = "if True:print('ooi')",style = dict(width=400,heigth="250px",left=500,top=100))
        # cod =Codigo(cena=sala_1.sul, topo = "como vai?",codigo = "if True:print('ooi')",style = dict(width=400,heigth="250px",left=500,top=100))

        MENSAGENS = [
            [sala_0.norte, "tendi", "tamu junto"],
            [sala_1.norte, "Hello", "if True:print('ooi')"],
            [sala_1.leste, "bonju", "if True:print(':)')"],
            [sala_1.oeste, "Buenos dias", "if True:print('oi')"],
            [sala_1.sul, "como vai?", "if True:print('oi')"],
            [sala_2.norte, "Bora lá?", "if True:print('oi')"],
            [sala_2.leste, "vamos?", "if True:print('oi')"],
            [sala_2.oeste, "lest go", "if True:print('oi')"],
            [sala_2.sul, "vamonos", "if True:print('oi')"],
            [sala_3.norte, "como estas?", "if True:print('oi')"],
            [sala_3.leste, "e o dia?", "if True:print('oi')"],
            [sala_3.oeste, "ta calor?", "if True:print('oi')"],
            [sala_3.sul, "quanto graus está agora?", "if True:print('oi')"],
            [sala_4.norte, "hey", "if True:print('oi')"],
            [sala_4.leste, "parabéns", "if True:print('oi')"],
            [sala_4.oeste, "você chegou até aqui!", "if True:print('oi')"],
            [sala_4.sul, "tenha muito orgulho de vc", "if True:print('oi')"],
            [
                sala_5.norte, "temos que comemorara pequenas vitórias",
                "if True:print('oi')"
            ], [sala_5.leste, "está indo muito bem", "if True:print('oi')"],
            [
                sala_5.oeste, "tudo que fizer coloque amor",
                "if True:print('oi')"
            ], [sala_5.sul, "se ame", "if True:print('oi')"],
            [sala_6.norte, "se cuide", "if True:print('oi')"],
            [sala_6.leste, "hoje o dia esta lindo", "if True:print('oi')"],
            [
                sala_6.oeste, "deixe a chuva lavar a alma",
                "if True:print('oi')"
            ], [sala_6.sul, "hasta la vista", "if True:print('oi')"],
            [sala_7.norte, " you say goodbye", "if True:print('oi')"],
            [sala_7.leste, "and say Hello", "if True:print('oi')"],
            [sala_7.oeste, "acredite em vc", "if True:print('oi')"],
            [sala_7.sul, "vc é capaz", "if True:print('oi')"],
            [sala_8.norte, "don't worry", "if True:print('oi')"],
            [sala_8.leste, "vc é capaz", "if True:print('oi')"],
            [sala_8.oeste, " be free", "if True:print('oi')"],
            [sala_8.sul, "está quase acabando", "if True:print('oi')"],
            [
                sala_9.norte, "você esta vencendo seus medos",
                "if True:print('oi')"
            ], [sala_9.leste, "está se superando", "if True:print('oi')"],
            [sala_9.oeste, "respire", "if True:print('oi')"],
            [sala_9.sul, "comemore, pois vc venceu", "if True:print('oi')"],
            [sala_A.norte, "tudo vai bem", "if True:print('oi')"],
            [sala_A.leste, "não desista", "if True:print('oi')"],
            [sala_A.oeste, "não é tão complicado", "if True:print('oi')"],
            [sala_A.sul, "avai sim", "if True:print('oi')"],
            [sala_B.norte, "tudo vai bem", "if True:print('oi')"],
            [sala_B.leste, "não desista", "if True:print('oi')"],
            [sala_B.oeste, "não é tão complicado", "if True:print('oi')"],
            [sala_B.sul, "avai sim", "if True:print('oi')"],
            [sala_C.norte, "tudo vai bem", "if True:print('oi')"],
            [sala_C.leste, "não desista", "if True:print('oi')"],
            [sala_C.oeste, "não é tão complicado", "if True:print('oi')"],
            [sala_C.sul, "avai sim", "if True:print('oi')"],
            [sala_D.norte, "tudo vai bem", "if True:print('oi')"],
            [sala_D.leste, "não desista", "if True:print('oi')"],
            [sala_D.oeste, "não é tão complicado", "if True:print('oi')"],
            [sala_D.sul, "avai sim", "if True:print('oi')"],
            [sala_E.norte, "tudo vai bem", "if True:print('oi')"],
            [sala_E.leste, "não desista", "if True:print('oi')"],
            [sala_E.oeste, "não é tão complicado", "if True:print('oi')"],
            [sala_E.sul, "avai sim", "if True:print('oi')"]
        ]
        STYLE = dict(width=400, heigth="250px", left=500, top=100)
        [
            Codigo(cena=a, topo=b, codigo=c, style=STYLE)
            for a, b, c in MENSAGENS
        ]
示例#17
0
文件: main.py 项目: kwarwp/dame
    def __init__(self, casa):
        self.pagina_atual = 0
        self.pagina_final = 0

        class PaginaAnterior:
            def __init__(self, livro):
                self.livro = livro

            def vai(self, *_):
                if self.pagina_atual == 0:
                    self.livro.fecha_livro()
                    return False
                self.livro.pagina_atual -= 1
                self.livro.texto.topo.html = TEXTO[self.livro.pagina_atual]

        class PaginaPosterior:
            def vai(self, *_):
                self.pagina_atual += 1
                self.texto.topo.html = TEXTO[self.pagina_atual]

        self.clica_livro = lambda: None
        self.onde = None
        _livro_fechado = "https://i.imgur.com/ty2fWuE.gif"
        _livro_aberto = "https://i.imgur.com/sI177hV.jpg"
        self.casa = casa()
        self.casa.vit.i.inicia()
        Amilase(self.casa.vit)
        livro = self.casa.vit.a(_livro_fechado,
                                "caderno de notas",
                                style=dict(left=280,
                                           top=500,
                                           width=60,
                                           height="60px"))
        cena_livro = self.casa.vit.c(_livro_aberto, PaginaAnterior(self), self)
        livro.entra(self.casa.sala.B.leste)
        self.texto = texto = Codigo(codigo="",
                                    topo=TEXTO[0],
                                    style=dict(left=440, top=20, width=380))
        texto.entra(cena_livro)

        def abre_livro(*_):
            self.clica_livro = lambda: self.fecha_livro()
            self.onde = self.casa.vit.i.cena
            cena_livro.vai()

        def pega_livro(*_):
            self.clica_livro = abre_livro
            self.casa.vit.i.bota(livro)

        self.abre_livro = abre_livro
        self.clica_livro = pega_livro
        livro.vai = lambda *_: self.clica_livro()

        class Aviso:
            def __init__(self, vit):
                porta = vit.sala.C.sul
                self.aviso = vit.n(porta, TRANCA)
                porta.meio = self

            def vai(self, *_):
                self.aviso.vai()

        aviso = Aviso(self.casa.vit)

        class Pagina:
            def __init__(self, vit, nova):
                quadro = vit.sala.B.sul
                self.vit, self.nova = vit, nova
                self.aviso = vit.n(quadro,
                                   "Você acha uma folha e cola no caderno",
                                   foi=nova)
                self.papel = vit.a("https://i.imgur.com/YU3IFrt.jpg",
                                   tit="pagina1",
                                   style=dict(left=155,
                                              top=500,
                                              width=16,
                                              height="60px"),
                                   cena=quadro,
                                   vai=self.vai)

            def vai(self, *_):
                self.aviso.vai()
                self.vit.i.bota(self.papel)
                self.vit.i.tira("pagina1")
                self.nova.pagina_final = 1
                #self.nova.pagina_atual = 1
                event.stopPropagation()

        pagina = Pagina(self.casa.vit, self)
示例#18
0
    def __init__(self):
        C_SUL = C1_SUL
        C2_SUL = C1_LESTE
        sala_0 = Sala(R_NORTE, R_LESTE, R_SUL, R_OESTE)
        sala_1 = Sala(C1_NORTE, C1_LESTE, C_SUL, C1_OESTE)
        sala_2 = Sala(C2_NORTE, C2_LESTE, C2_SUL, C2_OESTE)
        sala_3 = Sala(C3_NORTE, C3_LESTE, C3_SUL, C3_OESTE)
        sala_4 = Sala(C4_NORTE, C4_LESTE, C4_SUL, C4_OESTE)
        sala_5 = Sala(C5_NORTE, C5_LESTE, C5_SUL, C5_OESTE)
        sala_6 = Sala(C6_NORTE, C6_LESTE, C6_SUL, C6_OESTE)
        sala_7 = Sala(C7_NORTE, C7_LESTE, C7_SUL, C7_OESTE)
        sala_8 = Sala(C8_NORTE, C8_LESTE, C8_SUL, C8_OESTE)
        sala_9 = Sala(C9_NORTE, C9_LESTE, C9_SUL, C9_OESTE)
        sala_A = Sala(CA_NORTE, CA_LESTE, CA_SUL, CA_OESTE)
        sala_B = Sala(CB_NORTE, CB_LESTE, CB_SUL, CB_OESTE)
        sala_C = Sala(CC_NORTE, CC_LESTE, CC_SUL, CC_OESTE)
        sala_D = Sala(CD_NORTE, CD_LESTE, CD_SUL, CD_OESTE)
        sala_E = Sala(CE_NORTE, CE_LESTE, CE_SUL, CE_OESTE)
        # TEM DOIS SUL DA C9 QUE NA VERDADE ERA PARA SER C8
        sala_0.norte.meio = sala_9.leste
        sala_0.leste.meio = sala_1.norte
        sala_1.oeste.meio = sala_2.norte
        sala_1.sul.meio = sala_0.oeste
        sala_2.norte.meio = sala_A.norte
        sala_A.norte.meio = sala_3.norte
        sala_A.sul.meio = sala_1.leste
        sala_3.norte.meio = sala_4.norte
        sala_3.sul.meio = sala_A.sul
        sala_4.oeste.meio = sala_5.norte
        sala_4.sul.meio = sala_3.sul
        sala_5.leste.meio = sala_6.norte
        sala_5.oeste.meio = sala_C.norte
        sala_5.sul.meio = sala_4.leste
        sala_6.sul.meio = sala_5.oeste
        sala_C.norte.meio = sala_D.norte
        sala_C.sul.meio = sala_5.leste
        sala_D.norte.meio = sala_7.norte
        sala_D.sul.meio = sala_C.sul
        sala_D.norte.meio = sala_E.norte
        sala_6.leste.meio = sala_B.norte
        sala_B.sul.meio = sala_6.oeste
        sala_7.leste.meio = sala_8.norte
        sala_7.sul.meio = sala_E.leste
        sala_8.leste.meio = sala_9.norte
        sala_8.sul.meio = sala_7.oeste
        sala_9.sul.meio = sala_8.sul
        sala_9.oeste.meio = sala_0.sul
        sala_9.sul.meio = sala_8.oeste
        sala_E.oeste.meio = sala_7.norte
        sala_E.sul.meio = sala_D.sul

        dino = Elemento(img=DINO,
                        tit="Dino",
                        style=dict(left=50, top=160, width=200, height=200))
        dino.entra(sala_2.leste)
        dinotexto = Texto(sala_2.leste, "e ai,colega, tudo tranks?")
        dino.vai = dinotexto.vai

        #sala_0.norte.vai = sala_1.norte.vai()
        sala_0.norte.vai()
        # cod = Codigo(cena=sala_0.norte ,topo= "ola", codigo = "if True:print('oi')",style = dict(width=400,heigth="250px",left=500,top=100))
        # cod = Codigo(cena=sala_1.norte, topo = "hello",codigo = "if True:print('ooi')",style = dict(width=400,heigth="250px",left=500,top=100))
        # cod = Codigo(cena=sala_1.leste, topo = "Bonju",codigo = "if True:print('ooi')",style = dict(width=400,heigth="250px",left=500,top=100))
        # cod = Codigo(cena=sala_1.oeste, topo = "Buenos dias",codigo = "if True:print('ooi')",style = dict(width=400,heigth="250px",left=500,top=100))
        # cod =Codigo(cena=sala_1.sul, topo = "como vai?",codigo = "if True:print('ooi')",style = dict(width=400,heigth="250px",left=500,top=100))

        MENSAGENS = [
            [sala_0.norte, "tendi", "tamu junto"],
            [sala_1.norte, "Hello", "if True:print('ooi')"],
            [sala_1.leste, "bonju", "if True:print(':)')"],
            [sala_1.oeste, "Buenos dias", "if True:print('oi')"],
            [sala_1.sul, "como vai?", "if True:print('oi')"],
            [sala_2.norte, "Bora lá?", "if True:print('oi')"],
            [
                sala_2.leste,
                "Para associar um elemento a um texto, é preciso importar o elemento e texto do vitollino.Em seguida,dizer em qual sala(ou cena) aparecerá o texto.Apos isso e so adicionar o texto que quiser e pra terminar dar o comando de vai para o texto aparecer ao clicar no elemento.Codigo: ",
                """
from _spy.vitollino.main import Elemento, Texto
dino = Elemento(img=DINO, tit="Dino", 
style=dict(left=50, top=160, 
width=200, height=200))
dino.entra(sala_2.leste)
dinotexto = Texto(sala_2.leste,
"e aí,colega, tudo tranks?")
dino.vai = dinotexto.vai
"""
            ], [sala_2.oeste, "lest go", "if True:print('oi')"],
            [sala_2.sul, "vamonos", "if True:print('oi')"],
            [sala_3.norte, "como estas?", "if True:print('oi')"],
            [sala_3.leste, "e o dia?", "if True:print('oi')"],
            [sala_3.oeste, "ta calor?", "if True:print('oi')"],
            [sala_3.sul, "quanto graus está agora?", "if True:print('oi')"],
            [sala_4.norte, "hey", "if True:print('oi')"],
            [sala_4.leste, "parabéns", "if True:print('oi')"],
            [sala_4.oeste, "você chegou até aqui!", "if True:print('oi')"],
            [sala_4.sul, "tenha muito orgulho de vc", "if True:print('oi')"],
            [
                sala_5.norte, "temos que comemorara pequenas vitórias",
                "if True:print('oi')"
            ], [sala_5.leste, "está indo muito bem", "if True:print('oi')"],
            [
                sala_5.oeste, "tudo que fizer coloque amor",
                "if True:print('oi')"
            ], [sala_5.sul, "se ame", "if True:print('oi')"],
            [sala_6.norte, "se cuide", "if True:print('oi')"],
            [sala_6.leste, "hoje o dia esta lindo", "if True:print('oi')"],
            [
                sala_6.oeste, "deixe a chuva lavar a alma",
                "if True:print('oi')"
            ], [sala_6.sul, "hasta la vista", "if True:print('oi')"],
            [sala_7.norte, " you say goodbye", "if True:print('oi')"],
            [sala_7.leste, "and say Hello", "if True:print('oi')"],
            [sala_7.oeste, "acredite em vc", "if True:print('oi')"],
            [sala_7.sul, "vc é capaz", "if True:print('oi')"],
            [sala_8.norte, "don't worry", "if True:print('oi')"],
            [sala_8.leste, "vc é capaz", "if True:print('oi')"],
            [sala_8.oeste, " be free", "if True:print('oi')"],
            [sala_8.sul, "está quase acabando", "if True:print('oi')"],
            [
                sala_9.norte, "você esta vencendo seus medos",
                "if True:print('oi')"
            ], [sala_9.leste, "está se superando", "if True:print('oi')"],
            [sala_9.oeste, "respire", "if True:print('oi')"],
            [sala_9.sul, "comemore, pois vc venceu", "if True:print('oi')"],
            [sala_A.norte, "tudo vai bem", "if True:print('oi')"],
            [sala_A.leste, "não desista", "if True:print('oi')"],
            [sala_A.oeste, "não é tão complicado", "if True:print('oi')"],
            [sala_A.sul, "avai sim", "if True:print('oi')"],
            [sala_B.norte, "tudo vai bem", "if True:print('oi')"],
            [sala_B.leste, "não desista", "if True:print('oi')"],
            [sala_B.oeste, "não é tão complicado", "if True:print('oi')"],
            [sala_B.sul, "avai sim", "if True:print('oi')"],
            [sala_C.norte, "tudo vai bem", "if True:print('oi')"],
            [sala_C.leste, "não desista", "if True:print('oi')"],
            [sala_C.oeste, "não é tão complicado", "if True:print('oi')"],
            [sala_C.sul, "avai sim", "if True:print('oi')"],
            [sala_D.norte, "tudo vai bem", "if True:print('oi')"],
            [sala_D.leste, "não desista", "if True:print('oi')"],
            [sala_D.oeste, "não é tão complicado", "if True:print('oi')"],
            [sala_D.sul, "avai sim", "if True:print('oi')"],
            [sala_E.norte, "tudo vai bem", "if True:print('oi')"],
            [sala_E.leste, "não desista", "if True:print('oi')"],
            [sala_E.oeste, "não é tão complicado", "if True:print('oi')"],
            [sala_E.sul, "avai sim", "if True:print('oi')"]
        ]
        STYLE = dict(width=400, heigth="250px", left=500, top=100)
        [
            Codigo(cena=a, topo=b, codigo=c, style=STYLE)
            for a, b, c in MENSAGENS
        ]
示例#19
0
class Button(Sprite):
    BUTTONS = []
    DISTANCES = {}
    SHOW = Codigo("oi", style=dict(left=0, top=560, width=W))

    def __init__(self, x, y, image, cena, index=0):
        super().__init__(x, y, image, cena, index)
        self.x, self.y, self.image, self.cena, self.index = x, y, image, cena, index
        self.grav, self.ele = 10, 10
        self.heat = H // 2
        self.fit = 10000000
        # timer.set_timeout(self.move, 10)
        # timer.set_timeout(self.anneal, 10)

    def _move(self):
        self.x, self.y = self.x + randint(-10, 10), self.y + randint(-10, 10)
        self.elt.style.left, self.elt.style.top = self.x, self.y
        if 0 < self.x < 700 and 0 < self.y < 500:
            timer.set_timeout(self.move, 10)

    def do_move(self, dx, dy):
        self.x = (self.x + int(dx)) % W
        self.y = (self.y + int(dy)) % H
        self.elt.style.left, self.elt.style.top = self.x, self.y
        return self.x, self.y

    def move(self):
        forces = zip(*[
            b.force(self.x, self.y, self) for b in Button.BUTTONS if b != self
        ])
        dx, dy = [sum(force) for force in forces]
        self.x += int(dx)
        self.y += int(dy)
        # Button.SHOW._code.text = f"{dx} {dy} {self.x} {self.y}"
        self.elt.style.left, self.elt.style.top = self.x, self.y
        if abs(dx) > 1 or abs(dy) > 1:
            timer.set_timeout(self.move, 2)

    def anneal(self):
        Button.SHOW._code.text = "anneal"
        heat = int(self.heat)
        moves = [
            b.do_move(randint(-heat, heat), randint(-heat, heat))
            for b in self.BUTTONS
        ]
        Button.SHOW._code.text = f"b.do_move {moves}"
        fit = self.fitness()
        self.fit, deltafit = fit, self.fit - fit
        Button.SHOW._code.text = f"self.fitt:{self.fit}, the fit::{fit}, deltafiti:{deltafit}"
        if abs(deltafit) > 0.0001:
            self.heat = self.heat * 0.78 if deltafit < 0 else self.heat * 1.2
            Button.SHOW._code.text = f"self.heat = {self.heat} fited:{fit}, deltafitd:{deltafit}"
            timer.set_timeout(self.anneal, 1000)

    def fitness(self):
        def mean(values):
            values = list(values)
            return sum(values) / (len(values) if values else 1)

        distances = self.distances()
        Button.SHOW._code.text = f"fitness: {mean(list(distances))}"
        push = mean([distance for distance in distances if distance < 90]) + 1
        pull = [distance for distance in distances if distance > 90]
        upull = mean(distances)
        Button.SHOW._code.text = f"push:{push},pull:{pull}fit: {list(distances)}"
        return push * (mean(pull) + 1) * upull * (sum(pull) + 1)
        '''
        ux, uy = x-W/4, y-H/2
        distance = sqrt(dx*dx + dy*dy)
        univer = sqrt(ux*ux + uy*uy )
        pull = 0.001 / min(0.1, distance) if distance > 90 else 0.0
        push = min(100, 0.1 / min(0.1, distance)) if distance < 90 else 0.0
        upull = min(0.05, 0.01 / min(0.1, univer)) if univer > 160 else 0.0
        return (-dx * pull + dx * push -ux * upull, -dy * pull + dy * push -uy * upull)'''

    def force(self, x, y, other):
        dx, dy = x - self.x, y - self.y
        ux, uy = x - W / 3, y - H / 2
        distance = sqrt(dx * dx + dy * dy)
        univer = sqrt(ux * ux + uy * uy)
        pull = 0.001 / min(0.1, distance) if distance > 100 else 0.0
        push = min(40, 0.03 / min(0.1, distance**2)) if distance < 90 else 0.0
        upull = min(0.05, 0.01 / min(0.1, univer)) if univer > 160 else 0.0
        other.do_move(dx * push, dy * push)
        return (-dx * pull - ux * upull, -dy * pull - uy * upull)

    def distances(self):
        def distance(a, b):
            dx, dy = a.x - b.x, a.y - b.y
            return sqrt(dx * dx + dy * dy)

        # return [value() for key, value in Button.DISTANCES.items()]
        return [distance(a, b) for a, b in Button.DISTANCES.keys()]
        # return {key: value() for key, value in Button.DISTANCES.items()}

    def create(self):
        def distance(a, b):
            dx, dy = a.x - b.x, a.y - b.y
            return sqrt(dx * dx + dy * dy)

        Button.BUTTONS = [
            Button(randint(0, 800), randint(0, 300), self.image, self.cena,
                   index) for index in range(9)
        ]
        # Button.DISTANCES = {(a, b): lambda: distance(a, b) for a in self.BUTTONS for b in self.BUTTONS if a != b}
        for a in self.BUTTONS:
            for b in self.BUTTONS:
                if a != b and (b, a) not in Button.DISTANCES:
                    Button.DISTANCES[(a, b)] = lambda: distance(a, b)
        # Button.DISTANCES = {(a, b): lambda: distance(a, b) for a in self.BUTTONS for b in self.BUTTONS if a != b}
        # [Button.DISTANCES.pop((b, a)) for a, b in Button.DISTANCES.keys() if (b, a) in self.DISTANCES]
        Button.SHOW._code.text = str(len(self.distances()))
        timer.set_timeout(self.anneal, 1000)
        return Button.BUTTONS