Example #1
0
    def move(self):
        
        self.location[0] += self.velocity[0]
        self.location[1] += self.velocity[1]

        self.blit_location[0] = self.location[0] - abs(math_sin(math_pi*self.angle/90)*self.image.get_width()/math_sqrt(8))
        self.blit_location[1] = self.location[1] - abs(math_sin(math_pi*self.angle/90)*self.image.get_width()/math_sqrt(8))

        if 0 > self.location[0] + self.image.get_width() // 2:
            self.location[0] = const.WINDOW_WIDTH - self.image.get_width() // 2
            
        elif self.location[0] + self.image.get_width() // 2 > const.WINDOW_WIDTH:
            self.location[0] = - self.image.get_width() // 2
            
        if 0 > self.location[1] + self.image.get_height() // 2:
            self.location[1] = const.WINDOW_HEIGHT - self.image.get_height() // 2
            
        elif self.location[1] + self.image.get_height() // 2 > const.WINDOW_HEIGHT:
            self.location[1] = - self.image.get_height() // 2

        self.velocity[0] += self.acceleration[0]
        self.velocity[1] += self.acceleration[1]

        if math_sqrt( self.velocity[0]**2 + self.velocity[1]**2 ) > 10:
            self.velocity[0] *= 10 / math_sqrt( self.velocity[0]**2 + self.velocity[1]**2 )
            self.velocity[1] *= 10 / math_sqrt( self.velocity[0]**2 + self.velocity[1]**2 )

        
        #reset acceleration
        self.acceleration[0] = 0
        self.acceleration[1] = 0
Example #2
0
 def getRotationMatrix(angle):
     radiansAngle = math_radians(angle)
     # 9 digits of precision should be more than enough
     sinAngle = round(math_sin(radiansAngle), 9)
     cosAngle = round(math_cos(radiansAngle), 9)
     return Mat33([[cosAngle, -sinAngle, 0], [sinAngle, cosAngle, 0],
                   [0, 0, 1]])
Example #3
0
    def execute(self):
        _info = self.msg.info
        _info('==> execute...')
        self._n += 1
        n = self._n
        x = math_sin(float(n)) * 52. + 50.
        hsvc = self.hsvc
        hsvc['/temp/h1'].Fill(x)
        for _ in xrange(2): hsvc['/temp/other/h1a'].Fill(x)
        for _ in xrange(3): hsvc['/new/hists/h1'].Fill(x)
        _fill = hsvc['/upd/xxx/gauss1d'].Fill
        for _ in xrange(1000): _fill(gauss(mu=0.,sigma=15.),1.)
        _fill = hsvc['/rec/gauss2d'].Fill
        for _ in xrange(1000): _fill(gauss(mu=0.,sigma=15.),
                                     gauss(mu=0.,sigma=15.), 1.)
        _fill = hsvc['/rec/gauss3d'].Fill
        for _ in xrange(1000): _fill(gauss(mu=0.,sigma=15.),
                                     gauss(mu=0.,sigma=15.),
                                     gauss(mu=0.,sigma=15.), 1.)

        tr = hsvc['/rec/trees/stuff/tree1']
        if n == 0:
            p1 = array('i',[0])
            p2 = array('i',[0])
            p3 = array('i',[0])
            tr.Branch('branch1', p1, 'point1/I')
            tr.Branch('branch2', p2, 'point2/I')
            tr.Branch('branch3', p3, 'point3/I')
            _tr_fill = tr.Fill
            for i in xrange(1000):
                p1[0] = i
                p2[0] = i%10
                p3[0] = i%7
                _tr_fill()
        return StatusCode.Success
