Beispiel #1
0
 def render( self, svg ):
   
     bar_group = group.Group()
     
     if self.shadow and self.length > 0:
         shadow_paint = Paint()
         shadow_paint.fill = "#BBB"
         shadow_paint.fill_opacity = 0.6
         
         shadow = rect.Rect()    
         shadow.x = self.x
         shadow.y = self.y - 3
         shadow.width = self.length + 3
         shadow.height = self.width
         
         utils.copy_object( shadow_paint, shadow )
         
         bar_group.append( shadow )
       
     r = rect.Rect()    
     r.x = self.x
     r.y = self.y
     r.width = self.length
     r.height = self.width
     
     utils.copy_object( self.paint, r )
     bar_group.append( r )
     
     svg.append( bar_group )
Beispiel #2
0
    def getClusters(contours, i_w, i_h, thresh):
        boxes, clusters = [], []
        for c in contours:
            x, y, w, h = cv2.boundingRect(c)
            if w * h > i_w * i_h * thresh:
                clusters.append(rect.Rect(x, y, w, h))
            else:
                boxes.append(rect.Rect(x, y, w, h))

        clusters += rect.Rect.cluster(boxes)
        clusters = [
            clusters[c] for c in range(len(clusters))
            if clusters[c].area > i_w * i_h * thresh
        ]

        distThresh = ((i_w + i_h) / 2) * (thresh / 2)
        final = []
        for c1 in clusters:
            tooClose = False
            for c2 in clusters:
                if c1 != c2 and c1.dist(c2) < distThresh:
                    r = c1.maxRect(c2)
                    tooClose = True
                    if r not in final: final.append(r)
                    break
            if tooClose == False: final.append(c1)
        return final
    def __init__(self, width, height):
        self.width = width
        self.height = height

        self.sky = rect.Rect(0, 0, width, height, (20, 235, 250))
        self.grass = rect.Rect(0, 640, width, 320, (120, 190, 50))
        self.mountain1 = mountain.Mountain(200, 80, 640, 640, (50, 60, 160))
        self.mountain2 = mountain.Mountain(400, 120, 500, 640, (5, 15, 120))
        self.house = house.House(800, 540, 100, 100)
        self.house2 = house.House(850, 540, 150, 150)
Beispiel #4
0
    def get_AABB(self):
        '''Returns a local-coordinates Axis aligned Bounding Box'''

        v = self._vertex_list.vertices
        x = v[0], v[2], v[4], v[6]
        y = v[1], v[3], v[5], v[7]
        return rect.Rect(min(x), min(y), max(x) - min(x), max(y) - min(y))
Beispiel #5
0
    def __init__(self, values, vertical=False, grid=False):

        r = rect.Rect()
        r.x = 0
        r.y = 0
        r.width = 10
        r.height = 10
        r.rx = 0

        b = Bars(r, values, vertical)

        p = Paint()
        p.fill = "red"
        p.stroke = "black"
        p.stroke_width = 2

        if vertical:
            axisx_length = b.viewport.h
            axisy_length = b.viewport.w
        else:
            axisx_length = b.viewport.w
            axisy_length = b.viewport.h

        axis = (AxisX(axisx_length, 25, None,
                      p), AxisY(axisy_length, 25, None, p))

        Chart.__init__(self, b.viewport, axis, grid)

        self.append(b)
Beispiel #6
0
    def get_box( self ):
        """Returns the box that contains the menu item.

        :rtype: (x1,x2,y1,y2)
        """
        width = self.get_item_width ()
        height = self.get_item_height ()
        if self.item_halign == CENTER:
            x_diff = - width / 2
        elif self.item_halign == RIGHT:
            x_diff = - width
        elif self.item_halign == LEFT:
            x_diff = 0
        else:
            raise Exception("Invalid halign: %s" % str(self.item_halign) )

        y_diff = - height/ 2

        x1 = self.get_item_x() + x_diff
        y1 = self.get_item_y() + y_diff
