Kivy Blueprints

Book description

Build your very own app-store-ready, multi-touch games and applications with Kivy!

In Detail

Kivy is a Modern UI framework that greatly simplifies the development of cross-platform apps suitable for both mobile and desktop.

This book is a practical guide that will walk you through the creation of intuitive multi-platform games and apps for day-to-day use. You will learn how to build simple, common apps such as Stopwatch and Paint. Then, we will gradually dive into more advanced Python and Kivy features. We will also cover a number of related topics ranging from UI design to low-level GLSL shaders. You will be able to fill your resume with practical applications and games, including those inspired by the insanely popular puzzle game 2048 and Flappy Bird. Each chapter covers a fully functional program, highlighting different aspects of the Kivy framework.

What You Will Learn

  • Set up a development environment for Python and Kivy programming
  • Build cross-platform applications suitable for desktop and mobile
  • Create Modern UI apps reminiscent of Windows Phone flat design
  • Interface with the native Android API to broaden the scope of what functionality is available to your apps
  • Customize your applications by modifying the built-in Kivy features for your project specifications
  • Develop full-stack, client-server solutions with the backend and UI both written in Python
  • Write modular, reusable code while utilizing various aspects of the Kivy framework
  • Write your own cross-platform video-games, ready for distribution on Google Play, App Store, or even Steam

