Beispiel #1
0
 def add_walls(self, fColor=pm.Color(1.0, 0.0, 0.0)):
     if self.isRect_:
         return self.add_rectangular_walls(fColor=fColor)
     xleft, yleft, wtheta, hlen = self.sample_walls()
     walls = self._create_walls(xleft, yleft, (-wtheta, wtheta, 180 - wtheta),
                                (hlen, hlen, hlen), fColor=fColor)
     return walls
Beispiel #2
0
    def add_rectangular_walls(self, fColor=pm.Color(1.0, 0.0, 0.0)):
        #define the extents within which walls can be put.
        hlen = np.floor(self.wlmn_ + self.rand_.rand() *
                        (self.wlmx_ - self.wlmn_))
        vlen = np.floor(self.wlmn_ + self.rand_.rand() *
                        (self.wlmx_ - self.wlmn_))
        topxmx = self.xSz_ - (hlen + self.wth_)
        topymx = self.ySz_ - (vlen + self.wth_)
        xleft = np.floor(self.rand_.rand() * topxmx)
        ytop = np.floor(self.rand_.rand() * topymx)
        walls = self._create_walls(xleft,
                                   ytop, (0, 90, 180),
                                   (hlen - self.wth_, vlen, hlen - self.wth_),
                                   fColor=fColor)

        #define the walls
        #wallhordef = pm.walldef(sz=gm.Point(hlen, self.wth_), fColor=fColor)
        #wallverdef = pm.walldef(sz=gm.Point(self.wth_, vlen), fColor=fColor)
        #self.world_.add_object(wallverdef, initpos=gm.Point(xleft, ytop))
        #self.world_.add_object(wallverdef, initpos=gm.Point(xleft + hlen - self.wth_, ytop))
        #self.world_.add_object(wallhordef, initpos=gm.Point(xleft, ytop))
        #self.world_.add_object(wallhordef, initpos=gm.Point(xleft, ytop + vlen))
        #self.pts = [gm.Point(xleft, ytop)]
        #self.whl_, self.wvl_ = hlen, vlen
        return walls
Beispiel #3
0
def create_multiple_ball_world_gray():
	wThick = 30
	world = pm.World(xSz=640, ySz=480)
	bDef1  = pm.BallDef(fColor=pm.Color(0.5,0.5,0.5), radius=20)
	bDef2  = pm.BallDef(fColor=pm.Color(1.0,1.0,0.0), radius=20)
	xLength, yLength = 550, 400
	wallHorDef = pm.WallDef(sz=gm.Point(xLength, wThick), fColor=pm.Color(0.5,0.5,0.5))
	wallVerDef = pm.WallDef(sz=gm.Point(wThick, yLength), fColor=pm.Color(0.5,0.5,0.5))
	xLeft, yTop = 30, 30
	world.add_object(wallVerDef, initPos=gm.Point(xLeft, yTop))
	world.add_object(wallVerDef, initPos=gm.Point(xLeft + xLength -wThick, yTop))
	#Horizontal Wall
	world.add_object(wallHorDef, initPos=gm.Point(xLeft, yTop))
	world.add_object(wallHorDef, initPos=gm.Point(xLeft, yTop + yLength))
	world.add_object(bDef1, initPos=gm.Point(200,200))
	world.add_object(bDef2, initPos=gm.Point(400,210))
	im = world.generate_image()	
	return im, world	
