particlescv2.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:python-opencv2 作者: bunkahle 项目源码 文件源码
def Draw(self, display):
        if (self.pos[0] > 10000) or (self.pos[1] > 10000) or (self.pos[0] < -10000) or (self.pos[1] < -10000):
            return
        if self.drawtype == DRAWTYPE_POINT:  # Point
            # pygame.draw.circle(display, self.colour, self.pos, 0)
            # cv.Circle(display, (int(self.pos[0]), int(self.pos[1])), 0, self.colour)
            cv2.circle(display ,(int(self.pos[0]), int(self.pos[1])), 0, self.colour)

        elif self.drawtype == DRAWTYPE_CIRCLE:  # Circle
            # pygame.draw.circle(display, self.colour, self.pos, self.radius)
            # cv.Circle(display, (int(self.pos[0]), int(self.pos[1])), int(self.radius), self.colour, -1)
            cv2.circle(display ,(int(self.pos[0]), int(self.pos[1])), int(self.radius), self.colour, -1)

        elif self.drawtype == DRAWTYPE_LINE:
            if self.length == 0.0:
                # pygame.draw.circle(display, self.colour, self.pos, 0)
                # cv.Circle(display, (int(self.pos[0]), int(self.pos[1])), 0, self.colour)
                cv2.circle(display ,(int(self.pos[0]), int(self.pos[1])), 0, self.colour)
            else:
                velocitymagoverlength = math.sqrt(self.velocity[0]**2 + self.velocity[1]**2) / self.length
                linevec = [(self.velocity[0] / velocitymagoverlength), (self.velocity[1] / velocitymagoverlength)]
                endpoint = [self.pos[0] + linevec[0], self.pos[1] + linevec[1]]
                # pygame.draw.aaline(display, self.colour, self.pos, endpoint)
                # cv.Line(display, (int(self.pos[0]), int(self.pos[1])), (int(endpoint[0]), int(endpoint[1])), self.colour, lineType=cv.CV_AA)
                cv2.line(display, (int(self.pos[0]), int(self.pos[1])), (int(endpoint[0]), int(endpoint[1])), self.colour, lineType=cv2.CV_AA)

        elif self.drawtype == DRAWTYPE_SCALELINE:  # Scaling line (scales with velocity)
            endpoint = [self.pos[0] + self.velocity[0], self.pos[1] + self.velocity[1]]
            # pygame.draw.aaline(display, self.colour, self.pos, endpoint)
            # cv.Line(display, (int(self.pos[0]), int(self.pos[1])), (int(endpoint[0]), int(endpoint[1])), self.colour, lineType=cv.CV_AA)
            cv2.line(display, (int(self.pos[0]), int(self.pos[1])), (int(endpoint[0]), int(endpoint[1])), self.colour, lineType=cv2.CV_AA)

        elif self.drawtype == DRAWTYPE_BUBBLE:  # Bubble
            if self.radius >= 1.0:
                # pygame.draw.circle(display, self.colour, self.pos, self.radius, 1)
                # cv.Circle(display, (int(self.pos[0]), int(self.pos[1])), int(self.radius), self.colour, 1)
                cv2.circle(display ,(int(self.pos[0]), int(self.pos[1])), int(self.radius), self.colour, int(self.radius))
            else:  # Pygame won't draw circles with thickness < radius, so if radius is smaller than one don't bother trying to set thickness
                # pygame.draw.circle(display, self.colour, self.pos, self.radius)
                # cv.Circle(display, (int(self.pos[0]), int(self.pos[1])), int(self.radius), self.colour)
                cv2.circle(display ,(int(self.pos[0]), int(self.pos[1])), int(self.radius), self.colour)

        elif self.drawtype == DRAWTYPE_IMAGE:  # Image
            # size = self.image.get_size()
            # display.blit(self.image, (self.pos[0] - size[1], self.pos[1] - size[1]))
            size = self.image.shape
            x, y = self.pos[0] - size[1], self.pos[1] - size[1]
            # print x, y
            self.Paste(display, self.image, (x, y))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号