Beispiel #1
0
    def __init__(self, *args, **kwargs):
        #mouse handling for transforming scene
        self.mouse_down = False
        self.mouse_old = Vec([0., 0.])
        self.rotate = Vec([0., 0., 0.])
        self.translate = Vec([0., 0., 0.])
        #self.initrans = Vec([0., 0., -2.])
        self.init_persp_trans = Vec([-.5, 0., -1.5])
        self.init_ortho_trans = Vec([0., 0., 0.])
        self.init_persp_rotate = Vec([0., 0., 0.])
        self.init_ortho_rotate = Vec([90., -90., 0.])

        self.ortho = False
        self.choice = 2
        #self.stable = True
        self.stable = False
        #self.type = "square"
        self.wtype = "sin"
        #self.wtype = "sawtooth"
        #self.wtype = "sweep_poly"
        self.dt = dt

        self.width = 640
        self.height = 480

        glutInit(sys.argv)
        glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH)
        glutInitWindowSize(self.width, self.height)
        glutInitWindowPosition(0, 0)
        self.win = glutCreateWindow("Part 2: Python")

        #gets called by GLUT every frame
        glutDisplayFunc(self.draw)

        #handle user input
        glutKeyboardFunc(self.on_key)
        glutMouseFunc(self.on_click)
        glutMotionFunc(self.on_mouse_motion)

        #this will call draw every 30 ms
        glutTimerFunc(30, self.timer, 30)

        glViewport(0, 0, self.width, self.height)
        #setup OpenGL scene
        self.glprojection()

        #set up initial conditions
        self.init_wave(self.dt, dx, ntracers, True)
        #create our OpenCL instance
        #self.cle = part2.Part2(num, dt, "part2.cl")
        self.cle = wave.Wave(self.dt, dx, ntracers, self.params)
        self.cle.loadData(self.pos_vbo, self.col_vbo)

        self.cle.execute(subintervals)
        glutMainLoop()
Beispiel #2
0
    def game_actions(self):
        if self.life_counter <= 0:
            self.game_over = True
            return

        end_of_wave = self.wave_agent is None and len(self.monsters) == 0
        if end_of_wave and self.wave_counter == self.wave_max:
            self.game_over = True
            return

        elif end_of_wave and self.wave_counter < self.wave_max:
            instructions = game_data.waves[self.level][self.wave_counter]
            self.wave_agent = wave.Wave(instructions,
                                        game_data.paths[self.level])
            self.wave_counter += 1
            self.game_gui.score_wave.update_score(
                str(self.wave_counter) + "/" + str(self.wave_max))

        if self.wave_agent is not None:
            active, monster = self.wave_agent.action()
            if not active:
                self.wave_agent = None
            elif monster is not None:
                self.monsters.append(monster)
                self.game_gui.add(monster, send_back=True)
                self.game_gui.add(monster.bar_indicator)

        for monster in self.monsters[:]:
            active, alive = monster.action()
            if not active:
                if alive:
                    self.life_counter -= monster.damage
                    self.game_gui.score_life.update_score(
                        str(self.life_counter))
                else:
                    self.coin_counter += monster.coin
                    self.game_gui.score_coin.update_score(
                        str(self.coin_counter))
                self.monsters.remove(monster)
                self.game_gui.remove(monster)
                self.game_gui.remove(monster.bar_indicator)

        for b in self.buildings:
            projectile = b.action(self.monsters)
            if projectile is not None:
                self.projectiles.append(projectile)
                self.game_gui.add(projectile)

        for projectile in self.projectiles[:]:
            active = projectile.action(self.monsters)
            if not active:
                self.projectiles.remove(projectile)
                self.game_gui.remove(projectile)
Beispiel #3
0
def bell(freq=440.,
         volume=1.0,
         duration=None,
         attack=0.001,
         sustain=None,
         decay=0.5,
         bpm=120):
    assert freq < 2000., "bells don't go that high"
    A = 10**((volume - 10.0) / 3)
    t = np.arange(0.0, 5.0, 1. / kp.sps)
    data = np.zeros([len(t), 2])
    data[:, 0] = A * np.sin(2 * np.pi * t * freq) * np.exp(-t / decay)
    data[:, 1] = data[:, 0]
    W = kp.Wave(data=(kp.sps, data))
    return kp.Track(Wave=W, zero=0)
