Ejemplo n.º 1
0
 def __init__(self, background=None, **kwargs):
     """ Setup object
     :background: background fill color
     """
     SlTrace.lg("BlockPanel: %s" % (self))
     super().__init__(**kwargs)
     if background is None:
         background = "lightyellow"
     self.background = background
     canvas = self.get_canvas()
     if canvas is None:
         self.canvas = Canvas(width=self.cv_width, height=self.cv_height)
     self.entries = []  # entries e.g. cars, roads, ...
     """ Do background / scenery
     """
     bk_inset = .0001
     ###bk_inset = 0.
     p1 = Pt(0, 0)
     p2 = Pt(0, 1)
     p3 = Pt(1, 1)
     p4 = Pt(1, 0)
     background = BlockPolygon(tag="panel_background",
                               points=[p1, p2, p3, p4],
                               position=Pt(bk_inset, bk_inset),
                               container=self,
                               height=1.0 - 2 * bk_inset,
                               width=1.0 - 2 * bk_inset,
                               xkwargs={'fill': self.background})
     self.comps.append(background)
Ejemplo n.º 2
0
 def __init__(self, track, **kwargs):
     """ Setup Road object
      """
     super().__init__(track, road_type=RoadType.STRAIT, **kwargs)
     if self.width is None:
         self.width = self.get_road_width()
     if self.height is None:
         self.height = self.get_road_length()
     strait = BlockPolygon(
         container=self,
         tag=self.tag,
         position=Pt(0, 0),
         ###width=self.get_road_width(),
         ###height=self.get_road_length(),
         ###height=self.height,
         ###rotation=self.rotation,
         ctype=BlockType.POLYGON,
         points=[Pt(0, 0), Pt(1, 0), Pt(1, 1),
                 Pt(0, 1)],
         xkwargs={'fill': 'black'})
     self.comps.append(strait)
Ejemplo n.º 3
0
    def highlight(self, x=None, y=None, display=True):
        """ Hilight adjustment block
        :ck_block: adjustment block
        :x: x coordinate
        :y: y coordinate
        :display: display result default:
        """
        choice = AdjChoice.FORWARD
        if self.comps:
            for comp in self.comps:
                comp.remove_display_objects()
                del comp
            self.comps = []

        if not self.is_at(x, y):
            return

        self.xkwargs['activedash'] = 1
        self.xkwargs['activewidth'] = 1
        self.xkwargs['activeoutline'] = "red"
        #self.xkwargs['activefill'] = "gray"
        ip = self.get_internal_point([x, y])
        if (ip.y < self.mly and ip.y > self.by and ip.x > self.lx
                and ip.x < self.rx):
            choice = AdjChoice.BACKWARD
            if display:
                fp_points = [  # Backward point
                    Pt(self.lx, self.mly),
                    Pt(self.rx, self.mly),  # rt upper pt
                    Pt(self.mx, self.by)  # middle pt
                ]
                forward_point = BlockPolygon(container=self,
                                             points=fp_points,
                                             color="black")
                self.comps.append(forward_point)
        elif (ip.y < self.muy and ip.y > self.mly and ip.x > self.mx
              and ip.x < self.rx):
            choice = AdjChoice.RIGHT
            if display:
                right_points = [  # Right point
                    Pt(self.mx, self.muy),  # left point slant
                    Pt(self.rx, (self.mly + self.muy) / 2),  # Upper point
                    Pt(self.mx, self.mly),  # right point slant
                ]
                right_ind = BlockPolygon(container=self,
                                         points=right_points,
                                         color="green")
                self.comps.append(right_ind)
        elif (ip.y < self.muy and ip.y > self.mly and ip.x > self.lx
              and ip.x < self.mx):
            choice = AdjChoice.LEFT
            if display:
                backward_points = [  # Left point
                    Pt(self.mx, self.muy),  # right point slant
                    Pt(self.lx, (self.mly + self.muy) / 2),  # Upper point
                    Pt(self.mx, self.mly),  # right point slant
                ]
                right_ind = BlockPolygon(container=self,
                                         points=backward_points,
                                         color="blue")
                self.comps.append(right_ind)
        else:
            choice = AdjChoice.FORWARD
            if display:
                forward_points = [  # Forward point
                    Pt(self.lx, self.muy),  # left point slant
                    Pt(self.mx, self.ty),  # Upper point
                    Pt(self.rx, self.muy),  # right point slant
                ]
                backward_rect = BlockPolygon(container=self,
                                             points=forward_points,
                                             color="red")
                self.comps.append(backward_rect)
        if display:
            self.display()

        return choice
