Beispiel #1
0
    def runFinalScreen(self, won):
        pygame.mixer.music.fadeout(300)
    
        if won:
            texture = textures.Texture(data.filepath('youwon.png'))
            sound = pygame.mixer.Sound(data.filepath('funfair.ogg'))
        else:
            texture = textures.Texture(data.filepath('youfailed.png'))
            sound = pygame.mixer.Sound(data.filepath('ohnoes.ogg'))
        
        done = False
        glClearColor(0, 0, 0, 1)
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)
        
        clock = pygame.time.Clock()
        sound.play()
        elapsed = 0

        while not done:
            
            for e in pygame.event.get():
                if e.type == QUIT: sys.exit()
                if e.type != KEYDOWN: continue
                elif e.key == K_ESCAPE:
                    done = True
                    
            glClear(GL_COLOR_BUFFER_BIT)
            dt = clock.tick(60)
            
            if elapsed < 1.0:
                glColor(1, 1, 1, elapsed)
            elif elapsed > 5:
                glColor(1, 1, 1, ((8 - elapsed) / 3.0))
            else:
                glColor(1, 1, 1, 1)
                
            glPushMatrix()
            glTranslatef(0, 100, 0)
            texture.render()
            glPopMatrix()
            pygame.display.flip()
            
            if elapsed > 8:
                done = True
                
            elapsed += (dt / 1000.0)
Beispiel #2
0
    def __init__(self, position, color, num=20, speed=2, gravity=1., fade=.05):
        self.position = position
        self.color = list(color)
        self.gravity = gravity
        self.fade = fade

        self.spots = []
        for i in range(num):
            r = Matrix3.new_rotate(math.pi * 2 * random.random())
            m = speed + speed * random.random()
            self.spots.append((Point2(*position), r * Vector2(0, m)))

        if self.texture is None:
            filename = data.filepath(self.texture_file)
            t = self.__class__.texture = textures.Texture(filename)
            self.__class__.width = t.width
            self.__class__.height = t.height
            self.__class__.quad_list = glGenLists(1)
            glNewList(self.quad_list, GL_COMPILE)
            glTexCoord2f(0, 0)
            glVertex2f(0, 0)
            glTexCoord2f(1, 0)
            glVertex2f(t.width, 0)
            glTexCoord2f(1, 1)
            glVertex2f(t.width, t.height)
            glTexCoord2f(0, 1)
            glVertex2f(0, t.height)
            glEndList()
Beispiel #3
0
    def __init__(self):

        self.smash1 = pygame.mixer.Sound(data.filepath('smash1.ogg', 'sfx'))
        self.smash1played = False
        self.smash2 = pygame.mixer.Sound(data.filepath('smash2.ogg', 'sfx'))
        self.smash2played = False
        self.boing = pygame.mixer.Sound(data.filepath('jump.ogg', 'sfx'))
        self.numboings = 0
        self.boingsplayed = 0

        self.menaceloc = (275, 100)
        self.menacerot = False
        self.fluffyloc = (245, 100)
        self.bunnyloc = (160, 240)
        self.creditsalpha = 0
        self.alldone = False
        self.fadeincredits = False
        self.fadeouttime = False
        self.running = 0

        texture = textures.Texture(data.filepath('logo.png'))
        self.menace = texture.sub(214, 128 - 56, 512 - 214, 56)
        self.fluffy = texture.sub(77, 128 - 80, 202 - 77, 80 - 24)
        self.credits1 = texture.sub(60, 0, 238 - 60, 28)
        self.credits2 = texture.sub(238, 0, 512 - 238, 128 - 68)
        self.bunny = texture.sub(0, 128 - 95, 48, 95)
Beispiel #4
0
    def __init__(self):

        self.menumove = pygame.mixer.Sound(data.filepath(
            'menumove.ogg', 'sfx'))
        self.menuselect = pygame.mixer.Sound(
            data.filepath('menuselect.ogg', 'sfx'))

        texture = textures.Texture(data.filepath('menu.png'))
        self.menubg = texture  #.sub(0, 256, 1024, 768)
        self.loadingscreen = texture.sub(0, 0, 1024, 70)
        self.starguy = textures.TextureGrid(data.filepath('starguy.png'), 64,
                                            64).row(0)
        self.spinspeed = 25

        self.bg = textures.Texture(data.filepath('menu-back.png'))
        self.bgoffset = 0
        self.movingup = True
        self.fadein = True