#        x1 += self.parent.x
#        y1 += self.parent.y
#        x2 = x1 + width
#        y2 = y1 + height
#        return (x1,y1,x2,y2)
        return rect.Rect(x1,y1,width,height)
Beispiel #7
0
    def __init__(self, values):

        r = rect.Rect()
        r.x = 0
        r.y = 0
        r.width = 10
        r.height = 10
        r.rx = 0

        b = Bars(r, values, True)

        p = Paint()
        p.fill = "red"
        p.stroke = "grey"
        p.stroke_width = 2

        axisx_length = 100
        axisy_length = len(values)

        axis = (AxisX(axisx_length, 25, None,
                      p), AxisY(axisy_length, 1, None, p))

        Chart.__init__(self, b.viewport, axis)

        #grid = Grid( b.viewport, 25, 1, p )
        #self.append(grid)

        self.append(b)
Beispiel #8
0
    def __init__(self, x, y, width, height):
        self.x = x
        self.y = y
        self.width = width
        self.height = height

        self.walls = rect.Rect(x + width//6, y + height//3, width//3*2, height//3*2, (224,204,74))
        self.roof = mountain.Mountain(x + width//2, y, width, y + height//3, (0, 0, 0))
Beispiel #9
0
    def load_level(self, filename, tile_size):
        "Loads the level that corresponds to the given filename and initializes the rects"

        # Parse the level file
        self.level.parse_file(filename)

        # Create a rect for Pac-Man
        self.pacman_rect = rect.Rect(self.level.pacman_home,
                                     (tile_size, tile_size))

        # Total number of pellets originally for this level
        self.total_pellets = self.level.num_pellets

        # Create the ghost rects
        for i in range(GHOSTS):
            self.ghost_rect[i] = rect.Rect(self.level.ghost_home[i],
                                           (tile_size, tile_size))
Beispiel #10
0
    def motion_notify_event(self, widget, event):
        x = int(event.x)
        y = int(event.y)
        image_width = self.image.get_allocation().width
        image_height = self.image.get_allocation().height

        if self.select_state == SelectState.DRAG:
            self.select_area.left = clip(0, x - self.drag_x,
                                         image_width - self.select_area.width)
            self.select_area.top = clip(0, y - self.drag_y,
                                        image_height - self.select_area.height)
            self.queue_draw()
        elif self.select_state == SelectState.RESIZE:
            if self.resize_direction in [
                    rect.Edge.SE, rect.Edge.E, rect.Edge.NE
            ]:
                right = x - self.drag_x
                self.select_area.width = right - self.select_area.left

            if self.resize_direction in [
                    rect.Edge.SW, rect.Edge.S, rect.Edge.SE
            ]:
                bottom = y - self.drag_y
                self.select_area.height = bottom - self.select_area.top

            if self.resize_direction in [
                    rect.Edge.SW, rect.Edge.W, rect.Edge.NW
            ]:
                left = x - self.drag_x
                self.select_area.width = self.select_area.right() - left
                self.select_area.left = left

            if self.resize_direction in [
                    rect.Edge.NW, rect.Edge.N, rect.Edge.NE
            ]:
                top = y - self.drag_y
                self.select_area.height = self.select_area.bottom() - top
                self.select_area.top = top

            self.select_area.normalise()
            image = rect.Rect(0, 0, image_width, image_height)
            self.select_area = self.select_area.intersection(image)
            self.queue_draw()

        elif self.select_state == SelectState.WAIT:
            window = self.image.get_window()
            direction = self.select_area.which_corner(select_corner, x, y)

            if self.select_visible and \
                direction != rect.Edge.NONE:
                window.set_cursor(resize_cursor_shape[direction])

            elif self.select_visible and \
                self.select_area.includes_point(x, y):
                window.set_cursor(drag_cursor_shape)

            else:
                window.set_cursor(None)
Beispiel #11
0
    def __init__(self):
        r = rect.Rect()
        r.x = 1.0
        r.y = 1.0
        r.width = 1.0
        r.height = 1.0
        r.rx = 20

        self.append(r)
Beispiel #12
0
	def __init__(self, width, height):
		self.mWidth = width
		self.mHeight = height

		self.mSun = sun.Sun( (247, 238, 101), 175, 125, 50)
		self.mSky = rect.Rect((101, 233, 247), 0, 0, 900, 450)
		self.mGrass = rect.Rect((86, 219, 110), 0, 450, 900, 350)
		self.mTree1 = tree.Tree((143, 102, 26), (71, 153, 17), 650, 325, 75, 125)
		self.mTree2 = tree.Tree((168, 141, 50), (168, 50, 100), 800, 375, 50, 75)
		adult = 'adult'
		child = 'child'
		self.mParent1 = person.Person(adult, 225, 300 )
		self.mParent2 = person.Person(adult, 100, 300)
		self.mChild1 = person.Person(child, 350, 350)
		self.mChild2 = person.Person(child, 450, 350)
		self.mChild3 = person.Person(child, 550, 350)
		self.mCloud1 = cloud.Cloud(400, 50, 150, 100)
		self.mCloud2 = cloud.Cloud(650, 70, 200, 100)
		self.mBlanket = blanket.Blanket((219, 50, 107), 100, 500, 350, 150)
		return
Beispiel #13
0
    def get_selection(self):
        """Return a rect.Rect for the selection, or None if no selection
        is active.
        """
        if not self.select_visible:
            return None

        return rect.Rect(self.select_area.left / scale,
                         self.select_area.top / scale,
                         self.select_area.width / scale,
                         self.select_area.height / scale)
Beispiel #14
0
    def get_selection(self):
        """Return a rect.Rect for the selection, or None if no selection
        is active.
        """
        if not self.select_visible:
            return None

        image_width = self.image.get_allocation().width
        image_height = self.image.get_allocation().height
        return rect.Rect(1000 * self.select_area.left / image_width,
                         1000 * self.select_area.top / image_height,
                         1000 * self.select_area.width / image_width,
                         1000 * self.select_area.height / image_height)
Beispiel #15
0
    def focus_cb(self, widget, data=None):
        self.preview.set_live(False)

        if self.focus_window:
            self.focus_window.present()
        else:
            sel = self.preview.get_selection() or rect.Rect(
                0, 0, 1060 * 4, 706 * 4)

            self.focus_window = focus.Focus(self.camera, sel)
            self.focus_window.connect('destroy', self.focus_destroy_cb)
            self.focus_window.set_modal(True)
            self.focus_window.show()
Beispiel #16
0
    def make_level(self, items=None, MAX_ENEMIES_PER_ROOM=0):
        #self.rooms = []
        num_rooms = 0
        for r in range(self.max_rooms):
            w = random.randint(self.room_min_size, self.room_max_size)
            h = random.randint(self.room_min_size, self.room_max_size)
            x = random.randint(1, self.level_width - w - 1)
            y = random.randint(1, self.level_height - h - 1)
            new_room = rect.Rect(x, y, w, h)
            failed = False
            for other_room in self.rooms:
                if new_room.intersect(other_room):
                    failed = True
                    break
            if not failed:
                self.create_room(new_room)
                (new_x, new_y) = new_room.center()
                if num_rooms == 0:
                    try:
                        self.entities[0].x = new_x
                        self.entities[0].y = new_y
                    except:
                        print('No entities')
                        pass
                    try:
                        items[0].x = new_x + 1
                        items[0].y = new_y + 1
                    except:
                        print('No items')
                        pass
                else:
                    (prev_x, prev_y) = self.rooms[num_rooms-1].center()
                    if random.randint(0, 2) == 1:
                        self.create_h_tunnel(prev_x, new_x, prev_y)
                        self.create_v_tunnel(prev_y, new_y, new_x)
                    else:
                        self.create_v_tunnel(prev_y, new_y, prev_x)
                        self.create_h_tunnel(prev_x, new_x, new_y)
                self.rooms.append(new_room)
                if MAX_ENEMIES_PER_ROOM != 0:
                    for i in range(MAX_ENEMIES_PER_ROOM):
                        x_coord = random.randint(x+1, x+w-1)
                        y_coord = random.randint(y+1, y+h-1)
                        if not (x_coord, y_coord) in self.entities:
                            self.entities.append((x_coord, y_coord))


                num_rooms += 1
Beispiel #17
0
        def create_collision_buffer(parms):
            buffer_size = 10  # pixels

            def get_buffer_val(self, parms):
                if len(parms) == 1:
                    return parms[0] * buffer_size
                elif len(parms) == 2:
                    return self.gnav(parms[1]) + (parms[0] * buffer_size)
                else:
                    return parms[1].gnav(parms[2]) + (parms[0] * buffer_size)

            ## create_collision_buffer()
            if parms:
                left = get_buffer_val(self, parms[0])
                top = get_buffer_val(self, parms[1])
                width = get_buffer_val(self, parms[2])
                height = get_buffer_val(self, parms[3])
                self.collision_buffer = rect_lib.Rect((left, top, width, height))
Beispiel #18
0
    def get_rect(self):
        '''Get a cocos.rect.Rect for this sprite.

        Note that this rect's position is most likely NOT the same
        as the Sprite's position - in fact by default the rect's
        center is the Sprite's position. If you move the rect around
        and wish to reflect this change in the Sprite, you will probably
        have to do something like (again with the default image anchor
        in the center)::

            rect = sprite.get_rect()
            rect.midbottom = (0, 100)
            sprite.position = rect.center

        Returns a cocos.rect.Rect instance.
        '''
        x, y = self.position
        x -= self.image_anchor_x
        y -= self.image_anchor_y
        return rect.Rect(x, y, self.width, self.height)
Beispiel #19
0
    def __init__(self, camera, selection):
        Gtk.Window.__init__(self)
        self.connect('destroy', self.destroy_cb)

        left = selection.left + int(selection.width / 2) - 400
        top = selection.top + int(selection.height / 2) - 300

        self.times = []

        camera.focus_area(rect.Rect(0, 0, 800, 600))

        self.image = Gtk.Image()
        self.add(self.image)
        self.image.show()

        self.image.set_app_paintable(True)

        self.frame_buffer = None
        self.preview_timeout = GLib.timeout_add(frame_timeout, self.live_cb)
        self.fps_timeout = GLib.timeout_add(1000, self.fps_cb)
        self.camera = camera
        self.frame = 0
Beispiel #20
0
    def __init__(self, camera):
        """
        Startup.

        camera -- the camera to display, see camera.py

        The preview starts at 640x426 pixels, this may change if the camera
        turns out to have a different size for its preview image.
        """

        gtk.EventBox.__init__(self)

        self.image = gtk.Image()
        self.add(self.image)
        self.image.show()

        # start with a blank 640x426 image, we overwrite this with jpg from
        # the camera during live preview
        self.pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, 
                                     False, 8, 640, 426)
        self.image.set_from_pixbuf(self.pixbuf)
        self.image.set_app_paintable(True)

        self.preview_timeout = 0
        self.camera = camera
        self.frame = 0
        self.select_visible = False
        self.select_area = rect.Rect(10, 10, 100, 100)
        self.select_state = SelectState.WAIT
        self.resize_direction = rect.Edge.N
        self.drag_x = 0
        self.drag_y = 0

        self.image.connect_after('expose-event', self.expose_event)
        self.add_events(gtk.gdk.POINTER_MOTION_MASK)
        self.connect('button-press-event', self.button_press_event)
        self.connect('motion-notify-event', self.motion_notify_event)
        self.connect('button-release-event', self.button_release_event)
Beispiel #21
0
    def __init__(self, camera):
        """
        Startup.
        camera -- the camera to display, see camera.py
        The preview starts at 640x426 pixels, this may change if the camera
        turns out to have a different size for its preview image.
        """

        Gtk.EventBox.__init__(self)
        self.times = []

        self.image = Gtk.Image()
        self.add(self.image)
        self.image.show()

        self.image.set_app_paintable(True)

        self.frame_image = None
        self.frame_buffer = None
        self.preview_timeout = 0
        self.camera = camera
        self.frame = 0
        self.select_visible = False
        self.select_area = rect.Rect(10, 10, 100, 100)
        self.select_state = SelectState.WAIT
        self.resize_direction = rect.Edge.N
        self.drag_x = 0
        self.drag_y = 0

        self.image.connect_after('draw', self.expose_event)
        self.add_events(Gdk.EventMask.POINTER_MOTION_MASK)
        self.connect('button-press-event', self.button_press_event)
        self.connect('motion-notify-event', self.motion_notify_event)
        self.connect('button-release-event', self.button_release_event)

        self.score = None
Beispiel #22
0
try:
    import dxvideo
    video_available = 1
    video_select_keys = '0123456789'
except ImportError:
    video_available = 0

linear = transition.Transition()

exports = [
    'Drawable', 'Text', 'Image', 'Fill', 'BulletedList', 'Anim', 'Interactive',
    'Video'
]

default_camera = rect.Rect(0, 0, 400, 0, 4.0 / 3.0)


class Element(object):
    def __str__(self):
        return '<animation element>'

    def __getattr__(self, name):
        if name == '_current_params' or name == '_params':
            raise AttributeError
        plist = [i[0] for i in getattr(self, '_current_params', self._params)]
        if name in plist:
            raise AttributeError, "'%s' element is not on stage; can't access '%s' parameter" % (
                self.__class__.__name__, name)
        else:
            raise AttributeError, "'%s' element has no '%s' parameter" % (
Beispiel #23
0
 def viewport(self):
     """Rect: The drawing area for rendering on the current target."""
     viewport = rect.Rect(0, 0, 0, 0)
     check_int_err(lib.SDL_RenderGetViewport(self._ptr, viewport._ptr))
     return viewport
Beispiel #24
0
 def get_rect(self):
     '''Get a cocos.rect.Rect for this sprite.'''
     x = -self.image_anchor_x
     y = -self.image_anchor_y
     return rect.Rect(x, y, self.width, self.height)
Beispiel #25
0
from helper import *
from rect import Rect

import rect
import math

world_w, world_h = (200, 100)
new_platforms = [
    rect.Rect(0, 50, 50, 5),
    rect.Rect(55, 10, 5, 100),
    rect.Rect(30, 0, 5, 40),
    rect.Rect(55, 40, 200, 5),
    rect.Rect(300, 45, 300, 5),
]
new_player = R(y=0, vy=0, x=10, vx=0)

new_game = R(platforms=new_platforms, player=new_player)

player_thickness = 5
platform_thickness = 5


def player_rect(player):
    return rect.Rect(player.x - player_thickness / 2,
                     player.y - player_thickness / 2, player_thickness,
                     player_thickness)


def intersection_direction(player_r, i):
    if i.w >= i.h:
        if abs(i.y - player_r.y) > player_r.h / 2: return 'N'
Beispiel #26
0
 def setUp(self):
     self.r = rect.Rect(10, 10, 10, 10)
Beispiel #27
0
def player_rect(player):
    return rect.Rect(player.x - player_thickness / 2,
                     player.y - player_thickness / 2, player_thickness,
                     player_thickness)
Beispiel #28
0
def test_Rect():
    cmp(rect.return_Rect(), (18, 4, 154, 150))
    rect.receive_Rect(rect.Rect(69, 43,  13,  89))
 def initRects(self):
     for i in range(10):
         r = rect.Rect(random.randrange(0, 1920), self.id_index)
         self.id_index += 1
         self.allGameObjects[self.id_index] = r