This documentation is for the free plugin Py4D in CINEMA 4D R11.5 and not for the C4DSDK of Python in CINEMA 4D R12. For R12, please visit PluginCafe.com

c4d.Gradient – a Gradient class

A datatype which contains information about a gradient. This type is called by value. Check out:

#op is a BaseList2D instance and contains a Gradient element at the given position [GRADIENT_1]
#in this case you have to send the object back to apply the change.
gradient = op[GRADIENT_1] # does not return a reference, just a copy of this element
gradient.DoubleKnots()   # edit the content
op[GRADIENT_1] = gradient # send back
class c4d.Gradient

Methods

Gradient.__init__([v])
Parameter:v (Gradient) – Copy constructor.
Return type:Gradient
Returns:The new gradient.
Gradient.__hash__()

Returns a hash of the whole gradient state, including the needles, colors and interpolation type.:

print hash(obj) #hash calls obj.__hash__()
Return type:int
Returns:Hash value
Gradient.InvertKnots()

Inverts the knots.

Return type:bool
Returns:True if successful, otherwise False.
Gradient.DoubleKnots()
Inverts the knots.
Gradient.FlushKnots()
Flushes all knots.
Gradient.InitRender()

Initializes the renderer.

Return type:bool
Returns:True if successfull, otherwise False.
Gradient.FreeRender()
Free the render.
Gradient.CalcGradientPixel(pos)

Calculates a gradient pixel. Needs InitRender before.

Parameter:pos (float) – X position.
Return type:Vector
Returns:Calculated pixel.
Gradient.InsertKnot([col][, brightness][, pos][, bias][, index])

Insert a knot. Not passed arguments will be set with default values.

Parameters:
  • col (Vector) – The color.
  • brightness (float) – The brightness.
  • pos (float) – The position.
  • bias (float) – The bias.
  • index (int) – The index.
Return type:

int

Returns:

The new knot

Note

The new knot index is GetKnotCount - 1

Gradient.RemoveKnot(index)

Delete a knot.

Parameter:index (int) –

index knot.

Note

0 <= index < GetKnotCount

Gradient.GetKnot(index)

Returns the information about a knot.

Parameter:index (int) – The index.
:type

Note

The new knot index has to be 0 <= index < Gradient.GetKnotCount

Check out this small example how to use:

col, brightness, pos, bias, index = gradient.GetKnot(index)
Parameters:
  • index – Knot index.
  • col (Vector) – The color.
  • brightness (float) – The brightness.
  • pos (float:) – The position.
  • bias (float) – The bias.
  • index (int) – The index.
Gradient.SetKnot(index[, col][, brightness][, pos][, bias])

Set the values of a knot. Just the passed arguments will be set, the other will be discarded.

Parameters:
  • index (int) –

    The knot index.

    Note

    The new knot index has to be 0 <= index < Gradient.GetKnotCount

  • col (Vector) – The color.
  • brightness (float) – The brightness.
  • pos (float) – The position.
  • bias (float) – The bias.
Gradient.GetData(id)

Gets a data item from the gradient container.

Parameter:id (int) –

One of the following flags

GRADIENT_INTERPOLATION int Interpolation
GRADIENT_KNOT BaseContainer Contains the knots as sub-containers.
GRADIENT_MODE int Mode
GRADIENT_UNCLAMPED bool Unclamped
Return type:Depends on id.
Returns:The data.
Gradient.SetData(id, data)

Gets a data item from the gradient container.

Parameters:
  • id (int) – One of the following flags
  • data (Depends on id.) – The data.
Gradient.GetKnotCount()

Gets the knot count.

Return type:int
Returns:Knot count.
Gradient.GetAlphaGradient()

Gets a copy of the alpha gradient. Is just a copy of the original gradient. Can be changed, but has no effect to the original alpha-gradient.

Return type:Gradient
Returns:Alpha gradient.

Table Of Contents

This Page