Beispiel #5
0
    def __init__(self, location, map=None):
        i, j = self.location = location
        x, y = self.bottomleft = i * SCALE, j * SCALE
        self.left = x
        self.right = x + SCALE
        self.bottom = y
        self.top = y + SCALE
        self.topright = x + SCALE, y + SCALE
        self.bottomright = x + SCALE, y
        self.center = x + SCALE/2, y + SCALE/2

        if self.texture_file is None:
            return

        if self.texture is None:
            filename = data.filepath(self.texture_file)
            t = self.__class__.texture = textures.Texture(filename,
                internal_format=self.internal_format)
            # display list for quad rendering
            self.__class__.quad_list = glGenLists(1)
            glNewList(self.__class__.quad_list, GL_COMPILE)
            su, sv = 0, 0
            eu, ev = SCALE/float(t.width), SCALE/float(t.height)
            glBegin(GL_QUADS)
            glTexCoord2f(su, sv)
            glVertex3f(0, 0, 0)
            glTexCoord2f(eu, sv)
            glVertex3f(SCALE, 0, 0)
            glTexCoord2f(eu, ev)
            glVertex3f(SCALE, SCALE, 0)
            glTexCoord2f(su, ev)
            glVertex3f(0, SCALE, 0)
            glEnd()
            glEndList()

        if self.gradient is None:
            filename = data.filepath('gradient.png')
            Cell.gradient = textures.Texture(filename,
                internal_format=GL_LUMINANCE)
Beispiel #6
0
    def __init__(self, map, position):
        if self.texture is None:
            filename = data.filepath(self.texture_file)
            t = self.__class__.texture = textures.Texture(filename)
            self.__class__.width = t.width
            self.__class__.height = t.height
            self.__class__.quad_list = glGenLists(1)
            glNewList(self.quad_list, GL_COMPILE)
            glTexCoord2f(0, 0)
            glVertex2f(0, 0)
            glTexCoord2f(1, 0)
            glVertex2f(t.width, 0)
            glTexCoord2f(1, 1)
            glVertex2f(t.width, t.height)
            glTexCoord2f(0, 1)
            glVertex2f(0, t.height)
            glEndList()

        self.setPosition(map, position)
Beispiel #7
0
    def __init__(self, position):
        self.textures = {}
        self.texture = None

        # animation textures
        for name in 'wormy walking swimming flying flying-landing map map-overlay'.split():
            path = data.filepath(name + '.png')
            self.textures[name] = textures.TextureGrid(path, 64, 64)

        # numebrs - different grid size
        path = data.filepath('numbers.png')
        self.textures['numbers'] = textures.TextureGrid(path, 20, 32)

        # basic textures
        for name in 'light radar'.split():
            path = data.filepath(name + '.png')
            self.textures[name] = textures.Texture(path)

        self.sounds = {}
        for name in 'component landing star coin step1 step2 step3 wingbeat'.split():
            path = data.filepath('%s.ogg'%name, 'sfx')
            self.sounds[name] = pygame.mixer.Sound(path)

        #self.setForm(self.FORM_WORM)
        self.setMode(self.MODE_WORM)

        sprite.Sprite.__init__(self, self.texture)
        self.width = 64
        self.height = 64
        self.x, self.y = position
        self.impulse = Vector2(0, 0)
        self.velocity = Vector2(0, 0)
        self.gravity = Vector2(0, 0)
        self.frame = 0
        self.framecount = 0.00
        self.direction = 1
        self.angle = 0
        self.coins = 0
        self.health = 2
        self.components = []
        self.puffs = []

        self.offset = 44        # horizontal offset to center of worm
Beispiel #8
0
    def __init__(self, map, position, uvs, key_pos):
        self.key_pos = key_pos

        if self.texture is None:
            filename = data.filepath(self.texture_file)
            t = self.__class__.texture = textures.Texture(filename)
            self.__class__.width = t.width
            self.__class__.height = t.height

        self.setPosition(map, position)

        self.quad_list = glGenLists(1)
        glNewList(self.quad_list, GL_COMPILE)
        su, sv, eu, ev = uvs
        glTexCoord2f(su, sv)
        glVertex2f(0, 0)
        glTexCoord2f(eu, sv)
        glVertex2f(64, 0)
        glTexCoord2f(eu, ev)
        glVertex2f(64, 64)
        glTexCoord2f(su, ev)
        glVertex2f(0, 64)
        glEndList()
