Book Image

Kivy Cookbook

By : Hugo Solis
Book Image

Kivy Cookbook

By: Hugo Solis

Overview of this book

Table of Contents (16 chapters)
Kivy Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Storing and retrieving the coordinate space context


The graphical environment in Kivy uses a coordinate space to locate the content. In this recipe, we will take a look at how to work with the coordinate space. This recipe will define a vector and make some basic operations with it.

Getting ready

Now we are going to use the mathematical concept of vectors. You will get a better understanding of this recipe if you have the concept clear. Read the Wikipedia about it, a good start point. The implementation is made on top of a Python list, so it is important to have a good understanding of that concept too.

How to do it…

In this recipe, we will work directly with Python to show the possibilities of the vectors in Kivy, for which we will use the common vector operations.

  1. First, let's define a vector:

    v = Vector(82, 34)
    
  2. Now if we want to retrieve the coordinate from a widget, we use:

    w = widget.pos
    
  3. The sum of the last two defined vectors is given by:

    x = v + w
    
  4. The product of those vectors is given...