Ejemplo n.º 4
0
    position = Pt(pos_x, pos_y)

bP = BlockBlock(canvas=canvas,
                width=th_width,
                height=th_height,
                position=position,
                cv_width=width,
                cv_height=height,
                rotation=rotation)
bP.display()

poly_pos = Pt(.4, .5)
poly_points = [Pt(0, 0), Pt(0, 1), Pt(1, 1), Pt(1, 0)]
poly = BlockPolygon(container=bP,
                    position=poly_pos,
                    width=.5,
                    height=.3,
                    points=poly_points,
                    xkwargs={'fill': "red"})
bP.comps.append(poly)
bP.display()
SlTrace.lg("\npoly1 points: %s" % poly.get_absolute_points())
poly_xtran = poly.get_full_xtran()
SlTrace.lg("poly_xtran=%s" % tran2matrix(poly_xtran))
poly_ixtran = poly.get_full_ixtran()
SlTrace.lg("poly_ixtran=%s" % tran2matrix(poly_ixtran))
xtran_ti = poly_xtran * poly_ixtran
SlTrace.lg("xtran x ixtran=%s(%s)" % (tran2matrix(xtran_ti), xtran_ti))

poly2 = poly.dup()
poly2.xkwargs = {'fill': "orange"}
poly2.drag_block(delta_x=-.2, delta_y=-.2, canvas_coord=False)
Ejemplo n.º 5
0
    def __init__(self,
                 track,
                **kwargs):
        """ Setup Road object
         """
        super().__init__(track, car_type=CarType.SIMPLE, **kwargs)
        if self.width is None:
            self.width = self.get_car_width()
        if self.height is None:
            self.height = self.get_car_length()
        base_color = self.base_color
        if base_color is None:
            base_color = "violet"
        car_base = BlockPolygon(container=self,
                            tag=self.tag,
                            position=Pt(0,0),
                            points=[Pt(0,0), Pt(0,1), Pt(1,1), Pt(1,0)],
                            xkwargs={'fill' : base_color})
        self.comps.append(car_base)
        
        top_left = .01
        top_right = 1-top_left
        top_back = .25
        top_front = .50
        top_pts = [Pt(top_left,top_back),
                   Pt(top_left, top_front),
                   Pt(top_right, top_front),
                   Pt(top_right, top_back)]
        car_top = BlockPolygon(container=self,
                            tag=self.tag,
                            position=Pt(0,0),
                            points=top_pts,
                            xkwargs={'fill' : 'gray'})
        self.comps.append(car_top)

        windshield_left = top_left
        windshield_right = top_right
        windshield_back = top_front
        windshield_front = windshield_back + .1        
        windshield_pts = [Pt(windshield_left,windshield_back),
                   Pt(windshield_left, windshield_front),
                   Pt(windshield_right, windshield_front),
                   Pt(windshield_right, windshield_back)]
        car_windshield = BlockPolygon(container=self,
                            tag=self.tag,
                            position=Pt(0,0),
                            points=windshield_pts,
                            xkwargs={'fill' : 'lightgray'})
        self.comps.append(car_windshield)

        head_light_color = "yellow"
        hl_hight = .06
        hl_width = 4*hl_hight
        hl_inset = hl_width*.1
        hl_fw_pt = Pt(0,hl_hight)
        hl_rw_pt = Pt(hl_width,0)
        fd_light_pt = Pt(hl_inset,1-hl_hight)
        fd_light_pts = [fd_light_pt, fd_light_pt+hl_fw_pt,
                        fd_light_pt+hl_fw_pt+hl_rw_pt,
                        fd_light_pt+hl_rw_pt]

        front_driver_light = BlockPolygon(container=self,
                        color=head_light_color,
                        points=fd_light_pts
                        )
        self.comps.append(front_driver_light)
        fp_light_pt = Pt(1-hl_width-hl_inset,1-hl_hight)
        fp_light_pts = [fp_light_pt, fp_light_pt+hl_fw_pt,
                        fp_light_pt+hl_fw_pt+hl_rw_pt,
                        fp_light_pt+hl_rw_pt]

        front_pass_light = BlockPolygon(container=self,
                        color=head_light_color,
                        points=fp_light_pts
                        )
        self.comps.append(front_pass_light)

        rear_light_color = "red"
        rl_radius = .05
        rl_dia = 2*rl_radius
        rl_inset = rl_dia*.1
        rl_fw_pt = Pt(0,rl_radius)
        rl_rw_pt = Pt(rl_dia,0)
        rd_light_pt = Pt(rl_inset, 0)
        rd_light_pts = [rd_light_pt, rd_light_pt+rl_fw_pt,
                        rd_light_pt+rl_fw_pt+rl_rw_pt,
                        rd_light_pt+rl_rw_pt]

        rear_driver_light = BlockPolygon(container=self,
                        color=rear_light_color,
                        points=rd_light_pts
                        )
        self.comps.append(rear_driver_light)
        
        rp_light_pt = Pt(1-rl_dia-rl_inset, 0)
        rp_light_pts = [rp_light_pt, rp_light_pt+rl_fw_pt,
                        rp_light_pt+rl_fw_pt+rl_rw_pt,
                        rp_light_pt+rl_rw_pt]

        rear_pass_light = BlockPolygon(container=self,
                        color=rear_light_color,
                        points=rp_light_pts
                        )
        self.comps.append(rear_pass_light)
