Gradient Library
Posted: Wed Aug 01, 2018 6:29 pm
UPDATE (6/11/2018):
I added a new parameter for this library: GRADIENT.interpMethod$. This parameter that allows you to choose between one of several interpolation methods. This controls how transitional color and alpha values are calculated. Supported methods:
Overview
Functions provided:
NOTE: In order to draw smooth gradients at very high resolutions, these functions set the graphics mode to COPY, meaning that wherever a gradient is drawn, data under the gradient will be destroyed. If a gradient with transparency (alpha values < 1) is intended to be placed above other graphics, then draw the gradient in a sprite and position the sprite at the correct location (you can also stamp the sprite and then delete it if you want). Remember to set the graphics mode back to the desired setting after calling one of these functions!
(This is why I requested a GET GRAPHICS MODE M$ command! https://kibernetik.pro/forum/viewtopic.php?f=24&t=1463)
NOTE: Each function sets FILL ALPHA to 1 on completion
More details about function inputs and parameters and info on the interpolation method used for interpolating between gradients stops can be found in the library file's header.
Code
Code can be found here: https://www.dropbox.com/sh/431yatilp3zc ... mCZ6a?dl=0
There are four files required for this library (in the lib folder), though only one needs to be referenced in your code to use the library. The four files are:
I added a new parameter for this library: GRADIENT.interpMethod$. This parameter that allows you to choose between one of several interpolation methods. This controls how transitional color and alpha values are calculated. Supported methods:
- "linear" = Linear Interpolation
- "cosine" = Cosine Interpolation
- "poly5" = Parameterized 5th Order Polynomial
- "cubic" = Cubic Hermite Splines
- "cubicM" = Cubic Hermite Splines (Monotonic)
Overview
Functions provided:
- RECTGRAD (cD(,), aD(,), x, y, w, h, dir$)
- QUADGRAD (cD(,), aD(,), x(), y(), dir$)
- ELPSGRAD (cD(,), aD(,), x, y, rx, ry, dir$)
NOTE: In order to draw smooth gradients at very high resolutions, these functions set the graphics mode to COPY, meaning that wherever a gradient is drawn, data under the gradient will be destroyed. If a gradient with transparency (alpha values < 1) is intended to be placed above other graphics, then draw the gradient in a sprite and position the sprite at the correct location (you can also stamp the sprite and then delete it if you want). Remember to set the graphics mode back to the desired setting after calling one of these functions!
(This is why I requested a GET GRAPHICS MODE M$ command! https://kibernetik.pro/forum/viewtopic.php?f=24&t=1463)
NOTE: Each function sets FILL ALPHA to 1 on completion
More details about function inputs and parameters and info on the interpolation method used for interpolating between gradients stops can be found in the library file's header.
Code
Code can be found here: https://www.dropbox.com/sh/431yatilp3zc ... mCZ6a?dl=0
There are four files required for this library (in the lib folder), though only one needs to be referenced in your code to use the library. The four files are:
- gradient = The main library file. Include this in any program where you want to draw gradients using this library.
- gradient_init = File containing an initialization subroutine used by all three gradient functions.
- gradient_rgba = File containing an interpolation subroutine used by all three gradient functions.
- cubic_hermite_splines = File containing functions for the "cubic" and "cubicM" interpolation methods.
- Loading Screen Demo
- Speed Test (Shapes)
- Speed Test (Fullscreen)
- Ease Accel Comparison
- Interpolation Comparison