Beispiel #9
0
    def __init__(self):
        self.exit = False
        self.fadetonextscene = False
        self.cuttonextscene = False
        self.fadein = True

        self.voiceover1 = pygame.mixer.Sound(
            data.filepath('intro-danger.ogg', 'sfx'))
        self.voiceover1played = False
        self.voiceover2 = pygame.mixer.Sound(
            data.filepath('intro-scientist-plan.ogg', 'sfx'))
        self.voiceover2played = False
        self.voiceover3 = pygame.mixer.Sound(
            data.filepath('intro-scientist-needhelp.ogg', 'sfx'))
        self.voiceover3played = False
        self.voiceover4 = pygame.mixer.Sound(
            data.filepath('intro-scientist-items.ogg', 'sfx'))
        self.voiceover4played = False
        self.voiceover5 = pygame.mixer.Sound(
            data.filepath('intro-scientist-problem.ogg', 'sfx'))
        self.voiceover5played = False
        self.voiceover6 = pygame.mixer.Sound(
            data.filepath('intro-scientist-timemachine.ogg', 'sfx'))
        self.voiceover6played = False
        self.voiceover7 = pygame.mixer.Sound(
            data.filepath('intro-scientist-warn.ogg', 'sfx'))
        self.voiceover7played = False
        self.voiceover8 = pygame.mixer.Sound(
            data.filepath('timemachine2.ogg', 'sfx'))
        self.voiceover8played = False

        self.sndexplode = pygame.mixer.Sound(
            data.filepath('explode.ogg', 'sfx'))

        texture = textures.Texture(data.filepath('scene1.png'))
        self.scene = 1
        self.scene1bg = texture.sub(0, 212, 1024, 300)
        self.earth = texture.sub(0, 0, 217, 212)
        self.earthoffset = -5
        self.explode = texture.sub(219, 0, 650, 212)
        self.showexplode = False

        texture2 = textures.Texture(data.filepath('scene2.png'))
        self.scene2bg = texture2.sub(0, 724, 1024, 300)
        self.prof = texture2.sub(0, 424, 306, 300)
        self.profoffset = 0
        self.profhand1 = texture2.sub(812, 424, 210, 300)
        self.profback = texture2.sub(0, 124, 455, 300)
        self.monitor = texture2.sub(460, 124, 560, 300)
        self.wall = texture2.sub(308, 424, 477, 300)
        self.walloffset = 0

        texture3 = textures.Texture(data.filepath('scene3.png'))
        self.scene3bg = texture3.sub(0, 724, 1024, 300)
        self.scene4bg = texture3.sub(0, 318, 1024, 405)
        self.closeup = texture3.sub(0, 18, 540, 300)
        self.sceneoffset = 0

        texture4 = textures.Texture(data.filepath('subtitles.png'))
        self.subtitle1 = texture4.sub(0, 482, 512, 30)
        self.subtitle1show = False
        self.subtitle2 = texture4.sub(0, 452, 512, 30)
        self.subtitle2show = False
        self.subtitle3 = texture4.sub(0, 422, 512, 30)
        self.subtitle3show = False
        self.subtitle4 = texture4.sub(0, 392, 512, 30)
        self.subtitle4show = False
        self.subtitle5 = texture4.sub(0, 362, 512, 30)
        self.subtitle5show = False
        self.subtitle6 = texture4.sub(0, 302, 512, 60)
        self.subtitle6show = False
        self.subtitle7 = texture4.sub(0, 212, 512, 90)
        self.subtitle7show = False
        self.subtitle8 = texture4.sub(0, 182, 512, 30)
        self.subtitle8show = False
        self.subtitle9 = texture4.sub(0, 152, 512, 30)
        self.subtitle9show = False
        self.subtitle10 = texture4.sub(0, 122, 512, 30)
        self.subtitle10show = False
        self.subtitle11 = texture4.sub(0, 62, 512, 60)
        self.subtitle11show = False
        self.subtitle12 = texture4.sub(0, 0, 512, 62)
        self.subtitle12show = False
