Context instructions

The context instructions represent non graphics elements like:

  • Matrix manipulation (PushMatrix, PopMatrix, Rotate, Translate, Scale, MatrixInstruction)
  • Color manipulation (Color)
  • Texture binding (BindTexture)

Changed in version 1.0.8: LineWidth instruction have been removed. It wasn’t working before, and we actually no implementation working. We need to do more experimentation to get it right. Check the bug #207 for more informations.

class kivy.graphics.context_instructions.Color

Bases: kivy.graphics.instructions.ContextInstruction

Instruction to set the color state for any vertices being drawn after it. All the values passed are between 0 and 1, not 0 and 255.

In Python, you can do:

from kivy.graphics import Color

# create red color
c = Color(1, 0, 0)
# create blue color
c = Color(0, 1, 0)
# create blue color with 50% alpha
c = Color(0, 1, 0, .5)

# using hsv mode
c = Color(0, 1, 1, mode='hsv')
# using hsv mode + alpha
c = Color(0, 1, 1, .2, mode='hsv')

In kv lang:

<Rule>:
    canvas:
        # red color
        Color:
            rgb: 1, 0, 0
        # blue color
        Color:
            rgb: 0, 1, 0
        # blue color with 50% alpha
        Color:
            rgba: 0, 1, 0, .5

        # using hsv mode
        Color:
            hsv: 0, 1, 1

        # using hsv mode + alpha
        Color:
            hsv: 0, 1, 1
            a: .5
a

Alpha component, between 0-1

b

Blue component, between 0-1

g

Green component, between 0-1

h

Hue component, between 0-1

hsv

HSV color, list of 3 values in 0-1 range, alpha will be 1.

r

Red component, between 0-1

rgb

RGB color, list of 3 values in 0-1 range, alpha will be 1.

rgba

RGBA color, list of 4 values in 0-1 range

s

Saturation component, between 0-1

v

Value component, between 0-1

class kivy.graphics.context_instructions.BindTexture

Bases: kivy.graphics.instructions.ContextInstruction

BindTexture Graphic instruction. The BindTexture Instruction will bind a texture and enable GL_TEXTURE_2D for subsequent drawing.

Parameters :
texture: Texture

specifies the texture to bind to the given index

source

Set/get the source (filename) to load for texture.

class kivy.graphics.context_instructions.PushMatrix

Bases: kivy.graphics.instructions.ContextInstruction

PushMatrix on context’s matrix stack

class kivy.graphics.context_instructions.PopMatrix

Bases: kivy.graphics.instructions.ContextInstruction

Pop Matrix from context’s matrix stack onto model view

class kivy.graphics.context_instructions.Rotate

Bases: kivy.graphics.context_instructions.Transform

Rotate the coordinate space by applying a rotation transformation on the modelview matrix. You can set the properties of the instructions afterwards with e.g.:

rot.angle = 90
rot.axis = (0,0,1)
angle

Property for getting/settings the angle of the rotation

axis

Property for getting/settings the axis of the rotation

The format of the axis is (x, y, z).

set()

Set the angle and axis of rotation

>>> rotationobject.set(90, 0, 0, 1)
class kivy.graphics.context_instructions.Scale

Bases: kivy.graphics.context_instructions.Transform

Instruction to perform a uniform scale transformation

scale

Property for getting/setting the scale.

The same scale value is applied on all axis.

class kivy.graphics.context_instructions.Translate

Bases: kivy.graphics.context_instructions.Transform

Instruction to create a translation of the model view coordinate space

x

Property for getting/setting the translation on X axis

xy

2 tuple with translation vector in 2D for x and y axis

xyz

3 tuple translation vector in 3D in x, y, and z axis

y

Property for getting/setting the translation on Y axis

z

Property for getting/setting the translation on Z axis

class kivy.graphics.context_instructions.MatrixInstruction

Bases: kivy.graphics.instructions.ContextInstruction

Base class for Matrix Instruction on canvas

matrix

Matrix property. Numpy matrix from transformation module setting the matrix using this porperty when a change is made is important, becasue it will notify the context about the update