Esempio n. 1
0
    def setup(self):
        self.background_color = 'darkslategray'
        self.df_color = self.background_color
        self.tetris = TetrisMain(self.size)
        #self.mino = self.tetris.mino
        self.add_child(self.tetris)
        # --- btn start
        path = ui.Path.oval(0, 0, 72, 72)
        self.d_btn = scene.ShapeNode(path=path,
                                     parent=self,
                                     fill_color='white')
        self.d_btn.position = self.size * .5
        self.d_btn.position -= (0, self.size[1] / 2 - self.d_btn.size[1] / 2)
        self.l_btn = scene.ShapeNode(path=path, parent=self, fill_color='red')
        self.l_btn.position = self.size * .5
        self.l_btn.position -= (+(self.l_btn.size[0]),
                                self.size[1] / 2 - self.l_btn.size[1])
        self.r_btn = scene.ShapeNode(path=path, parent=self, fill_color='blue')
        self.r_btn.position = self.size * .5
        self.r_btn.position -= (-(self.r_btn.size[0] * 1),
                                self.size[1] / 2 - self.r_btn.size[1])
        self.e_btn = scene.ShapeNode(path=path,
                                     parent=self,
                                     fill_color='yellow')
        self.e_btn.position = self.size * .5
        self.e_btn.position -= (0, self.size[1] / 2 - self.e_btn.size[1] * 1.5)

        self.s_btn = scene.ShapeNode(parent=self, fill_color='pink')
        self.s_btn.path = ui.Path.oval(0, 0, 32, 32)
        self.s_btn.position = self.size * .5
        self.s_btn.position -= (self.s_btn.size[0] - self.size[0] / 2,
                                self.size[1] / 3)
 def add_line(self, angle):
     p = ui.Path.rect(0, 0, 1000, 1)
     line = scene.ShapeNode(p, stroke_color='white', fill_color='none')
     line.anchor_point = (0, 0)
     line.rotation = math.radians(angle)
     line.position = self.size / 2
     self.add_child(line)
Esempio n. 3
0
    def __init__(self, parent: scene.Node, promotion_square: Square, square_shape: SquareShape) -> None:
        self.options: List[scene.SpriteNode] = []
        self.shapes: List[scene.ShapeNode] = []

        direction = promotion_square.piece.color.value

        promotion_options = ("queen", "knight", "rook", "bishop")

        for i, piece_name in enumerate(promotion_options, start=1):
            x, y = square_shape.position
            if HEIGHT - 16*SQUARE_SIZE < 0:
                # Can't fit the vertical piece selection on the screen => running for example on iPad's 4:3 screen.
                pos = ((i-2.5)*SQUARE_SIZE + WIDTH/2, 1.15*SQUARE_SIZE*direction + y)
            else:
                pos = (x, i * SQUARE_SIZE * direction + y)

            # Black menu is flipped 180 degrees.
            size = (SQUARE_SIZE * direction,) * 2
            
            self.shapes.append(
                scene.ShapeNode(
                    path=ui.Path.rect(0, 0, *size),
                    parent=parent,
                    position=pos,
                    fill_color="#eeeeee",
                )
            )
            sn = scene.SpriteNode(
                texture=get_image(promotion_square.piece, piece_name),
                parent=parent,
                position=pos,
                size=size,
            )
            sn.piece_name = piece_name
            self.options.append(sn)
Esempio n. 4
0
 def setup(self, Scene):
     path = ui.Path.oval(0, 0, 20, 20)
     self.node = scene.ShapeNode(path)
     self.node.position = self.position
     self.node.color = (random.uniform(0.5, 1), 0, random.uniform(0.5,
                                                                  1), 1)
     Scene.add_child(self.node)
Esempio n. 5
0
    def __init__(self, nodes: List[scene.Node]) -> None:
        self.nodes = nodes
        super().__init__()
        self.bg = scene.SpriteNode(color="black", parent=self)
        bg_shape = ui.Path.rounded_rect(0, 0, 240, len(nodes) * 64 + 70, 8)
        bg_shape.line_width = 4
        shadow = ((0, 0, 0, 0.35), 0, 0, 24)
        self.menu_bg = scene.ShapeNode(bg_shape, (1, 1, 1, 0.9),
                                       "black",
                                       shadow=shadow,
                                       parent=self)

        for i, node in enumerate(nodes):
            node.position = (0, i * 64 - (len(nodes) - 1) * 32)
            if isinstance(node, scene.Node):
                self.menu_bg.add_child(node)
            else:
                self.menu_bg.view.add_subview(node)

        self.did_change_size()
        self.menu_bg.scale = 0
        self.bg.alpha = 0
        self.bg.run_action(scene.Action.fade_to(0.4))
        self.menu_bg.run_action(
            scene.Action.scale_to(1, 0.3, scene.TIMING_EASE_OUT_2))
        self.background_color = "white"