Beispiel #4
0
def initialise():
    curr_enemies = []
    for n in range(constants.BASE_WAVE_AMOUNT):
        location = wave.random_spawn_location(constants.DISPLAY_WIDTH,
                                              constants.DISPLAY_HEIGHT)
        curr_enemies.append(enemy.Zombie(location[0], location[1]))

    instance = game.Game()
    instance.light_map = generate_light_surface(instance.lights)
    instance.current_wave = wave.Wave(1, curr_enemies)

    player = baseCharacter.Wizard(constants.DISPLAY_WIDTH / 2,
                                  constants.DISPLAY_HEIGHT / 2,
                                  constants.WIZARD_BASE_HEALTH,
                                  constants.CHAR_SPEED,
                                  constants.WIZARD_SHOT_DAMAGE, 100, 100, 0,
                                  [])

    return player, instance
    def __init__(self, *args, **kwargs):
        #mouse handling for transforming scene
        self.mouse_down = False
        self.mouse_old = Vec([0., 0.])
        self.rotate = Vec([0., 0., 0.])
        self.translate = Vec([0., 0., 0.])
        self.initrans = Vec([0., 0., -2.])

        self.width = 640
        self.height = 480

        glutInit(sys.argv)
        glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH)
        glutInitWindowSize(self.width, self.height)
        glutInitWindowPosition(0, 0)
        self.win = glutCreateWindow("Part 2: Python")

        #gets called by GLUT every frame
        glutDisplayFunc(self.draw)

        #handle user input
        glutKeyboardFunc(self.on_key)
        glutMouseFunc(self.on_click)
        glutMotionFunc(self.on_mouse_motion)

        #this will call draw every 30 ms
        glutTimerFunc(30, self.timer, 30)

        #setup OpenGL scene
        self.glinit()

        #set up initial conditions
        (pos_vbo, col_vbo, params) = initialize.wave(dt, dx, ntracers)
        #create our OpenCL instance
        #self.cle = part2.Part2(num, dt, "part2.cl")
        self.cle = wave.Wave(dt, dx, ntracers, params)
        self.cle.loadData(pos_vbo, col_vbo)

        self.cle.execute(subintervals)
        glutMainLoop()
Beispiel #6
0
def drone(freq=440.,
          volume=1.0,
          duration=4.0,
          attack=0.1,
          sustain=None,
          decay=0.1,
          bpm=120):
    assert freq < 600., "drones shouldn't be high... that's annoying"
    A = 10**((volume - 10.0) / 3)
    t_cut = duration * 60. / bpm
    t_end = (duration + 4) * 60 / bpm
    t = np.arange(0.0, t_end, 1. / kp.sps)
    drfreq = bpm / 60. * random.randint(1, 2)
    depth = 0.1 + 0.2 * random.random()
    Amp = (1 - depth) * A + depth * A * np.cos(2 * np.pi * t * drfreq)
    dt = np.sin(2 * np.pi * t * freq) * (1 - np.exp(-t / attack))
    dt = Amp * dt
    dt[t > t_cut] = dt[t > t_cut] * np.exp(-(t[t > t_cut] - t_cut) / decay)
    if sustain != None: dt *= np.exp(-t / sustain)
    data = np.zeros([len(t), 2])
    data[:, 0] = dt
    data[:, 1] = dt
    W = kp.Wave(data=(kp.sps, data))
    return kp.Track(Wave=W, zero=0)
Beispiel #7
0
    elif x == 3:
        return 'III'
    elif x == 4:
        return 'IV'
    elif x == 5:
        return 'V'
    elif x == 6:
        return 'VI'
    elif x == 7:
        return 'VII'


#initialize wave spawning
#-------------------------
waves = [
    wave.Wave([0, 0, 0, 0, 0], 2),
    wave.Wave([0, 0, 0, 0, 0, 0, 0, 0], 0.2),
    wave.Wave([2, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0], 0.4),
    wave.Wave([1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1], 1),
    wave.Wave([1, 1, 1, 1, 1, 1, 1, 1], 0.5),
    wave.Wave([1, 1, 0, 1, 1, 0, 0, 2, 2, 0, 0, 1, 1, 2], 1),
    wave.Wave([3], 1)
]
wave_num = 0
#-------------------------

font = pygame.font.Font(None, 36)
halfFont = pygame.font.Font(None, 18)