Beispiel #4
0
    def add_balls(self):
        #generate ball definitions
        allr, allpos = [], []
        for i in range(self.numBalls_):
            placeflag = True
            while placeflag:
                #randomly sample the radius of the ball
                r = int(
                    np.floor(self.bmn_ + self.rand_.rand() *
                             (self.bmx_ - self.bmn_)))
                bdef = pm.BallDef(radius=r, fColor=pm.Color(0.5, 0.5, 0.5))
                #find a position to keep the ball
                '''
					if self.isrect_:
						xleft, ytop = self.pts[0].x_asint(), self.pts[0].y_asint()
						#xmn  = xleft + 2 * r + self.wth_
						#ymn  = ytop  + 2 * r + self.wth_
						#xmx  = xleft + self.whl_ - self.wth_ - 2 * r
						#ymx  = ytop  + self.wvl_ - self.wth_ - 2 * r
						xmn  = xleft + r + self.wth_ + 2 #give some margin
						ymn  = ytop  + r + self.wth_ + 2
						xmx  = xleft + self.whl_ - self.wth_ - r - 2
						ymx  = ytop  + self.wvl_ - self.wth_ - r - 2
						xloc = int(np.floor(xmn + (xmx - xmn) * self.rand_.rand()))
						yloc = int(np.floor(ymn + (ymx - ymn) * self.rand_.rand()))
					else:
					'''
                findflag = True
                count = 0
                while findflag:
                    pt, isvalid, md = self.find_point_within_lines(
                        r + self.wth_ + 2)  #2 is safety margin
                    count += 1
                    if isvalid:
                        findflag = False
                    if count >= 500:
                        print "failed to find a point to place the ball"
                        pdb.set_trace()
                if self.verbose_ > 0:
                    print("ball at (%f, %f), dist: %f" % (pt.x(), pt.y(), md))
                xloc, yloc = pt.x_asint(), pt.y_asint()
                pt = gm.Point(xloc, yloc)
                #determine if the ball can be placed at the chosen position or not
                isok = True
                for j in range(i):
                    dist = pt.distance(allpos[j])
                    if self.verbose_ > 0:
                        print("placement dist:", dist)
                    isok = isok and dist > (allr[j] + r)
                if isok:
                    placeflag = False
                    allr.append(r)
                    allpos.append(pt)
            self.world_.add_object(bdef, initPos=gm.Point(xloc, yloc))
        return allpos
Beispiel #5
0
def create_world_diamond():
	world = pm.World(xSz=640, ySz=480)
	pt1   = gm.Point(50, 240)
	pt2   = gm.Point(300, 40)
	pt3   = gm.Point(550, 240)
	pt4   = gm.Point(300, 440)
	walls = pm.create_cage([pt1, pt2, pt3, pt4], wThick=20)
	for w in walls:
		world.add_object(w)

	bDef  = pm.BallDef(fColor=pm.Color(0.5,0.5,0.5))
	world.add_object(bDef, initPos=gm.Point(200,200))
	im = world.generate_image()	
	return im, world	
Beispiel #6
0
def create_ball_world():
	world = pm.World(xSz=640, ySz=480)
	bDef  = pm.BallDef()
	bDef2 = pm.BallDef(fColor=pm.Color(0.0,0.0,1.0))
	wallHorDef = pm.WallDef(sz=pm.Point(600, 4))
	wallVerDef = pm.WallDef(sz=pm.Point(4, 450))
	#Horizontal Wall
	world.add_object(wallHorDef, initPos=pm.Point(20,20))
	world.add_object(wallHorDef, initPos=pm.Point(20,470))
	world.add_object(wallVerDef, initPos=pm.Point(20,20))
	world.add_object(wallVerDef, initPos=pm.Point(616,20))
	world.add_object(bDef, initPos=pm.Point(200,200))
	world.add_object(bDef2, initPos=pm.Point(400,400))
	im = world.generate_image()	
	return im, world	
Beispiel #7
0
 def add_walls(self, xleft=20, yleft=20, hLen=None, vLen=None,
               fColor=pm.Color(1.0, 0.0, 0.0)):
     if hLen is None:
         hLen = self.wlen_
     if vLen is None:
         vLen = self.wlen_
     wtheta = self.wtheta_
     if type(wtheta) == list:
         th1, th2, th3 = wtheta
     else:
         th1, th2, th3 = -wtheta, wtheta, 180 - wtheta
     th1, th2, th3 = fix_theta_range(th1), fix_theta_range(th2), fix_theta_range(th3)
     walls = self._create_walls(xleft, yleft, (th1, th2, th3),
                                (vLen, hLen, vLen), fColor=fColor)
     return walls
Beispiel #8
0
 def add_balls(self):
     for i in range(self.numballs_):
         bdef = pm.BallDef(radius=self.bsz_, fColor=pm.Color(0.5, 0.5, 0.5))
         self.world_.add_object(bdef, initPos=self.bloc_[i])