Creating Apps in Kivy by Dusty Phillips
Author:Dusty Phillips
Language: eng
Format: epub, mobi, pdf
ISBN: 9781491946671
Publisher: O’Reilly Media, Inc.
Published: 2014-09-01T04:00:00+00:00
It’ll be easier to understand the math if you first look at the effect in Figure 5-2 (your app won’t look like this until you hook up the main.py code in a couple minutes).
Figure 5-2. Rendering of clear, cold skies
This simple sunshine graphic is composed of some relatively simple instructions and some not completely simple mathematics. I’ll describe each instruction in turn.
First, a Color instruction sets a nice yellow-orange color in RGB format. It has 80% red, 70% green, and 30% blue, since Kivy RGB settings range from 0 to 1 in floating point.
This is followed by four Line instructions. These all have the same structure, composed of cap, width, and points properties. The width is obviously the width of the line. The cap can be set to a few different values; "round" gives the ends of the line a nice radiused feeling. The points property is a list of values for the line. Alternating values are x and y coordinates in the coordinate space of the window. This means that 0, 0 is the lower-left corner of the window. Therefore, it is typically wise to adjust the points relative to the pos or center of the widget holding the canvas to which you are issuing instructions.
Each line has four values in the points list. These values are used to draw a single line between two points. Each of the lines is the length of the height of the widget, and is centered on the widget. The first line has the same y coordinate (the middle of the window) for both points, so it represents a horizontal line. The second similarly represents a vertical line.
The latter two lines represent a cross at a 45-degree angle to the other lines. You can safely think of the value 0.35355 as “magic” unless you know basic trigonometry, in which case it is an approximation of √2 / 4, which combines the sine of 45° with a division by 2 on the height.
Finally, the color is made a bit darker, just for fun, and an ellipse with equal height and width (a circle) is drawn in front of the lines. This circle is smaller than the length of the lines, so they poke out behind it like a radix. Note my minor attempt at style: by making the color quite dark, I’ve made the white label readable in front of it.
Admittedly, that was not a lot of fun. It took me several minutes of fiddling to get the image to look the way I wanted it to. It isn’t normal to tweak graphics primitives by hand in the KV language, though it can be useful. Mathematically derived graphics are more often created in Python code, while artistic effects should be applied as textures to an image rather than being encoded in primitives.
If you’ve created this widget in weather.kv, you might be wondering how to turn it on in main.py. You can do this with a simple conditional in the render_conditions function, as you can see in Example 5-6.
Download
Creating Apps in Kivy by Dusty Phillips.mobi
Creating Apps in Kivy by Dusty Phillips.pdf
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Deep Learning with Python by François Chollet(12571)
Hello! Python by Anthony Briggs(9916)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9796)
The Mikado Method by Ola Ellnestam Daniel Brolund(9779)
Dependency Injection in .NET by Mark Seemann(9340)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8298)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7763)
Grails in Action by Glen Smith Peter Ledbrook(7696)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7557)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(7076)
Microservices with Go by Alexander Shuiskov(6843)
Practical Design Patterns for Java Developers by Miroslav Wengner(6765)
Test Automation Engineering Handbook by Manikandan Sambamurthy(6703)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6414)
Angular Projects - Third Edition by Aristeidis Bampakos(6109)
The Art of Crafting User Stories by The Art of Crafting User Stories(5640)
NetSuite for Consultants - Second Edition by Peter Ries(5570)
Demystifying Cryptography with OpenSSL 3.0 by Alexei Khlebnikov(5378)
Kotlin in Action by Dmitry Jemerov(5063)