Ejemplo n.º 6
0
 def __init__(self, track, **kwargs):
     """ Setup Road object
      """
     super().__init__(track, road_type=RoadType.STRAIT, **kwargs)
     if self.width is None:
         self.width = self.get_road_width()
     if self.height is None:
         self.height = self.get_road_length()
     xkwargs = self.xkwargs
     if xkwargs is None:
         xkwargs = {'fill': 'black'}
     strait = BlockPolygon(container=self,
                           tag=self.tag,
                           position=Pt(0, 0),
                           points=[Pt(0, 0),
                                   Pt(0, 1),
                                   Pt(1, 1),
                                   Pt(1, 0)],
                           xkwargs=xkwargs)
     self.comps.append(strait)
     median_width = self.median_width
     median_x = self.median_x
     off_edge = self.off_edge
     edge_width = self.edge_width
     median_strip = BlockPolygon(container=self,
                                 tag=self.tag,
                                 position=Pt(0, 0),
                                 points=[
                                     Pt(median_x - median_width, 0),
                                     Pt(median_x - median_width, 1),
                                     Pt(median_x + median_width, 1),
                                     Pt(median_x + median_width, 0)
                                 ],
                                 xkwargs={
                                     'fill': 'yellow',
                                     'width': 2
                                 })
     self.comps.append(median_strip)
     left_edge = BlockPolygon(container=self,
                              tag=self.tag,
                              position=Pt(0, 0),
                              points=[
                                  Pt(off_edge, 0),
                                  Pt(off_edge, 1),
                                  Pt(off_edge + edge_width, 1),
                                  Pt(off_edge + edge_width, 0)
                              ],
                              xkwargs={
                                  'fill': 'white',
                                  'width': 2
                              })
     self.comps.append(left_edge)
     right_edge = BlockPolygon(container=self,
                               tag=self.tag,
                               position=Pt(0, 0),
                               points=[
                                   Pt(1 - off_edge, 0),
                                   Pt(1 - off_edge, 1),
                                   Pt(1 - off_edge - edge_width, 1),
                                   Pt(1 - off_edge - edge_width, 0)
                               ],
                               xkwargs={
                                   'fill': 'white',
                                   'width': 2
                               })
     self.comps.append(right_edge)