Example #1
0
File: main.py Project: kwarwp/ada
    def __init__(self):
        from browser import svg, document
        rosa = [(1, 0), (0, -1), (-1, 0), (0, 1)] * 20
        self.last = (500, 200)

        def block(dd):
            nx, ny = rosa.pop(0)
            ox, oy = self.last
            nx, ny = ox + nx * 20, oy - ny * 20
            self.last = (nx, ny)
            return svg.rect(width=400 - dd * 20,
                            height=400 - dd * 20,
                            x=nx,
                            y=ny,
                            style={
                                "fill": 'rgb(255,0,0)',
                                'filter': f'hue-rotate({dd*48}deg)',
                                'opacity': 0.2
                            })

        # cena  = Cena(WHITE).vai()
        base = document["pydiv"]
        base.html = ''
        tela = svg.svg(width=1200, height=700)
        base <= tela
        [tela <= block(dd) for dd in range(4)]
Example #2
0
 def __init__(self):
     doc[html.HEAD][0] <= ".hander:hover {cursor: hand; cursor: pointer;}"
     #Leg.GAME = svg.svg(width="1024px", lenght="860px")
     Leg.GAME = svg.svg(width="1024", height="860")
     doc["main"] <= Leg.GAME
     LegTakeOne(Leg.GAME)
     Blog(Leg.GAME)
     Alien(Leg.GAME)
Example #3
0
File: main.py Project: kwarwp/ada
 def __init__(self):
     self.tela = svg.svg(version="1.1",
                         viewBox="150 -10 300 300",
                         width="1600",
                         height="800")
     self.cena = Cena(BLACK)
     self.rects = Elemento('', x=0, y=0, w=1350, h=800, cena=self.cena)
     self.cena.vai()
     self.rects.elt <= self.tela
Example #4
0
File: main.py Project: kwarwp/ada
 def __init__(self):
     from browser import svg, document
     # cena  = Cena(WHITE).vai()
     base = document["pydiv"]
     self.rect, self.path = svg.rect, svg.path
     self.hue = (0, 360)
     self.color = (255, 100, 100)
     base.html = ''
     self.tela = svg.svg(width=1200, height=700)
     base <= self.tela
Example #5
0
    def _vai(self, ev):
        self.remaining_shuffle_count -= 1
        if not self.remaining_shuffle_count:
            self.quit()
            return

        from browser import document, alert, svg
        dx, dy = randint(-300, 300), 100 - randint(-100, 100)
        dy = abs(300 - dx) // 3
        dx, dy = 200 - dx, 100 - randint(-dy, dy)
        #alert (ev.target.id)
        obj = document[ev.target.id]
        obj_name = ev.target.id[4:]
        if obj.getAttribute("data-didit") == "_did_":
            return
        if obj_name in self.comida + ["gato"]:
            food = Elemento('',
                            x=0,
                            y=50,
                            w=200,
                            h=200,
                            tit=f"{ev.target.id}_",
                            cena=self.cena)
            stag = svg.svg(version="1.1", width="200", height="200")
            food.elt <= stag
            #food.tit = f"{ev.target.id}_"
            stag <= obj
            obj.setAttribute(
                'transform',
                f"translate(-{ROFFX-485} -{ROFFY-220}) scale(0.60 1.35)")
            obj.setAttribute(
                'transform',
                f"translate(-{ROFFX-485} -{ROFFY-220}) scale(0.60 1.35)")
            INV.bota(food)
            #self.__vai = lambda *_: None
            obj.setAttribute("data-didit", "_did_")
            if obj_name == "gato":
                obj.setAttribute(
                    'transform',
                    f"translate(-{ROFFX-485} -{ROFFY-345}) scale(0.60 0.6)")
                food.vai = TheHero().calma
                TheHero().blacking(food.tit)
                return
            TheHero().fishing(food.tit)
        else:
            obj.setAttribute(
                'transform',
                f"translate({dx} {dy})  rotate({7*randint(0,70)} {ROFFX} {ROFFY}) scale(2.5)"
            )
def set_up_board_svg_graphics():
  # alternative graphics method.
  global APANEL, SHOW_SELECTION_Button, board
  boarddiv = html.DIV(Id="boarddivid", style={"backgroundColor":"#CCFFCC"})
  boarddiv <= html.I("Puzzle state:")
  APANEL = svg.g(Id="panel")
  board = svg.svg(Id="svgboard", 
                  style={"width":PAINTING_WIDTH, "height":PAINTING_HEIGHT, 
                         "backgroundColor":"#AAAABB"})
  board <= APANEL
  boarddiv <= board
  # Put in a button for controlling whether or not the currently selected box is highlighted.
  SHOW_SELECTION_Button = html.BUTTON("Hide/Show selected box", Id="HideOrShowSelected")
  SHOW_SELECTION_Button.bind('click', hideOrShowSelection)
  boarddiv <= SHOW_SELECTION_Button
  gui <= boarddiv
Example #7
0
File: main.py Project: kwarwp/ada
 def __init__(self):
     from browser import svg, document
     # cena  = Cena(WHITE).vai()
     base = document["pydiv"]
     base.html = ''
     tela = svg.svg(width=1200, height=700)
     base <= tela
     bar = svg.rect(width="300",
                    height="100",
                    style={"fill": 'rgb(255,0,0)'})
     tela <= bar
     [
         tela <= svg.rect(x=ix * 40,
                          width="40",
                          height=600 - ix * 30,
                          style={
                              "fill": 'rgb(255,0,0)',
                              'filter': f'hue-rotate({ix*18}deg)'
                          }) for ix in range(20)
     ]