def main(thresh1, kernel):

    print(kernel)

    HEIGHT = 3  # distance of kernel from x-y plane

    img = cv2.imread('./Dilation/assets/dilation7x7sample2.jpg', 0)

    ret, thresh1 = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY)

    n1, n2 = thresh1.shape
    n1 += 2  # horizontal number of pixels plus 2 for padding
    n2 += 2  # vertical number of pixels plus 2 for padding

    threshNew = [['' for j in range(n1)] for i in range(n2)]
    resultMatrix = [['' for j in range(n1)] for i in range(n2)]
    dilationSquareMatrixFront = [[[(2 + n1, -n2 - 2, 0),
                                   (2 + n1, 0.5 - n2 - 2, 1),
                                   (n1 - 2, 0.5 - n2 - 2, 1),
                                   (n1 - 2, -n2 - 2, 0)]]]
    dilationSquareMatrixBack = [[[(2 + n1, -n2 - 2 + 1, 0),
                                  (2 + n1, 0.5 - n2 - 2, 1),
                                  (n1 - 2, 0.5 - n2 - 2, 1),
                                  (n1 - 2, -n2 - 2 + 1, 0)]]]

    for y in range(n2):
        for x in range(n1):
            if (y == 0 or x == 0 or y == n2 - 1 or x == n1 - 1):
                threshNew[y][x] = 0
            else:
                threshNew[y][x] = thresh1[y - 1][x - 1]
            resultMatrix[y][x] = ''

    thresh1 = np.array(threshNew, np.uint8)
    kernel = np.array([[0, 1, 0, 0], [1, 1, 1, 0], [0, 1, 0, 1], [0, 0, 0, 0]],
                      np.uint8)
    kn1, kn2 = kernel.shape

    squareMatrix = makeSquareMatrix(n1, n2)
    squareResultMatrix = makeSquareResultMatrix(n1, n2)
    kernelSquareMatrix = makeKernelMatrix(0, 0, HEIGHT, kn1, kn2)

    pygame.init()
    display = (1000, 563)
    img = pygame.display.set_mode(display, DOUBLEBUF | OPENGL)

    gluPerspective(45, (display[0] / display[1]), 0.1, 50.0)

    glTranslatef(-n1, n1 / 3, -(n1 + n2))

    glEnable(GL_LINE_SMOOTH)
    glEnable(GL_POLYGON_SMOOTH)
    glHint(GL_LINE_SMOOTH_HINT, GL_NICEST)
    glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST)
    glEnable(GL_BLEND)
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
    glEnable(GL_MULTISAMPLE)

    glRotatef(20, 0, 0, 1)
    glRotatef(-50, 1, 0, 0)
    glRotatef(20, 0, 1, 0)

    xindex = 0
    yindex = 0

    texture = textures.Texture(True, n1, n2)
    texture.loadTexture(0)

    tmp_texture = textures.Texture(True, n1, n2)
    tmp_texture.loadTexture(1)
    tmp_texture.set_vertices(1)

    tmp_texture2 = textures.Texture(True, n1, n2)
    tmp_texture2.loadTexture(2)
    tmp_texture2.set_vertices(2)

    rate = 0

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()
            if event.type == pygame.MOUSEBUTTONDOWN:
                if event.button == 4:
                    glTranslatef(0, -1, 0)
                elif event.button == 5:
                    glTranslatef(0, 1, 0)
            keys = pygame.key.get_pressed()
            if keys[K_LEFT]:
                glTranslatef(1, 0, 0)
            if keys[K_RIGHT]:
                glTranslatef(-1, 0, 0)
            if keys[K_UP]:
                glTranslatef(0, 0, -1)
            if keys[K_DOWN]:
                glTranslatef(0, 0, 1)

        # glClearColor(0.88, 0.3, 0.53, 1)
        glClearColor(0.29, 0.32, 0.6, 1)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        if (xindex == 0 and yindex == 0):
            for y in range(n2):
                for x in range(n1):
                    resultMatrix[y][x] = ''

        texture.draw()
        tmp_texture2.draw()
        Graphics(xindex, yindex, HEIGHT, kn1, kn2, n1, n2, squareMatrix,
                 kernel, thresh1, squareResultMatrix, resultMatrix,
                 dilationSquareMatrixBack, dilationSquareMatrixFront)
        tmp_texture.draw()

        if (rate == 0):
            xindex = (xindex + 1) % (n1 - kn1 + 1)
            if (xindex == 0):
                yindex = (yindex + 1) % (n2 - kn2 + 1)

        rate = (rate + 1) % 10

        pygame.display.flip()
        pygame.time.wait(50)