官术网_书友最值得收藏!

Chapter 2. Graphics – the Canvas

Any Kivy Widget contains a Canvas object. A Kivy Canvas is a set of drawing instructions that define the graphical representation of Widget.

Tip

Be careful with the name because it tends to be confusing! A Canvas object is not what we draw on (for example, as it is in HTML5); it is a set of instructions to draw in the coordinate space.

The coordinate space refers to the place in which we draw. All the Kivy widgets share the same coordinate space, and a Canvas instance, the instructions to draw on it. A coordinate space is not restricted to the size of the window or the application screen, which means that we can draw outside of the visible area.

We will discuss how to draw and manipulate the representation of the widgets through the instructions we add to the Canvas object. Here is a list of the most important skills that we will cover:

  • Drawing basic geometric shapes (straight and curve lines, ellipses, and polygons) through vertex instructions
  • Using colors, and rotating, translating, and scaling the coordinate space through the context instructions
  • The difference between vertex and context instructions and how they complement each other
  • The three different sets of instructions of Canvas that we can use to modify the order of execution of the graphics instructions
  • Storing and retrieving the current coordinate space context through PushMatrix and PopMatrix

Using the Kivy canvas brings with it some technical challenges because Kivy integrates graphic processing with efficiency in mind. These challenges are not initially obvious, but there is nothing particularly difficult about them if we understand the underlying problem. This is why the next section is dedicated to introduce the main considerations that we face when we use the canvas.

主站蜘蛛池模板: 芦溪县| 航空| 牟定县| 贵德县| 阿图什市| 石嘴山市| 黔西县| 鹤峰县| 民县| 翼城县| 仪陇县| 横峰县| 龙游县| 阿勒泰市| 平江县| 张掖市| 岑溪市| 闽清县| 大姚县| 安国市| 凤阳县| 永寿县| 大化| 绥中县| 将乐县| 江山市| 遂溪县| 丹寨县| 岐山县| 青海省| 平江县| 宿州市| 鄂托克前旗| 永胜县| 威信县| 勐海县| 濮阳县| 商河县| 房产| 永胜县| 嵊州市|