Working with ranges made simple
A small, easy-to-use library for working with ranges.
This package can be installed with the command:
pip install qrange
How to use
Use qrange in your project by adding the following line at the top of your file:
This library provides a set of functions for making it easier to work with ranges:
set_min_max(x, min_max, min_max_new): Takes an
min_max, and changes the limits to
min_max_new. Example usage:
color = [128, 0, 0] color = set_min_max(color, [0, 255], [0, 1]) #converts 0-255 color to 0-1 color range.
reverse_range(x, min_max): Reverses an
xvalue in a
min_maxrange. Suppose you have a
softnessvariable, but you made the program so that the higher the softness is, the harder it gets.
reverse_rangecan fix that for you:
softness = reverse_range(softness, [0, 10]) # If the variable was 0, this function made it 10. # similarly, if it had a value of 10, it is now 0.
is_in_range(x, min_max, limits = ['c', 'c']): Checks if an
xvalue is between
min_max. The limits of the range are closed by default, so if
xis equal to one of them, the function returns
True. However, you can choose between
o(closed/open) for each one of the two limits. An example:
isBetween = is_in_range(var, [25, 75])
range_lerp(min_max, t): Returns the linear interpolation between
min_max. The following line prints the value halfway between 1 and 5:
print(range_lerp([1, 5], 0.5)) # outputs 3
find_lerp(x, min_max): returns the corresponding
tvalue (between 0 and 1) of an
min_max. Consider the following examples:
print(find_lerp(5, [5, 10])) #outputs 0 print(find_lerp(10, [5, 10])) #outputs 1 print(find_lerp(8, [5, 10])) #outputs 0.6
clamp(x, min_max): Restricts the value to stay within the limits
var = clamp(var, [25, 75])
- qrange has been created
About the author
Hi! I am a solo software developer. I created qrange as an open source library to simplify the process of using ranges in Python. Check out my other repositories as well. If you want to support me, please buy me a coffee here. Any amount is appreciated! :)
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size qrange-1.0.6-py3-none-any.whl (3.5 kB)||File type Wheel||Python version py3||Upload date||Hashes View|
|Filename, size qrange-1.0.6.tar.gz (2.8 kB)||File type Source||Python version None||Upload date||Hashes View|