Example #4
0
    def execute(self):
        _info = self.msg.info
        _info('==> execute...')
        self._n += 1
        n = self._n
        x = math_sin(float(n)) * 52. + 50.
        hsvc = self.hsvc
        hsvc['/temp/h1'].Fill(x)
        for _ in range(2):
            hsvc['/temp/other/h1a'].Fill(x)
        for _ in range(3):
            hsvc['/new/hists/h1'].Fill(x)
        _fill = hsvc['/upd/xxx/gauss1d'].Fill
        for _ in range(1000):
            _fill(gauss(mu=0., sigma=15.), 1.)
        _fill = hsvc['/rec/gauss2d'].Fill
        for _ in range(1000):
            _fill(gauss(mu=0., sigma=15.), gauss(mu=0., sigma=15.), 1.)
        _fill = hsvc['/rec/gauss3d'].Fill
        for _ in range(1000):
            _fill(gauss(mu=0., sigma=15.), gauss(mu=0., sigma=15.),
                  gauss(mu=0., sigma=15.), 1.)

        tr = hsvc['/rec/trees/stuff/tree1']
        if n == 0:
            p1 = array('i', [0])
            p2 = array('i', [0])
            p3 = array('i', [0])
            tr.Branch('branch1', p1, 'point1/I')
            tr.Branch('branch2', p2, 'point2/I')
            tr.Branch('branch3', p3, 'point3/I')
            _tr_fill = tr.Fill
            for i in range(1000):
                p1[0] = i
                p2[0] = i % 10
                p3[0] = i % 7
                _tr_fill()
        return StatusCode.Success