Esempio n. 6
0
 def setup(self):
     print(self.size, self.bounds, self.frame)
     self.label_node = scene.LabelNode('Hello World', 
         position=self.size/2.0, parent=self)
     self.sprite_node = scene.SpriteNode('Dog_Face', 
         position=(self.size[0]/2, self.size[1]/2-100), parent=self)
     self.shape_node = scene.ShapeNode(ui.Path.oval(0, 0, 50, 50), fill_color='red', 
         stroke_color='green', position=(self.size[0]/2, self.size[1]/2+100), parent=self)  
Esempio n. 7
0
	def setup(self):
		self.glyphs_list = [scene.ShapeNode(i) for i in glyphs_list1[::int(reduction_factor)]]
		self.myPath = self.glyphs_list[0]
		self.myPath.anchor_point = 0, 0
		self.myPath.position = (1024 - self.myPath.bbox.width * 1.75,
		768 - self.myPath.bbox.height * 1.3)
		self.add_child(self.myPath)
		self.background_color = 'lightgrey'
		self.touch_moved = self.touch_began
Esempio n. 8
0
 def setup(self):
     self.background_color = 'midnightblue'
     self.ship = scene.SpriteNode('spc:PlayerShip1Orange',
                                  position=self.size / 2,
                                  parent=self)
     self.button = scene.ShapeNode(ui.Path.oval(0, 0, 100, 100),
                                   position=(200, 100),
                                   fill_color='green',
                                   parent=self)
 def add_circle(self):
     radius = self.size.height / 2
     oval = ui.Path.oval(-radius, -radius, radius, radius)
     node = scene.ShapeNode(path=oval,
                            fill_color='none',
                            stroke_color='lightblue')
     node.color = 'white'
     node.position = self.size / 2
     self.add_child(node)
Esempio n. 10
0
 def __init__(self, p_parent):
     super().__init__()
     guide_color = 'red'
     p_x = p_parent.size[0]
     p_y = p_parent.size[1]
     line = scene.ShapeNode(parent=self)
     line.path = ui.Path()
     line.path.move_to(0, p_y / 2)
     line.path.line_to(p_x, p_y / 2)
     line.path.move_to(p_x / 2, 0)
     line.path.line_to(p_x / 2, p_y)
     line.stroke_color = guide_color
     x_oval = scene.ShapeNode(parent=self)
     x_o = min(p_x, p_y)
     x_oval.path = ui.Path.oval(0, 0, x_o / 2, x_o / 2)
     x_oval.fill_color = (0, 0, 0, 0)
     x_oval.stroke_color = guide_color
     self.alpha = .25
     self.position = p_parent.size / 2
     p_parent.add_child(self)
 def touch_ended(self, touch):
     '''instantiate a shapenode, and animate it'''
     self.touch = None
     self.spot = scene.ShapeNode(path=ui.Path.oval(0, 0, 100, 100),
                                 parent=self)
     self.spot.fill_color = self.spot_color
     self.spot.position = self.points[0].location
     actions = []
     for i in range(len(self.points) - 1):
         duration = self.timing[i + 1] - self.timing[i]
         loc = self.points[i].location
         actions.append(scene.Action.move_to(*loc, duration))
         self.spot.run_action(
             scene.Action.repeat_forever(scene.Action.sequence(actions)))
 def setup(self):
     self.background_color = (1, 1, 1)
     n = len(self.data) // 8 + 8
     r = 0.49 * min(self.size.w, self.size.h)
     rled = r * 0.025
     Rled = +0.95 * r
     xc = self.size.h / 2
     yc = self.size.h / 2
     self.phi1 = 1.5 * 2 * pi / n
     self.phi2 = self.phi1 - 3 * 2 * pi / n
     for pos in ((xc + Rled * cos(phi), yc + Rled * sin(phi))
                 for phi in (self.phi1, self.phi2)):
         circ = scene.ShapeNode(ui.Path.oval(0, 0, 2 * rled, 2 * rled),
                                fill_color='#00ffde',
                                stroke_color='#000000',
                                position=pos)
         self.add_child(circ)
     self.statusLed = scene.ShapeNode(ui.Path.oval(0, 0, 2 * rled,
                                                   2 * rled),
                                      color='#ff0000',
                                      position=(self.size.h - 20, 20))
     self.add_child(self.statusLed)
     self.dial = dial(self.size.h / 2,
                      self.size.h / 2,
                      0.9 * r,
                      r,
                      n,
                      scale=1.0)
     self.add_child(self.dial)
     text = LabelNode("——", color=(0, 0, 0))
     text.position = (self.size.h / 2 + 0.9 * r, self.size.h / 2)
     self.add_child(text)
     self.dial.angle = pi / 16
     self.stateTable = StateTable(self.size.h, 0, self.size.w - self.size.h,
                                  self.size.h, self.data)
     self.stateTable.state = self.initial_state
     self.add_child(self.stateTable)
