- Kivy:Interactive Applications in Python
- Roberto Ulloa
- 443字
- 2021-08-04 10:03:17
Chapter 2. Graphics – The Canvas
Any Kivy Widget
contains a Canvas
object. Be careful with the name because it might be confusing:
Note
A Canvas
is not the place where we draw. Instead, a Canvas
contains all the drawing instructions that will render the graphical representation of the Widget
.
The coordinate space refers to the place where we draw, what you might have thought to be the canvas is in the first place. In this chapter, you are going to learn how to draw and manipulate the representation of the widgets through the instructions that we add to the Canvas
instances:
- Draw 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 the
Canvas
that we can use to modify the order of execution - Storing and retrieving the current coordinate space context through
PushMatrix
andPopMatrix
Any Widget
contains its own Canvas
but all of them share the same coordinate space. This has consequences; for example, if we add a Rotate
instruction to a specific Canvas
(let's say the Canvas
of a Button
); it will also affect all the subsequent graphic instructions that are going to be displayed in the coordinate space. It doesn't matter if the graphics belong to canvases of different widgets. A context instruction changes the context of the coordinate space and we are going to learn strategies to control this.
Another important concept related to this is the Widget
. A Widget
is pretty much a place marker (with its position and size), but not necessarily a placeholder because the instructions of the Canvas
of a Widget
are not restricted to the specific area of the Widget
, but to the whole coordinate space. At the same time, the coordinate space is not even restricted to the visual space of the Kivy window and this might also create some difficulties.
In this chapter, you will learn the available statements to draw and change the context of the coordinate space. More importantly, you will understand the canvas as a set of instructions, the implications of sharing a coordinate space, and the concept of widgets as place markers. In the last section of the chapter, we will illustrate the acquired knowledge within the comic creator. Here, you will also learn the most common technique to deal with the problem of sharing the same coordinate space. By the end, we will be on complete control of the graphics that are displayed on the screen.
- Android Wearable Programming
- Spring Boot開發與測試實戰
- SQL Server 2012數據庫技術及應用(微課版·第5版)
- 深入淺出Spring Boot 2.x
- Instant Typeahead.js
- Java性能權威指南(第2版)
- PostgreSQL Replication(Second Edition)
- The Complete Coding Interview Guide in Java
- 微服務架構深度解析:原理、實踐與進階
- PHP編程基礎與實例教程
- Mastering Akka
- 從零開始學Android開發
- Machine Learning for OpenCV
- Clojure編程樂趣
- 面向對象分析與設計(第3版)