Example #8
0
 def dump(self, cena, sorte=4):
     from browser import svg
     h = TheHero()
     #cena.elt <= self.cache
     self.cena = cena
     self.fundo = Elemento(RUBISH, x=0, y=0, w=1350, h=800, cena=cena)
     self.desiste = Elemento(DESISTO, y=100, cena=cena, vai=self.quit)
     self.remaining_shuffle_count = 20 + 2 * h.pers + h.levl // 5
     self.rubish = svg.svg(version="1.1",
                           viewBox="400 250 1000 600",
                           width="1600",
                           height="800")
     self.fundo.elt <= self.rubish
     comer = self.comida * (4 + h.levl // 2)
     shuffle(comer)
     shuffle(lixo)
     trash = 20 + 2 * h.levl
     sujo = 10 + 2 * h.levl
     sorte += h.luck + randint(0, h.levl) // 3
     pilha = lixo[:trash] + self.sujeira[:sujo] + comer[:sorte] + ['gato']
     shuffle(pilha)
     for indice, label in enumerate(pilha):
         dx, dy = randint(-300, 300), 100 - randint(-100, 100)
         #dy = abs(300 -dx)//3
         dy = (300 - abs(dx)) // 2
         dx, dy = 200 - dx, 100 - randint(-dy, dy)
         obj = svg.use(
             id=f"#{indice:03d}{label}",
             href=f"#{label}",
             x=200,
             y=100,
             width=250,
             height=250,
             transform=
             f"translate({dx} {dy})  rotate({7*indice} {ROFFX} {ROFFY}) scale(2.5)"
         )
         self.rubish <= obj
         obj.bind('click', self._vai)
         obj.setAttribute("data-didit", "_no_")

x1 = 50
y1 = 50

x2 = 50
y2 = 150

x3 = 150
y3 = 150

x4 = 150
y4 = 50

board = svg.svg(Id = "svgboard",
	style = {"width":400, "height":400,
				"backgroundColor":"#AAAABB"})
window.addAttribute(board,"viewBox","0,0,400,400")


defs = svg.defs()
pattern = svg.pattern(id="wallpaper", width = "100%", height= "100%")
img = svg.image(xlink_href="force.jpg", width = "1", height = "1", transform = "translate(1,1) , rotate(180)")
window.addAttribute(pattern,"patternContentUnits","objectBoundingBox")
window.addAttribute(img,"preserveAspectRatio","none")

# Append
pattern <= img
board <= pattern

#img.transform = "rotate(180,1,1)"
def initial_render():
	boarddiv = html.DIV(Id = "boarddivid", style = {"backgroundColor":"rgb(180,198,211)"})
	
	# Create canvas
	global ctx, roleCanvas
	roleCanvas = html.CANVAS(id = "roleCanvas", width = GAME_WIDTH, height = GAME_HEIGHT)
	ctx = roleCanvas.getContext("2d")
	
	# Create svg board
	global APANEL, board, PList
	board = svg.svg(Id = "svgboard", 
					style = {"width":GAME_WIDTH, "height":GAME_HEIGHT,
							"backgroundColor":"rgb(190,208,221)"})
	board.elt.style.display = "none"
	APANEL = svg.g(Id = "panel", style = {"text-align" : "center"})

	
	# Create music divs
	global musicDisplay
	musicDisplay = html.DIV(id ="musicDisplay")
	musicDisplay.style = {  'width' : str(GAME_WIDTH) + "px", 
							'height' : str(GAME_HEIGHT) + "px",
							"backgroundColor":"black",
							'display' : 'none',
							'color' : 'white',
							'text-align' : 'center', 
							'font-weight' : 'bold',
							'font-size' : '28pt'}
							
	playButton = html.BUTTON(id = "playButton", type = "button")
	playButton.style = {'width' : str( 1/4 *GAME_WIDTH) + "px",
						'height' : str( 1/5 * GAME_HEIGHT) + "px",
						'position' : 'absolute',
						'top' : str(GAME_HEIGHT + 10) + "px",
						'left' : "28px"
						}
	playButton.innerHTML = "Play Song"
	playButton.bind('click',handlePlayButtonClick)
	
	
	songSelected = html.P(id = "songSelected")
	songSelected.style = {'margin' : 0}
	songSelected.innerHTML = "No Song Selected"
	
	# Create rule divs
	global ruleDisplay
	ruleDisplay = html.DIV(id="ruleDisplay")
	ruleDisplay.style = {  'width' : str(GAME_WIDTH) + "px", 
							'height' : str(GAME_HEIGHT) + "px",
							"backgroundColor":"black",
							'display' : 'none',
							'color' : 'white',
							'text-align' : 'center', 
							'font-weight' : 'bold',
							'font-size' : '28pt'}
	
	
	board <= APANEL	
	boarddiv <= board
	boarddiv <= roleCanvas
	musicDisplay <= songSelected
	musicDisplay <= playButton
	
	boarddiv <= musicDisplay
	boarddiv <= ruleDisplay
	
	gui <= boarddiv
	
	# Javascript that manages canvas.
	setCanvasManager()