Skip to content

Ramarren/color-gradients

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A simple color gradient generation library for Common Lisp. It computes linear of radial gradients. Multistop color progression using linear or sin^2 interpolation is available.

Usage:

*steps-per-stop* controls a default number of steps in color interpolation table per color stop

make-linear-gradient (point-1 point-2
		      &key (color-1 '(0 0 0 255)) (color-2 '(255 255 255 255))
			   (steps (* 2 *steps-per-stop*)) (table nil) (fixnum-xy nil) (repeat :pad))

This returns two values. A primary values is a closure of two arguments, coordinates in a gradient space returning a list of RGBA components of a color, as integers in 0-255 range. Returned lists are shared, and so should not be modified.

The second value is a color table, to allow reuse of precomputed color tables for gradients.

The arguments for make-linear-gradient:
 point-1 point-2 are lists of two coordinates of points delimiting a gradient
 color-1 color-2 are lists of color components of form (R G B) or (R G B A), opaque black is default for color-1, opaque white for color-2, if no alpha is provided it defaults to 255
 steps is a number of steps in precomputed color table
 table is an array of lists of colors, if this argument is provided color-1, color-2 and steps are ignored and table is use used as a precomputed color table. This allows sharing tables between gradients by capturing second return value and using arbitrary color progressions.
 fixnum-xy if not null, a closure is generated which arguments are declared to be fixnums
 repeat is one of :pad, :repeat or :reflect, and it determines whether color just continues behind boundary, it is repeated by jumping from color-2 to color-1 directly, or is went through in reverse

make-radial-gradient is similar, except is takes circle-1 and circle-2 instead of points, which are lists of form (x y radius) defining the circles. circle-1 should be entirely contained inside circle-2, but this is not checked. fixnum-xy is ignored, other arguments are identical

make-angular-gradient is also similar, but has three non-optional arguments: center point, start angle and end angle

make-multistop-table (stops &key (steps nil) (interpolation :linear))
stops is a list of lists of four or five elements, first marking a stop position between 0 and 1, and the rest specify color components as above, there have to be at least two stops, but they do not have to be in order
steps specify the size of color table, if not provided it is *steps-per-stop* times the number of steps is assumed
interpolation is one of :linear :sin2, specify color interpolation between stops

this table can be used by :table argument to make-*-gradient functions, see above

About

A simple Common Lisp library for generation of color gradients.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published