Module gwy :: Class Gradient
[hide private]
[frames] | no frames]

Class Gradient

source code

A map from numbers to RGBA colors

Gradient is a map from interval [0,1] to RGB(A) color space. Each gradient is defined by an ordered set of color points, the first of them is always at 0.0, the last at 1.0 (thus each gradient must consist of at least two points). Between them, the color is interpolated. Color points of modifiable gradients (see Resource) can be edited with functions like Gradient.insert_point(), Gradient.set_point_color(), or Gradient.set_points().

Gradient objects can be obtained from gwy_gradients_get_gradient(). New gradients can be created with Inventory.new_item() on the Inventory returned by gwy_gradients().

Instance Methods [hide private]
 
get_color(x, color)
Computes the color at a given position of a color gradient.
source code
 
sample_to_pixbuf(pixbuf)
Samples a color gradient to a provided pixbuf.
source code
 
get_npoints()
Returns the number of points in a color gradient.
source code
 
get_point(index_)
Returns the point at given index of a color gradient.
source code
 
set_point(index_, point)
Sets a single color point in a color gradient.
source code
 
set_point_color(index_, color)
Sets the color of a color gradient point without moving it.
source code
 
delete_point(index_)
Deletes a point at given index in a color gradient.
source code
 
reset()
Resets a gradient to the default two-point gray scale state.
source code
 
get_points()
Returns the complete set of color points of a gradient.
source code
 
set_points(npoints, points)
Sets the complete color gradient definition to a given set of points.
source code
 
set_from_samples(nsamples, samples, threshold)
Reconstructs a color gradient definition from sampled colors.
source code
Method Details [hide private]

get_color(x, color)

source code 

Computes the color at a given position of a color gradient.

Parameters:
  • x - Position in gradient, in range 0..1. (float)
  • color - Color to fill with interpolated color at position x. (RGBA)

sample_to_pixbuf(pixbuf)

source code 

Samples a color gradient to a provided pixbuf.

Unlike Gradient.sample() which simply takes samples at equidistant points this method uses supersampling and thus it gives a bit better looking gradient presentation.

Parameters:
  • pixbuf - A pixbuf to sample gradient to (in horizontal direction). (gdk.Pixbuf)

get_npoints()

source code 

Returns the number of points in a color gradient.

Returns:
The number of points in gradient. (int)

get_point(index_)

source code 

Returns the point at given index of a color gradient.

Parameters:
  • index_ - Color point index in gradient. (int)
Returns:
Color point at index_. (GradientPoint)

set_point(index_, point)

source code 

Sets a single color point in a color gradient.

It is an error to try to move points beyond its neighbours, or to move first (or last) point from 0 (or 1).

Parameters:
  • index_ - Color point index in gradient. (int)
  • point - Color point to replace current point at index_ with. (const-GradientPoint*)

set_point_color(index_, color)

source code 

Sets the color of a color gradient point without moving it.

Parameters:
  • index_ - Color point index in gradient. (int)
  • color - Color to set the point to. (const-RGBA*)

delete_point(index_)

source code 

Deletes a point at given index in a color gradient.

It is not possible to delete points in gradients with less than 3 points. First and last points should not be deleted unless there's another point with x = 0 or x = 1 present.

Parameters:
  • index_ - Color point index in gradient. (int)

get_points()

source code 

Returns the complete set of color points of a gradient.

Returns:
Tuple consisting of 2 values (value, npoints). ((const-GradientPoint*), (int))

set_points(npoints, points)

source code 

Sets the complete color gradient definition to a given set of points.

The point positions should be ordered, and first point should start at 0.0, last end at 1.0. There should be no redundant points.

Parameters:
  • npoints - The length of points. (int)
  • points - Color points to set as new gradient definition. (const-GradientPoint*)

set_from_samples(nsamples, samples, threshold)

source code 

Reconstructs a color gradient definition from sampled colors.

The result is usually approximate.

Parameters:
  • nsamples - Number of samples, it must be at least one. (int)
  • samples - Sampled color gradient in GdkPixbuf-like RRGGBBAA form. (string)
  • threshold - Maximum allowed difference (for color components in range 0..1). When negative, default value 1/80 suitable for most purposes is used. (float)