Table of contents

  1. Kivy Blueprints
    1. Table of Contents
    2. Kivy Blueprints
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    7. Preface
      1. Write once, run anywhere
      2. What this book covers
      3. Setting up the working environment
        1. A note on Python
        2. Installing and running Kivy
        3. Note on coding
      4. Hello, Kivy
        1. Code
        2. Layout
      5. Who this book is for
      6. Conventions
      7. Reader feedback
      8. Customer support
        1. Downloading the example code
        2. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    8. 1. Building a Clock App
      1. The starting point
      2. Modern UI
        1. Design inspiration
        2. Loading custom fonts
        3. Formatting text
        4. Changing the background color
      3. Making the clock tick
        1. Updating the time on the screen
        2. Binding widgets using properties
      4. Layout basics
        1. Finalizing the layout
        2. Reducing repetition
          1. Named classes
      5. Styling buttons
        1. 9-patch scaling
        2. Using 9-patch images
      6. Counting time
        1. Formatting the time for stopwatch
          1. Computing values
          2. Putting a stopwatch in place
      7. Stopwatch controls
      8. Summary
    9. 2. Building a Paint App
      1. Setting the stage
      2. Fine-tuning the looks
        1. Visual appearance
        2. Window size
        3. Mouse cursor
        4. Multitouch emulation
      3. Drawing touches
        1. A very short introduction to the canvas
        2. Displaying touches on the screen
      4. Clearing the screen
        1. Passing events
        2. Clearing the canvas
      5. Connecting the dots
      6. The color palette
        1. Subclassing the buttons
        2. Taking away the ability to deselect
          1. Overriding the standard behavior
        3. Coloring buttons
          1. A new kind of button
          2. Defining the palette
      7. Setting the line thickness
        1. Changing the line width
      8. Summary
    10. 3. Sound Recorder for Android
      1. Writing platform-dependent code
        1. Introducing Pyjnius
        2. Emulating Android
      2. Metro UI
        1. The buttons
        2. The grid structure
          1. Visual attributes
        3. Scalable vector icons
          1. Icon fonts
          2. Rationale for using icon fonts
          3. Using the icon font in Kivy
      3. Testing on Android
      4. Using the native API
        1. Loading Java classes
        2. Looking up the storage path
          1. Reading logs from the device
        3. Recording sound
          1. Major caveat – permissions
        4. Playing sound
        5. Deleting files
      5. Summary
    11. 4. Kivy Networking
      1. Writing the chat server
        1. The protocol definition
        2. The server source code
        3. The principle of operation
        4. Testing the server
      2. Screen manager
        1. Customizing the animation
        2. Login screen layout
        3. Chatroom screen layout
          1. Overscroll modes
      3. Bringing the app online
        1. Building a simple Python client
        2. Kivy integration with Twisted
          1. ChatClient and ChatClientFactory
        3. UI integration
        4. Application logic of the client
        5. Cross-application interoperability
      4. Enhancements and eye candy
        1. Escaping the special syntax
        2. What's next
      5. Summary
    12. 5. Making a Remote Desktop App
      1. The server
        1. The Flask web server
        2. Advanced server functionality – taking screenshots
        3. Emulating clicks
      2. JavaScript client
        1. Endless loop of screenshots
        2. Passing clicks to host
      3. Kivy Remote Desktop app
        1. The login form
        2. The remote desktop screen
        3. Loop of screenshots in Kivy
        4. Sending clicks
        5. What's next
      4. Summary
    13. 6. Making the 2048 Game
      1. About the game
        1. Gameplay concepts and overview
          1. Randomness, or lack thereof
        2. The 2048 project outline
        3. What makes 2048 a good choice of project?
          1. Simplicity as a feature
      2. Creating the 2048 board
        1. Going through cells
        2. Rendering empty cells
        3. Board data structure
          1. Variable naming
          2. Calling reset()
        4. Testing passability
      3. Making tiles
        1. Tile initialization
        2. Resizing tiles
      4. Implementing the game logic
        1. Moving tiles
          1. Controlling the iteration sequence
          2. Implementing the move() method
          3. Binding touch controls
        2. Combining tiles
        3. Adding more tiles
          1. Synchronizing turns
        4. Game over
          1. The winning condition
          2. The loss condition
      5. Where to go from here
      6. Summary
    14. 7. Writing a Flappy Bird Clone
      1. Project overview
      2. Creating an animated background
        1. Loading tileable textures
        2. The Background widget
        3. Animating the background
      3. Making pipes
        1. An overview of the pipe properties
        2. Setting texture coordinates
        3. Implementing pipes
        4. Spawning pipes
        5. Moving and recycling pipes
      4. Introducing Kivy Bird
        1. Revised application flow
          1. Accepting user input
        2. Learning to fly straight down
          1. Remaining in flight
        3. Rotating the bird
      5. Collision detection
        1. Game over
      6. Producing sound effects
        1. Kivy sound playback
        2. Adding sound to the Kivy Bird game
      7. Summary
    15. 8. Introducing Shaders
      1. Unscientific introduction to OpenGL
        1. Concepts and parallelism
        2. Performance gains, or lack thereof
          1. Improving performance
        3. Taking a closer look at GLSL
      2. Using custom shaders in Kivy
        1. Building the geometry
          1. Illustrating the Indices
        2. Writing GLSL
          1. Storage classes and types
          2. Basic shaders
          3. Procedural coloring
          4. Colorful vertices
          5. Texture mapping
      3. Making the Starfield app
        1. Application structure
        2. Data structures and initializers
        3. Advancing the scene
        4. Writing a corresponding GLSL
      4. Summary
    16. 9. Making a Shoot-Em-Up Game
      1. Limitations of the project
      2. Texture atlases at a glance
        1. Creating an atlas
        2. Atlas structure
        3. Using Kivy atlases in an easy way
        4. Ad hoc usage of atlases with GLSL
          1. Data structure for UV mapping
          2. Writing an atlas loader
          3. Rendering sprites from atlas
      3. Designing a reusable particle system
        1. Class hierarchy
          1. The PSWidget renderer class
          2. The Particle class
      4. Writing the game
        1. Implementing stars
        2. Making a spaceship
        3. Creating a trail of fire
        4. Making bullets
        5. Implementing enemies
          1. Collision detection
      5. Finishing touches
      6. Summary
    17. A. The Python Ecosystem
    18. Index

Product information

  • Title: Kivy Blueprints
  • Author(s): Mark Vasilkov
  • Release date: January 2015
  • Publisher(s): Packt Publishing
  • ISBN: 9781783987849