index = 0
timer = 0
Beispiel #8
0
        def Key_control (self):
            self.keytime +=1
            if self.keytime == 3:
                self.keytime =0
                k = pygame.key.get_pressed()
                if k[pygame.K_t]:
                    if k[pygame.K_UP]:
                        if not self.focus_panel == None and self.focus_panel.type == 'Wave':
                                self.focus_panel.T += 5
                if k[pygame.K_l]:
                    if k[pygame.K_UP]:
                        if not self.focus_panel == None and self.focus_panel.type == 'Wave':
                                self.focus_panel.l += 1

                if k[pygame.K_s]:
                    if not self.focus_panel == None and self.focus_panel.type == 'Wave':
                        self.focus_panel.dir *=-1

                if k[pygame.K_a]:
                    if k[pygame.K_UP]:
                        if not self.focus_panel == None and self.focus_panel.type == 'Wave':
                                self.focus_panel.A += 0.1

                if k[pygame.K_o]:
                    if k[pygame.K_UP]:
                        if not self.focus_panel == None and self.focus_panel.type == 'Wave':
                                self.focus_panel.teta += 0.6
                #-----Down-----#
                if k[pygame.K_DOWN]:
                    if k[pygame.K_t]:
                        if not self.focus_panel == None and self.focus_panel.type == 'Wave':
                            self.focus_panel.T -= 5

                    if k[pygame.K_l]:
                        if not self.focus_panel == None and self.focus_panel.type == 'Wave':
                            self.focus_panel.l -= 1

                    if k[pygame.K_a]:
                        if not self.focus_panel == None and self.focus_panel.type == 'Wave':
                            self.focus_panel.A -= 0.1

                    if k[pygame.K_o]:
                        if not self.focus_panel == None and self.focus_panel.type == 'Wave':
                            self.focus_panel.teta -= 0.1
                #--Crate New Wave_Panel---#
                if k[pygame.K_LCTRL] and self.new:
                    self.new = False
                    if k[pygame.K_n]:
                        Wave = wave.Wave(5,100,10)
                        self.add_wave(Wave)
                    if k[pygame.K_e]:
                        Wave = wave.Wave(5,100,10)
                        Wave2 = wave.Wave(5,100,10,0.5,-1)
                        Wave.add_wave(Wave2)
                        self.add_wave(Wave)
                    if k[pygame.K_r]:
                        Wave = wave.Wave(5,100,66)
                        Wave2 = wave.Wave(5,100,66,0,-1)
                        Wave.add_wave(Wave2)
                        self.add_wave(Wave)
                    if k[pygame.K_f]:
                        Wave = wave.Wave(5,100,50)
                        Wave2 = wave.Wave(5,100,50,0,-1)
                        Wave.add_wave(Wave2)
                        self.add_wave(Wave)

                    if k[pygame.K_d]:
                        self.delate_waves()
                else:
                    self.new = True
Beispiel #9
0
import wave as wv

wave = wv.Wave()
wave.initiate_fem()
wave.crank_nicolson()
#wave.symplectic_euler()
#wave.stormer_verlet()
#wave.save_snapshots()
Beispiel #10
0
        mqtt_msgs.append((mqtt_topic_c,w_co2,1,False))
    if mqtt_topic_v != None:
        mqtt_msgs.append((mqtt_topic_v,w_voc,1,False))
    try:
        publish.multiple(mqtt_msgs, hostname=mqtt_host, port=mqtt_port, client_id="wavemqttbridge", auth=mqtt_auth, tls=None)
    except Exception as ex:
        logging.error('Exception while publishing to MQTT broker: {}'.format(ex))

while True:
    
    start = datetime.now()

    # Use regular Wave
    if aw_type == "WAVE":
        try:
            w = wave.Wave(aw_serial)
            w.connect()

            date_time    = w.read(wave.SENSOR_IDX_DATETIME)
            humidity     = w.read(wave.SENSOR_IDX_HUMIDITY)
            temperature  = w.read(wave.SENSOR_IDX_TEMPERATURE)
            radon_st_avg = w.read(wave.SENSOR_IDX_RADON_ST_AVG)
            radon_lt_avg = w.read(wave.SENSOR_IDX_RADON_LT_AVG)

            if mqtt_host != None:
                publish_mqtt(radon_st_avg,radon_lt_avg,temperature,humidity,None,None,None)

        except Exception as ex:
            logging.error('Exception while communicating with wave: {}'.format(ex))

        finally:
Beispiel #11
0
        #now vary depth for wave break
        for d in range(1, INC):
            #now vary distance past the sandcastle
            #print(d)
            for dist in range(1, INC):
                #Make a shape and a wave
                side_length = VOL**(1/3)
                cube = shapes.Cube(side_length)
                #print(cube.side_length)
                #Increment the wave values
                wave_HEIGHT= (h * HEIGHT_INCREMENT) + START_HEIGHT
                wave_DEPTH = (d * DEPTH_INCREMENT) + START_DEPTH
                wave_DIST = (dist * DIST_INCREMENT) + START_DISTANCE

                #make the wave
                w = waves.Wave(wave_HEIGHT, wave_DEPTH, wave_DIST)
                #Set the cube base_height
                cube.set_base_height(w.wave_height)
                saturation = INITIAL_SATURATION
                #now commence the testing!
                wave_hits = 0
                while cube.base_radius > 0 and wave_hits < MAX_WAVE_HITS and castle_still_standing(cube, w) and not_oversaturated(cube, saturation):
                    saturation = saturation + rain_on_shape(cube) #update the saturation by raining on the shape
                    wave_hits +=1
                    erode_shape(cube, w)
                    #print("base_radius: " + str(cube.base_radius))
                t = (wave_hits, cube, w)
                cube_array.append(t)
                #update dictionary
                if cube.base_radius <= 0: 
                    erosion_dict[cube.string_name()] = erosion_dict[cube.string_name()] + 1
Beispiel #12
0
import wave
import test_function

dt = 0.003
dx = 0.1
t_end = 20.
x_end = 6.

W = wave.Wave(dt,
              dx,
              t_end,
              x_end,
              5.0, [0., 0.],
              function_t0=test_function.sin_t0)

W.wave_solve()

W.show()