Beispiel #1
0
def get_custom_harmonic_levels(params):
    levels = []
    for h in range(harmonic_count):
        n = h + 1  # harmonic numbers start at 1
        level = get_custom_level(n, params)
        levels.append(level)
    return levels
Beispiel #2
0
def get_sqr_levels():
    """Get the sawtooth levels and take out the even harmonics to get square levels."""
    saw_levels = get_saw_levels()
    levels = []
    for i in range(len(saw_levels)):
        n = i + 1
        level = saw_levels[n] if n % 2 != 0 else 0
        levels.append(level)
    return levels
Beispiel #3
0
def get_saw_levels():
    """Get level for 1/n for each harmonic."""
    levels = []
    for i in range(harmonic_count):
        n = i + 1  # harmonic numbers start at 1
        a = 1.0 / float(n)
        print(n, a)
        level = get_level(a)
        levels.append(level)
    return levels
Beispiel #4
0
def get_tri_levels():
    """Get levels for amplitude 1/n^2 for each harmonic n."""
    levels = []
    negative = False  # is current harmonic negative?
    for h in range(harmonic_count):
        n = h + 1  # harmonic numbers start at 1
        level = 0
        if n % 2 != 0:  # using only odd harmonics
            a = 1.0 / float(n * n)
            if negative:
                a = -a
                negative = not negative
            level = get_level(a)
        levels.append(level)
    return levels
    def saveLevel(self, test=False):
        """Saves the level. If testing is wanted it's saved to a temp file. Otherwise in the main levels file."""

        # Stores the statics in the correct way - [colour, tile1, tile2]
        points = []
        for static in self.statics:
            found = False
            i = 0
            while i < len(points):
                if points[i][0] == static[1]:
                    points[i].append(static[0])
                    found = True
                    break
                i += 1

            if not found:
                points.append([static[1], static[0]])

        # Appends to saved levels or overwrites old tempfile if testing is chosen.
        if test:
            levels = []
            filename = "tempsave.json"
        else:
            with open("levels.json") as f:
                levels = json.loads(f.read())
            filename = "levels.json"

        # Store the info in a dict
        newLevel = {}
        newLevel["points"] = points
        newLevel["height"] = self.level.height
        newLevel["width"] = self.level.width
        levels.append(newLevel)

        # Saves to file
        with open(filename, "w") as f:
            f.write(json.dumps(levels, indent=4))  # , indent=4

        print(points)