How to use the fluids.assets.shape.Shape function in fluids

To help you get started, we’ve selected a few fluids examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github BerkeleyAutomation / Urban_Driving_Simulator / fluids / assets / terrain.py View on Github external
from fluids.assets.shape import Shape

class Terrain(Shape):
    def __init__(self, **kwargs):
        Shape.__init__(self, color=(0xfd,0xF8,0xef), **kwargs)
github BerkeleyAutomation / Urban_Driving_Simulator / fluids / assets / shape.py View on Github external
def get_relative(self, other, offset=(0,0)):
        if type(other) == tuple:
            x, y, angle = other
        else:
            x, y, angle = other.x, other.y, other.angle
        new_points = np.array(self.shapely_obj.exterior.coords) - np.array([x, y])
        new_points = new_points.dot(rotation_array(-angle))
        new_points = new_points + np.array(offset)
        shape = Shape(points=new_points[:,:2], color=self.color)
        shape.__class__ = type(self)
        return shape
github BerkeleyAutomation / Urban_Driving_Simulator / fluids / assets / car.py View on Github external
from fluids.utils import PIDController, fluids_assert
from fluids.obs import *
from fluids.consts import *


def integrator(state, t, steer, acc, lr, lf):
    x, y, vel, angle = state

    beta = np.arctan((lr / (lf + lr) * np.tan(steer)))
    dx = vel * np.cos(angle + beta)
    dy = vel * -np.sin(angle + beta)
    dangle = vel / lr * np.sin(beta)
    dvel = acc
    return dx, dy, dvel, dangle

class Car(Shape):
    def __init__(self, vel=0, mass=400, max_vel=5,
                 planning_depth=20, **kwargs):
        from fluids.assets import Lane, Car, Pedestrian, TrafficLight, Terrain, Sidewalk, PedCrossing
        collideables = [Lane,
                        Car,
                        Pedestrian,
                        TrafficLight,
                        Terrain,
                        Sidewalk,
                        PedCrossing]
        Shape.__init__(self,
                       collideables=collideables,
                       color=(0x1d,0xb1,0xb0),#769BB0
                       xdim=70,
                       ydim=35,
                       **kwargs)
github BerkeleyAutomation / Urban_Driving_Simulator / fluids / assets / traffic_light.py View on Github external
from fluids.assets.shape import Shape
from fluids.consts import *




class TrafficLight(Shape):
    def __init__(self, init_color="red", **kwargs):
        color = {"red":RED,
                 "green":GREEN,
                 "yellow":YELLOW}[init_color]
        self.timer = {"red":0,
                      "green":200,
                      "yellow":350}[init_color]

        Shape.__init__(self, xdim=20, ydim=60, color=color, **kwargs)


    def step(self, action):
        self.timer += 1
        if self.timer < 200:
            self.color = RED
        elif self.timer < 350:
github BerkeleyAutomation / Urban_Driving_Simulator / fluids / assets / waypoint.py View on Github external
p2 = [x1 - .3*distance_between_points*np.cos(a1),
          y1 + .3*distance_between_points*np.sin(a1)]
    p3 = [x1,y1]

    first_point = interpolate(p0,p1,p2,p3,0)
    res_path = [first_point]
    for t in np.arange(0,1,.001):
        new_point = interpolate(p0,p1,p2,p3,t)
        old_point = res_path[-1]
        if (new_point[0] - old_point[0])**2 \
           + (new_point[1] - old_point[1])**2 > smooth_level:
            res_path.append(new_point)
    res_path.append([x1, y1])
    return res_path

class Waypoint(Shape):
    def __init__(self, x, y, owner=None, angle=0, nxt=None, **kwargs):

        self.radius = 0
        self.nxt    = nxt if nxt else []
        self.owner  = owner
        points = [(x-1, y-1),
                  (x+1, y-1),
                  (x+1, y+1),
                  (x-1, y+1)]


        super(Waypoint, self).__init__(angle=angle,
                                       points=points,
                                       color=(0, 255, 255),
                                       **kwargs)