Example #5
0
def play():
    
    #Objects
    asteroid_list = []
    bullet_list = []
    battleShip = obj.Ship((const.WINDOW_WIDTH // 2 - const.SPRITE_SHIP.get_width() //2 , const.WINDOW_HEIGHT // 2 - const.SPRITE_SHIP.get_height() // 2))
    slow_ship = True
    
    const.DISPLAYSURF.fill(const.BGCOLOR) #clear the screen

    #Music settings
    pygame.mixer.music.set_volume(0.5)
    pygame.mixer.music.play()
    pygame.key.set_repeat(1, 1)
    
    while True:
        if random_randrange(25) == 0:
            asteroid_list.append( obj.Asteroid() )
        const.DISPLAYSURF.fill(const.BGCOLOR)
              
        for i in asteroid_list:
            i.move()

        battleShip.move(slow_ship)

        for i in asteroid_list:
            const.DISPLAYSURF.blit(i.image, i.location)

        if len(bullet_list) != 0:
            for i in bullet_list:
                i.move(battleShip.image.get_width())
                const.DISPLAYSURF.blit(i.image, i.location)
                
        const.DISPLAYSURF.blit( pygame.transform.rotate(battleShip.image, battleShip.angle), battleShip.blit_location )

        #event loop
        
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                func.terminate()

            elif event.type == pygame.KEYDOWN:
                slow_ship = False
                
                if event.key == pygame.K_LEFT:
                    battleShip.angle += 3

                elif event.key == pygame.K_RIGHT:
                    battleShip.angle -= 3

                elif event.key == pygame.K_DOWN:
                    battleShip.acceleration = [math_sin(math_pi * battleShip.angle / 180), math_cos(math_pi * battleShip.angle / 180)]

                elif event.key == pygame.K_UP:
                    battleShip.acceleration = [-math_sin(math_pi * battleShip.angle / 180), -math_cos(math_pi * battleShip.angle / 180)]

            elif event.type == pygame.KEYUP:
                if event.key == pygame.K_SPACE:
                    bullet_list.append(obj.Bullet(battleShip.location[0] + const.SPRITE_SHIP.get_width() // 2 - const.SPRITE_BULLET.get_width() // 2,
                                                  battleShip.location[1] + const.SPRITE_SHIP.get_height() // 4, battleShip.angle))
                    const.BLAST.play()
                else:
                    slow_ship = True

        pygame.display.update()
        const.FPSCLOCK.tick(10)
Example #6
0
def qcos(a):
    return Q(math_cos(a.number), "cos(%s)", a.units, abs(a.uncert * math_sin(a.number)), a.prefu, (a,))
Example #7
0
def qcos(a):
    return Q(math_cos(a.number), "cos(%s)", a.units, abs(a.uncert * math_sin(a.number)), a.prefu, (a,))
Example #8
0
def test_prim_sin(x):
    return math_sin(x)
Example #9
0
 def move(self, width):
     
     self.location[0] -= 30*math_sin(self.angle)
     self.location[1] -= 30*math_cos(self.angle)
Example #10
0
 def __init__(self, posX, posY, angle):
     self.image = const.SPRITE_BULLET
     self.angle = math_pi*angle / 180
     self.location = [math_sin(self.angle) + posX, posY]
     self.location = list(self.location)
     self.rect = self.image.get_rect()
Example #11
0
 def move(self, width):
     #self.location[0] = self.location[0] - abs(math_sin(math_pi*self.angle/90)*width/math_sqrt(8))
     #self.location[1] = self.location[1] - abs(math_sin(math_pi*self.angle/90)*width/math_sqrt(8))
     self.location[0] -= 30*math_sin(self.angle)
     self.location[1] -= 30*math_cos(self.angle)
Example #12
0
 def __init__(self, posX, posY, angle):
     self.image = const.SPRITE_BULLET
     self.angle = math_pi*angle / 180
     self.location = [math_sin(self.angle) + posX, posY]
     self.location = list(self.location)
Example #13
0
def show_start_screen():

    
    
    #Title
    titleFont = pygame.font.Font(const.BASICFONT, 100)
    
    titleSurf = titleFont.render('Asteroids', True, const.WHITE, const.BGCOLOR)
    displacement = 1
    state = 0

    #Objects
    asteroid_list = []
    battleShip = obj.Ship([const.WINDOW_WIDTH // 2 - 15, 2 * const.WINDOW_HEIGHT // 3, 10, 10])

    #Buttons
    StartButton = obj.Button(const.DARKGREEN, const.GREEN, (const.WINDOW_WIDTH // 2 - 50, const.WINDOW_HEIGHT * 2 // 3, 100, 40))
   
    pygame.mixer.music.play()

    pygame.key.set_repeat(1, 1)
    
    while True:
        if random_randrange(25) == 0:
            asteroid_list.append( obj.Asteroid() )
        const.DISPLAYSURF.fill(const.BGCOLOR)
        titleRect = titleSurf.get_rect()
        titleRect.center = (const.WINDOW_WIDTH / 2, const.WINDOW_HEIGHT / 2 + displacement)
        
        for i in asteroid_list:
            i.move()

        battleShip.move()
        
        const.DISPLAYSURF.blit(titleSurf, titleRect)

        for i in asteroid_list:
            const.DISPLAYSURF.blit(i.image, i.location)

        const.DISPLAYSURF.blit( pygame.transform.rotate(battleShip.image, battleShip.angle), battleShip.blit_location )

        StartButton.Func('Start', const.WHITE, 20)

        #event loop
        
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                func.terminate()

            elif event.type==pygame.MOUSEBUTTONDOWN:
                if StartButton.Press():
                    pass #start game

            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_LEFT:
                    battleShip.angle += 3

                elif event.key == pygame.K_RIGHT:
                    battleShip.angle -= 3

                elif event.key == pygame.K_DOWN:
                    battleShip.acceleration = [math_sin(math_pi * battleShip.angle / 180), math_cos(math_pi * battleShip.angle / 180)]

                elif event.key == pygame.K_UP:
                    battleShip.acceleration = [-math_sin(math_pi * battleShip.angle / 180), -math_cos(math_pi * battleShip.angle / 180)]

            
        
                        

        pygame.display.update()
        const.FPSCLOCK.tick(15)
        if displacement > 10:
            state = 0
        elif displacement < -10:
            state = 1

        if state:
            displacement += 1
        else:
            displacement -= 1
Example #14
0
do_video = True

#
#		End of customisation here
#
###############################################################################

exposure_frame_weight = None

if weighting == "INVERSE":
    exposure_frame_weight = [
        1 / (exposure_frame_count - i) for i in range(exposure_frame_count)
    ]
elif weighting == "SIN":
    exposure_frame_weight = [
        math_sin(math_pi * i / exposure_frame_count)
        for i in range(exposure_frame_count)
    ]

src = folder + name + "." + input_extension
input_src = VideoReader(src, start_frame=start_frame, end_frame=end_frame)

if moving_exposure:
    if do_video:
        output_generator = VideoOutput(dims=(1080, 1920, 3),
                                       name=output_name,
                                       folder=output_folder,
                                       video_type=output_extension,
                                       codec=output_codec,
                                       frame_rate=30)
    else:
Example #15
0
from math import cos
from math import sin as math_sin

myValue = math_sin(45)
value = cos(28)
print(value, '\n', myValue)

print('----------------------------')

import string
print(dir(string))
print('\n', string.printable)
print('\n', string.punctuation)
print('\n', string.ascii_uppercase)

print('Проверка свойство или метод')
#string.ascii_lowercase()
print('Просто вызвать')
print('''    string.ascii_lowercase()
TypeError: 'str' object is not callable''')
print('ЭТО ЗНАЧИТ ЧТО ЭТО НЕ ФУНКЦИЯ, ЭТО СВОЙСТВО')

print('TO DOWNLOAD MODULES')
print('pip install numpy')

import numpy

num1 = numpy.product([1,2,3,4,5])
print(num1)

print('\nTO UNINSTALL MODULES')
Example #16
0
def mysin(x):
    return math_sin(x)
Example #17
0
def show_start_screen():

    #Title
    titleFont = pygame.font.Font(const.BASICFONT, 100)

    titleSurf = titleFont.render('Asteroids', True, const.WHITE, const.BGCOLOR)
    displacement = 1
    state = 0

    #Objects
    asteroid_list = []
    battleShip = obj.Ship(
        [const.WINDOW_WIDTH // 2 - 15, 2 * const.WINDOW_HEIGHT // 3, 10, 10])
    slow_ship = True

    #Buttons
    StartButton = obj.Button(
        const.DARKGREEN, const.GREEN,
        (const.WINDOW_WIDTH // 2 - 50, const.WINDOW_HEIGHT * 2 // 3, 100, 40))

    pygame.mixer.music.play()

    pygame.key.set_repeat(1, 1)

    while True:
        if random_randrange(25) == 0:
            asteroid_list.append(obj.Asteroid())
        const.DISPLAYSURF.fill(const.BGCOLOR)
        titleRect = titleSurf.get_rect()
        titleRect.center = (const.WINDOW_WIDTH / 2,
                            const.WINDOW_HEIGHT / 2 + displacement)

        for i in asteroid_list:
            i.move()

        battleShip.move(slow_ship)

        const.DISPLAYSURF.blit(titleSurf, titleRect)

        for i in asteroid_list:
            const.DISPLAYSURF.blit(i.image, i.location)

        const.DISPLAYSURF.blit(
            pygame.transform.rotate(battleShip.image, battleShip.angle),
            battleShip.blit_location)

        StartButton.Func('Start', const.WHITE, 20)

        #event loop

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                func.terminate()

            elif event.type == pygame.MOUSEBUTTONDOWN:
                if StartButton.Press():
                    pass  #start game

            elif event.type == pygame.KEYDOWN:
                slow_ship = False

                if event.key == pygame.K_LEFT:
                    battleShip.angle += 3

                elif event.key == pygame.K_RIGHT:
                    battleShip.angle -= 3

                elif event.key == pygame.K_DOWN:
                    battleShip.acceleration = [
                        math_sin(math_pi * battleShip.angle / 180),
                        math_cos(math_pi * battleShip.angle / 180)
                    ]

                elif event.key == pygame.K_UP:
                    battleShip.acceleration = [
                        -math_sin(math_pi * battleShip.angle / 180),
                        -math_cos(math_pi * battleShip.angle / 180)
                    ]

            elif event.type == pygame.KEYUP:
                slow_ship = True

        pygame.display.update()
        const.FPSCLOCK.tick(15)
        if displacement > 10:
            state = 0
        elif displacement < -10:
            state = 1

        if state:
            displacement += 1
        else:
            displacement -= 1
Example #18
0
def play():
    
    #Objects
    asteroid_list = []
    bullet_list = []
    battleShip = obj.Ship((const.WINDOW_WIDTH // 2 - const.SPRITE_SHIP.get_width() //2 , const.WINDOW_HEIGHT // 2 - const.SPRITE_SHIP.get_height() // 2))
    slow_ship = True

    list_explosion = []

    lives = 2
    lives_string = 'Lives: ' + str(lives)
    lives_font = pygame.font.Font(const.BASICFONT, 20)
    lives_surf = lives_font.render(lives_string, True, const.WHITE)
    lives_rect = lives_surf.get_rect()
    lives_rect.center = (lives_surf.get_width(), const.WINDOW_HEIGHT - lives_surf.get_height())
                                  
    score = 0
    score_string = 'Score: ' + str(score)
    score_font = pygame.font.Font(const.BASICFONT, 20)
    score_surf = score_font.render(score_string, True, const.WHITE)
    score_rect = score_surf.get_rect()
    score_rect.center = (const.WINDOW_WIDTH - score_surf.get_width(), const.WINDOW_HEIGHT - score_surf.get_height())
    
    const.DISPLAYSURF.fill(const.BGCOLOR) #clear the screen

    #Music settings
    pygame.mixer.music.set_volume(0.2)
    pygame.mixer.music.play()
    
    while lives > 0:
        
        #Generating the asteroids
        if random_randrange(15) == 0:
            asteroid_list.append( obj.Asteroid() )
            
        const.DISPLAYSURF.fill(const.BGCOLOR)
        const.DISPLAYSURF.blit(const.BG, (0,0))
              
        for i in asteroid_list:
            i.move()
            
        if len(bullet_list) != 0:
            for i in bullet_list:
                if battleShip != 0:
                    i.move(battleShip.image.get_width())
                    const.DISPLAYSURF.blit(i.image, i.location)
                
                for j in asteroid_list:
                    if i.check_collision(j):
                        asteroid_list.remove(j)
                        bullet_list.remove(i)
                        list_explosion.append(obj.Explosion(j))
                        score += 1
                        break
                    
        if battleShip != 0:
            battleShip.move(slow_ship)
            const.DISPLAYSURF.blit( pygame.transform.rotate(battleShip.image, battleShip.angle), battleShip.blit_location )
            for i in asteroid_list:
                if battleShip != 0:
                    if battleShip.check_collision(i):
                        pos_exp = battleShip.location
                        battleShip = 0
                        lives -= 1
                        for j in range(len(asteroid_list)):
                            asteroid_list.pop()

                        for i in const.EXP_LIST:
                            const.DISPLAYSURF.fill(const.BGCOLOR)
                            const.DISPLAYSURF.blit(const.BG, (0,0))
                            const.DISPLAYSURF.blit(i, pos_exp)
                            pygame.display.update()
                            const.FPSCLOCK.tick(15)
                            
                            
                else:
                    continue

        for i in asteroid_list:
            const.DISPLAYSURF.blit(i.image, i.location)

        score_string = 'Score: ' + str(score)
        score_surf = score_font.render(score_string, True, const.WHITE)
        const.DISPLAYSURF.blit(score_surf, score_rect)

        lives_string = 'Lives: ' + str(lives)
        lives_surf = lives_font.render(lives_string, True, const.WHITE)
        const.DISPLAYSURF.blit(lives_surf, lives_rect)

        if len(list_explosion) != 0:
            for i in list_explosion:
                i.draw()

        #event loop
        
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                func.terminate()

            if battleShip == 0:
                battleShip = obj.Ship((const.WINDOW_WIDTH // 2 - const.SPRITE_SHIP.get_width() //2 , const.WINDOW_HEIGHT // 2 - const.SPRITE_SHIP.get_height() // 2))

            else:

                list_key = []
                list_key = pygame.key.get_pressed()
                
                if len(list_key) != 0:
                
                    slow_ship = True
                    
                    if list_key[pygame.K_LEFT]:
                        battleShip.angle += 10
                        slow_ship = False

                    if list_key[pygame.K_RIGHT]:
                        battleShip.angle -= 10
                        slow_ship = False

                    if list_key[pygame.K_DOWN]:
                        battleShip.acceleration = [math_sin(math_pi * battleShip.angle / 180), math_cos(math_pi * battleShip.angle / 180)]
                        slow_ship = False
                    
                    if list_key[pygame.K_UP]:
                        battleShip.acceleration = [-math_sin(math_pi * battleShip.angle / 180), -math_cos(math_pi * battleShip.angle / 180)]
                        slow_ship = False

                    if event.type == pygame.KEYUP:
                        if event.key == pygame.K_SPACE:
                            bullet_list.append(obj.Bullet(battleShip.location[0] + const.SPRITE_SHIP.get_width() // 2 - const.SPRITE_BULLET.get_width() // 2,
                                                          battleShip.location[1] + const.SPRITE_SHIP.get_height() // 4, battleShip.angle))
                            const.BLAST.play()

        #delete the bullets that can't be seen on the screen
        for i in bullet_list:
            if i.location[0] < 0 or i.location[0] > const.WINDOW_WIDTH\
               or i.location[1] < 0 or i.location[1] > const.WINDOW_HEIGHT:
                bullet_list.remove(i)

        #Same for asteroids
        for i in asteroid_list:
            if i.location[0] + i.image.get_width() < 0 or i.location[0] - i.image.get_width() > const.WINDOW_WIDTH\
               or i.location[1] + i.image.get_height() < 0 or i.location[1] - i.image.get_height() > const.WINDOW_HEIGHT:
                asteroid_list.remove(i)

        for i in list_explosion:
            if i.size > 30:
                list_explosion.remove(i)
                
        pygame.display.update()
        const.FPSCLOCK.tick(15)
        
    pygame.mixer.music.stop()
    game_over()