Esempio n. 13
0
    def __init__(self,
                 parent,
                 x,
                 y,
                 w,
                 h,
                 border=True,
                 rounded=True,
                 text="foo",
                 color='white',
                 bordercolor='black',
                 textcolor='black',
                 altcolor='black',
                 altbordercolor='white',
                 alttextcolor='white'):
        #Basic button colors
        self.color = color
        self.textcolor = textcolor
        self.bordercolor = bordercolor

        #Colors for when button is pressed
        self.altcolor = altcolor
        self.altbordercolor = altbordercolor
        self.alttextcolor = alttextcolor

        #create button label and apply arguments
        self.label = scene.LabelNode(text)
        self.label.color = textcolor

        #create button path and shape
        #rounded variable determines rounded rect or not
        if rounded == True:
            self.path = ui.Path.rounded_rect(0, 0, w, h, 10)
        else:
            self.path = ui.Path.rect(0, 0, w, h)

        #Create button node
        self.node = scene.ShapeNode(self.path,
                                    stroke_color=self.bordercolor,
                                    position=(x, y))

        #Extra stuff
        self.node.line_width = 1.5
        self.node.fill_color = self.color

        #Add label to button, add button to parent scene
        self.node.add_child(self.label)
        parent.add_child(self.node)
    def __init__(self, x, y, r1, r2, n, **args):
        scene.Node.__init__(self, **args)
        self.all_flags = []
        self.angle_ = 0.0
        self.r1 = r1
        self.r2 = r2
        self.position = (x, y)
        self.n = n

        p = ui.Path()
        p.move_to(r1, 0)
        ang1 = 2 * 2 * pi / self.n
        p.add_arc(0, 0, r1, 0, -ang1 / 2, False)
        p.add_arc(0, 0, r2, -ang1 / 2, ang1 / 2, True)
        p.add_arc(0, 0, r1, ang1 / 2, 0, False)
        p.close()
        rcorr = (cos(ang1 / 2) * r1 + r2) / 2
        rcorr = 0.0
        for ang in [(4 * i + 3) * (2 * pi / n)
                    for i in (*range(self.n // 4), -0.5)]:
            flag = ShapeNode(p)
            flag.fill_color = (0, 0, 0)
            flag.stroke_color = (0, 0, 0)
            flag.alpha = 0.8
            flag.position = (cos(ang) * rcorr, sin(ang) * rcorr)
            flag.anchor_point = (0.0, 0.5)
            flag.rotation = ang
            self.add_child(flag)
            self.all_flags.append(flag)
        circ = scene.ShapeNode(ui.Path.oval(0, 0, 2 * r1, 2 * r1))
        circ.fill_color = (1, 1, 1)
        circ.stroke_color = (0, 0, 0)
        self.add_child(circ)
        for i in range(self.n):
            ang = -i * 2 * pi / self.n
            text = LabelNode("%3d – " % (i - 4), color=(0, 0, 0), scale=1.0)
            text.rotation = ang
            text.position = (cos(ang) * (self.r1 - text.size.w / 2),
                             sin(ang) * (self.r1 - text.size.w / 2))
            self.add_child(text)
        text = LabelNode("+", color=(0, 0, 0), scale=1.0)
        self.add_child(text)
Esempio n. 15
0
 def setup(self):
     button_font = ('Avenir Next', 20)
     title_font = ('Avenir Next', 36)
     num_buttons = len(self.button_titles)
     self.bg = scene.SpriteNode(color='#000000', parent=self)
     bg_shape = ui.Path.rounded_rect(0, 0, 240, num_buttons * 64 + 140, 8)
     bg_shape.line_width = 4
     shadow = ((0, 0, 0, 0.35), 0, 0, 24)
     self.menu_bg = scene.ShapeNode(bg_shape,
                                    '#BBADA0',
                                    '#CDC1B4',
                                    shadow=shadow,
                                    parent=self)
     self.title_label = scene.LabelNode(
         self.title,
         font=title_font,
         color='#000000',
         position=(0, self.menu_bg.size.h / 2 - 40),
         parent=self.menu_bg)
     self.title_label.anchor_point = (0.5, 1)
     self.subtitle_label = scene.LabelNode(
         self.subtitle,
         font=button_font,
         position=(0, self.menu_bg.size.h / 2 - 100),
         color='#000000',
         parent=self.menu_bg)
     self.subtitle_label.anchor_point = (0.5, 1)
     self.buttons = []
     for i, title in enumerate(reversed(self.button_titles)):
         btn = ButtonNode(title, parent=self.menu_bg)
         btn.position = 0, i * 64 - (num_buttons - 1) * 32 - 50
         self.buttons.append(btn)
     self.did_change_size()
     self.menu_bg.scale = 0
     self.bg.alpha = 0
     self.bg.run_action(A.fade_to(0.4))
     self.menu_bg.run_action(A.scale_to(1, 0.3, scene.TIMING_EASE_OUT_2))
     self.background_color = '#FFFFFF'
Esempio n. 16
0
 def draw(self):
     self.clear()
     width, height = self.parent.scene.size
     width *= self.xsize
     height *= self.ysize
     if self.xdata is None:
         return
     kwargs = dict(
         fill_color='clear',
         stroke_color='gray',
         anchor_point=(0, 0)    
     )
     scale_x = width / (self.x_max - self.x_min)
     scale_y = height / (self.y_max - self.y_min)
     step_x_axis = scale_x * (self.x_max - self.x_min)/self.nticks
     step_y_axis = scale_y * (self.y_max - self.y_min)/self.nticks
     
     # draw axes
     axesPath = ui.Path()
     # move to graph (0, 0) and add y-axis
     axesPath.move_to(0, 0)
     axesPath.line_to(0, height-self.ysize)
     kwargs['stroke_color'] = 'black'
     self.axis = scene.ShapeNode(axesPath, **kwargs)
     
     # mark values on y-axis
     yPath = ui.Path()
     def makeLabelNode(i):
         label = '{:.01f}'.format(self.y_min + (self.nticks-i)*(self.y_max - self.y_min)/self.nticks)
         n = scene.LabelNode(label, font=('Avenir Next', 13), 
                             position = (-15, height - step_y_axis * i))
         return n
     
     self.labels = []   
     for i in range(self.nticks + 1):
         yPath.move_to(5, height - step_y_axis*i)
         yPath.line_to(0, height - step_y_axis*i)
         self.labels.append(makeLabelNode(i))
     self.ticks = scene.ShapeNode(yPath, **kwargs)
 
     # data
     x = self.xdata
     y = self.ydata
     dataPath = ui.Path()
     dataPath.move_to(scale_x * (x[0] - self.x_min),
                      height - scale_y * (y[0] - self.y_min))
     for i in range(len(x)):
         draw_x = scale_x * (x[i] - self.x_min)
         draw_y = height - scale_y * (y[i] - self.y_min)
         dataPath.line_to(draw_x, draw_y)
     dataPath.line_width = 2
     kwargs['stroke_color'] = self.graph_color
     self.graph = scene.ShapeNode(dataPath, **kwargs)
     
     # target
     kwargs['stroke_color'] = 'gray'
     if self.goal is not None:
         goalPath = ui.Path()
         goalPath.move_to(scale_x * (x[0] - self.x_min), 
                          height - scale_y * (self.goal - self.y_min))
         goalPath.line_to(scale_x * (x[-1] - self.x_min), 
                          height - scale_y * (self.goal - self.y_min))
         self.target = scene.ShapeNode(goalPath, **kwargs)
     else:
         self.target = None
                     
     self.add()
def circle_segment_shape(point, r, angle):
    '''Blue & red shape for circle segment of radius r and angle degrees at point'''
    return scene.ShapeNode(path=circle_segment_path(r, angle),
                           fill_color='blue',
                           stroke_color='red',
                           position=point)
Esempio n. 18
0
    def setup(self):
        color_gps = "#2299ff"
        self.background_color = "#161616"

        self.scrw = numpy.min([440, self.size.w])
        self.scrh = self.size.h / self.size.w * self.scrw
        self.scale = self.size.h / self.scrh

        self.adiCenter = [self.scrw / 2.0, self.scrh - 155]
        self.pxPerDeg = 10

        self.hdg_mode = True
        self.dtk = 0.0
        self.yaw_history = list()

        ADI = scene.Node(parent=self)
        ADI.position = self.adiCenter

        # Attitude pitch marks
        #self.pitchMarks=scene.SpriteNode("IMG_2130.JPG")

        self.pitchMarks = sg.adi_pitchBars(self.pxPerDeg)
        ADI.add_child(self.pitchMarks)
        self.rollPointer = sg.adi_rollPointer(150)
        ADI.add_child(self.rollPointer)
        self.yawPointer = sg.adi_yawPointer(150)
        ADI.add_child(self.yawPointer)

        ADI.add_child(sg.adi_ac())
        ADI.add_child(sg.adi_rollMarks(150))

        # Location labels
        locationNode = scene.ShapeNode(scene.ui.Path.rect(0, 0, 200, 48))
        locationNode.anchor_point = [0.0, 0.99]
        locationNode.position = [0.0, self.scrh]
        locationNode.fill_color = "#000000"

        h = 24
        self.lbl_lat = scene.LabelNode("%3.3f" % 0)
        self.lbl_lat.position = [0, 0]
        self.lbl_lat.anchor_point = [0, 1.0]
        self.lbl_lat.color = color_gps
        locationNode.add_child(self.lbl_lat)
        self.lbl_lon = scene.LabelNode("%3.3f" % 0)
        self.lbl_lon.position = [0, -h]
        self.lbl_lon.anchor_point = [0, 1.0]
        self.lbl_lon.color = color_gps
        locationNode.add_child(self.lbl_lon)

        adi_height = 280
        hsi_height = self.scrh - adi_height
        altNode = scene.ShapeNode(scene.ui.Path.rect(0, 0, self.scrw + 1,
                                                     self.scrh - adi_height),
                                  "#000000",
                                  parent=self)
        altNode.anchor_point = (0.0, 0.0)
        altNode.position = [-1.0, -1.0]

        # Alt label
        [alt_symbol, self.txt_alth, self.txt_altd] = sg.alt_display(ADI)
        alt_symbol.position = [self.scrw / 2, 0.0]

        # GS label
        [gs_symbol, self.txt_spd] = sg.gs_display(ADI)
        gs_symbol.position = [-self.scrw / 2, 0.0]

        # HSI
        self.cdi_r = 180.0
        [self.rose] = sg.compass_rose(altNode, self.cdi_r)
        self.rose.position = [
            self.scrw / 2, self.scrh - adi_height - self.cdi_r - 32
        ]

        [self.cdi_needle, self.cdi_track] = sg.cdi(self.cdi_r)

        [ac] = sg.ac_symbol(altNode)
        ac.position = [self.scrw / 2, self.scrh - adi_height - self.cdi_r - 32]

        # Heading label
        h = 30
        [self.hdg_symbol, self.txt_hdg] = sg.hdg_display(altNode, h)
        self.hdg_symbol.position = [self.scrw / 2, hsi_height + 10]

        # Waypoint info display
        [self.wpt_dsp, self.wpt_name, self.wpt_dtk,
         self.wpt_dist] = sg.wpt_display(altNode)
        self.wpt_dsp.position = [0, hsi_height]

        self.wpt = ""
        self.scratchpad = sg.scratchpad(self, self.scrw, 128)

        # G meter
        [g_symbol, self.txt_g] = sg.g_display(ADI)
        g_symbol.position = [self.scrw / 2, -adi_height / 3]

        location.start_updates()
        motion.start_updates()

        self.isInit = True
        print(self.pitchMarks)
        print("PFD initialized")