示例#1
0
 def _GenRangePoints(self):
     if (0 == self.rangeMode):
         self.rangePointA1 = point(1, 1)
         self.rangePointA2 = point(self.backGroundSize - self.rectSize - 1)
     else:
         self.rangePointA1 = point(-self.rectSize)
         self.rangePointA2 = point(self.backGroundSize)
示例#2
0
    def right(self):
        x1 = (self.mapSize - 1) * self.unit
        x2 = (self.mapSize) * self.unit
        y1 = (self.mapSize // 2 + self.road // 4) * self.unit
        y2 = (self.mapSize // 2 + self.road // 4 + 1) * self.unit

        self.sp = point(x1, y1)
        self.ep = point(x2, y2)
示例#3
0
    def left(self):
        x1 = 0 * self.unit
        x2 = 1 * self.unit
        y1 = (self.mapSize // 2 - self.road // 4 - 1) * self.unit
        y2 = (self.mapSize // 2 - self.road // 4) * self.unit

        self.sp = point(x1, y1)
        self.ep = point(x2, y2)
示例#4
0
    def down(self):
        x1 = (self.mapSize // 2 - self.road // 4 - 1) * self.unit
        y1 = (self.mapSize - 1) * self.unit
        x2 = (self.mapSize // 2 - self.road // 4) * self.unit
        y2 = (self.mapSize) * self.unit

        self.sp = point(x1, y1)
        self.ep = point(x2, y2)
示例#5
0
    def up(self):
        """ calculate the postion of the car from the upper bound."""
        x1 = (self.mapSize // 2 + self.road // 4) * self.unit
        x2 = (self.mapSize // 2 + self.road // 4 + 1) * self.unit
        y1 = 0 * self.unit
        y2 = 1 * self.unit

        self.sp = point(x1, y1)
        self.ep = point(x2, y2)
示例#6
0
def RandPos(rangePoint1, rangePoint2):
    assert type(rangePoint1) == type(rangePoint2)
    maxx = np.max([rangePoint1.x, rangePoint2.x])
    minx = np.min([rangePoint1.x, rangePoint2.x])
    maxy = np.max([rangePoint1.y, rangePoint2.y])
    miny = np.min([rangePoint1.y, rangePoint2.y])
    return point(random.randint(minx, maxx), random.randint(miny, maxy))
示例#7
0
 def _AddRandColorToRect(self):
     if 0 == self.rectColorMode:
         rectColor = RandColor()
         self.rectArray = RectAddColor(self.rectArray, rectColor)
     elif 1 == self.rectColorMode:
         rectColorArray = RandColorArray(self.rectSize)
         self.rectArray = RectAddColorArray(self.rectArray, rectColorArray)
     elif 2 == self.rectColorMode:
         rectColor = RandColor()
         rectColorArray = RandColorArray(self.rectSize - arr(4, 4))
         self.rectArray = RectAddColor(self.rectArray, rectColor)
         self.rectArray = ImposeRect(self.rectArray, rectColorArray,
                                     point(2, 2))
示例#8
0
 def __init__(self,
              location,
              all_light,
              Canvas=None,
              UNIT=10,
              size=100,
              RoadWidth=12):
     dire = {'up': 'down', 'down': 'up', 'left': 'right', 'right': 'left'}
     self.mapSize = size
     self.loc = location  # the car initial location
     self.direction = dire[self.loc]  # the direction of moving
     self.sp = point(0, 0)  # start point
     self.ep = point(0, 0)  # end point
     self.can_id = None
     self.road = RoadWidth
     self.can = Canvas
     self.unit = UNIT
     self.speed = self.unit
     intial_fun = {
         'up': self.up,
         'down': self.down,
         'left': self.left,
         'right': self.right
     }
     self.color = {
         'up': 'purple',
         'down': 'firebrick1',
         'left': 'blue4',
         'right': 'deep pink'
     }
     self.step_num = 1  # if step number > 100 delete the car from canvas.
     self.moveState = True
     self.all_light = all_light
     self.Dis_light = None
     # intial function:
     intial_fun[self.loc]()
     self.create()
     self.cal_distance_from_light()
def Geojsonify(data, Type='Point'):

    # Determine which function to use
    if Type == 'Point':
        return point(data)

    elif Type == 'LineString':
        return line_string(data)

    elif Type == 'Polygon':
        return polygon(data)

    else:
        print("Error: Type has to be either Point, LineString, or Polygon")  
    def __init__(self):
        super(traffic, self).__init__()
        self.UNIT = 10
        self.change = True
        self.car_list = []
        # self.time_stamp = 0
        self.speed = self.UNIT  # initial speed
        self.roadLen = 12  # self.UNIT
        self.size = 100
        self.canvas = tk.Canvas(self,
                                bg="white",
                                height=self.size * self.UNIT,
                                width=self.size * self.UNIT)
        roadV_light_size = (6, 2)  #(6 / 2, 2 / 2)
        roadH_light_size = (2, 6)  #(2 / 2, 6 / 2)

        self.road_point_NW = point(*((self.size / 2 - self.roadLen / 2),
                                     (self.size / 2 -
                                      self.roadLen / 2)))  # Northwest
        self.road_point_SW = point(*((self.size / 2 - self.roadLen / 2),
                                     (self.size / 2 +
                                      self.roadLen / 2)))  # Southwest
        self.road_point_NE = point(*((self.size / 2 + self.roadLen / 2),
                                     (self.size / 2 -
                                      self.roadLen / 2)))  # Northeast
        self.road_point_SE = point(*((self.size / 2 + self.roadLen / 2),
                                     (self.size / 2 +
                                      self.roadLen / 2)))  # southeast

        self.light_NW = light(
            point(self.road_point_NW.x - roadH_light_size[0],
                  self.road_point_NW.y), *roadH_light_size, self.canvas,
            self.UNIT, 'NW', 'red', 'L')
        self.light_SW = light(self.road_point_SW, *roadV_light_size,
                              self.canvas, self.UNIT, 'SW', 'green', 'L')
        self.light_SE = light(point(self.road_point_SE.x,
                                    self.size / 2), *roadH_light_size,
                              self.canvas, self.UNIT, 'SE', 'red', 'R')
        self.light_NE = light(
            point(self.size / 2, self.road_point_NE.y - roadV_light_size[1]),
            *roadV_light_size, self.canvas, self.UNIT, 'NE', 'green', 'R')
        self.lightList = (self.light_NW, self.light_SW, self.light_SE,
                          self.light_NE)
示例#11
0
def RandMov(posA, minMovDis, maxMovDis, rangePoint1, rangePoint2):
    minmx = minMovDis[0]
    maxmx = maxMovDis[0]
    minmy = minMovDis[1]
    maxmy = maxMovDis[1]
    maxx = np.max([rangePoint1.x, rangePoint2.x])
    minx = np.min([rangePoint1.x, rangePoint2.x])
    maxy = np.max([rangePoint1.y, rangePoint2.y])
    miny = np.min([rangePoint1.y, rangePoint2.y])
    Ax = posA.x
    Ay = posA.y
    while (1):
        mx = random.randint(minmx, maxmx)
        my = random.randint(minmy, maxmy)
        signx = random.randint(0, 1) * 2 - 1
        signy = random.randint(0, 1) * 2 - 1
        movex = signx * mx
        movey = signy * my
        Bx = Ax + movex
        By = Ay + movey
        if (minx < Bx < maxx and miny < By < maxy): break
    return point(Bx, By), arr([movex, movey])
示例#12
0
def RectAddColorArray(rectArray, colorArray):
    assert (rectArray.shape[0:2] == colorArray.shape[0:2])
    return ImposeRect(rectArray, colorArray, posPoint=point(0, 0))