Last active
April 11, 2023 15:04
-
-
Save Alzarath/fd29886b7c4ca806669a181fd1e876ab to your computer and use it in GitHub Desktop.
Calculates the numbers for a periodic effect given the amount applied over the duration, the duration, and a tick rate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
def calculate_options(amount: float, duration: float, divisible: float = 0.0625): | |
valid_values: list = [] | |
for tick in range(1, int(duration / divisible)): | |
period: float = tick * divisible | |
if period % divisible != 0: # Skip if the calculated period is not divisible | |
continue | |
count: float = duration / period | |
if count % 1 != 0: # Skip if the total ticks is not an integer | |
continue | |
amount_per_tick: float = amount / count | |
if amount_per_tick % divisible != 0: # Skip if the calculated amount is not divisible | |
continue | |
valid_values.append({"period": period, "count": int(count), "amount": amount_per_tick}) | |
return valid_values | |
if __name__ == '__main__': | |
import argparse | |
parser = argparse.ArgumentParser(description='Calculate the values for a periodic effect given an amount, duration, and tick rate.') | |
parser.add_argument('amount', type=float, help='Total effect amount') | |
parser.add_argument('duration', type=float, help='Duration that the effect amount is spread over') | |
parser.add_argument('increment', type=float, nargs='?', default=0.0625, help='The minimum incremental value') | |
args = parser.parse_args() | |
for value in calculate_options(args.amount, args.duration, args.increment): | |
print(value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment