Details zum E-Book

Python 2.6 Graphics Cookbook. Learn how to use Python’s built-in graphics capabilities to create static and animated graphics for a range of real-world purposes. Over 100 recipes take you from basic shape creation to developing interactive GUIs

Python 2.6 Graphics Cookbook. Learn how to use Python’s built-in graphics capabilities to create static and animated graphics for a range of real-world purposes. Over 100 recipes take you from basic shape creation to developing interactive GUIs

Mike Ohlson de Fine, Michael J Ohlson

E-book
Python is a great object-oriented and interactive programming language that lets you develop graphics, both static and animated, using built-in vector graphics functions that are provided with Python.

Python 2.6 Graphics Cookbook is a collection of straightforward recipes and illustrative screenshots for creating and animating graphic objects using the Python language. This book makes the process of developing graphics interesting and entertaining by working in a graphic workspace without the burden of mastering complicated language definitions and opaque examples.

If you choose to work through all the recipes from the beginning, you will learn to install Python and create basic programs for making lines and shapes using the built-in Tkinter module. The confusing topic of color manipulation is explored in detail using existing Python tools as well as some new tools in the recipes. Next you will learn to manipulate font size, color, and placement of text as placing text exactly where you want on a screen can be tricky because font height, inter-character spacing, and text window dimensions all interfere with each other. Then you will learn how to animate graphics, for example having more than one independent graphic object co-exist and interact using various Python methods.

You will also learn how you can work with raster images, such as converting their formats using the Python Imaging Library. Next you will learn how you can combine vector images with raster images so that you can animate the raster images with ease. You will also walk through a set of recipes with the help of which you can handle and manipulate blocks of raw data that may be hundreds of megabytes in size using datastreams, files, and hard drives. You will also learn how you can use Inkscape to dismantle existing images and use parts of them for your own graphics and Python programs. At the end of the book you will learn how you can create GUIs for different purposes.
  • Python 2.6 Graphics Cookbook
    • Table of Contents
    • Python 2.6 Graphics Cookbook
    • Credits
    • About the Author
    • About the Reviewers
    • Preface
      • What this book covers
      • What you need for this book
      • Who this book is for
      • Conventions
      • Reader feedback
      • Customer support
        • Errata
        • Piracy
        • Questions
    • 1. Start your Engines
      • Introduction
      • Running a shortest Python program
        • How to do it...
        • How it works...
        • Theres more...
      • Ensuring that the Python modules are present
        • How to do it...
        • How it works...
        • There's more...
      • A basic Tkinter program
        • How to do it...
        • How it works...
      • Make a compiled executable under Windows and Linux
        • Getting ready
        • How to do it under MS Windows...
        • How to do it under Linux (Debian and Ubuntu)...
        • How to compile under both Linux and MS Windows...
        • How it works...
        • What about py2exe?
    • 2. Drawing Fundamental Shapes
      • Introduction
      • A straight line and the coordinate system
        • How to do it...
        • How it works...
        • There's more...
      • Draw a dashed line
        • How to do it...
        • How it works...
        • There's more...
      • Lines of varying styles with arrows and endcaps
        • How to do it...
        • How it works...
        • There's more...
      • A two segment line with a sharp bend
        • How to do it...
        • How it works...
        • There's more...
      • A line with a curved bend
        • How to do it...
        • How it works...
        • There's more...
      • Drawing intricate shapes the curly vine
        • Getting ready
        • How to do it
        • How it works...
        • There's more...
      • Draw a rectangle
        • How to do it...
        • How it works...
        • There's more...
      • Draw overlapping rectangles
        • How to do it...
        • How it works...
        • There's more...
      • Draw concentric squares
        • How to do it...
        • How it works...
      • A circle from an oval
        • How to do it...
        • How it works...
        • There's more...
      • A circle from an arc
        • How to do it...
        • How it works...
        • There's more...
      • Three arc ellipses
        • How to do it...
        • How it works...
        • There's more...
      • Polygons
        • How to do it...
        • How it works...
      • A star polygon
        • How to do it...
        • How it works...
      • Cloning and resizing stars
        • How to do it...
        • How it works...
        • There's more...
    • 3. Handling Text
      • Introduction
      • Simple text
        • How to do it...
        • How it works...
        • There's more...
      • Text font type, size, and color
        • Getting ready
        • How to do it...
        • How it works...
        • There's more...
        • Getting ready
        • How to do it...
        • How it works...
      • Alignment of text left and right justify
        • Getting ready
        • How to do it...
        • How it works...
      • All the fonts available on your computer
        • How to do it...
        • How it works...
    • 4. Animation Principles
      • Introduction
      • Static shifting of a ball
        • How to do it...
        • How it works...
        • There's more...
      • Time-controlled shifting of a ball
        • How to do it...
        • How it works...
        • There's more...
          • The robustness of Tkinter
      • Complete animation using draw-move-pause-erase cycles
        • How to do it...
        • How it works...
        • There's more...
      • More than one moving object
        • How to do it...
        • How it works...
        • There's more...
      • A ball that bounces
        • How to do it...
        • How it works...
      • Bouncing in a gravity field
        • How to do it...
        • How it works...
        • There's more...
        • See also
      • Precise collisions using floating point numbers
        • How to do it...
        • How it works...
        • A graphic debugging tool...
      • Trajectory tracing and ball-to-ball collisions
        • How to do it...
        • How it works...
        • There's more...
        • Why do we sometimes get tkinter.TckErrors?
      • Rotating line
        • Getting ready
        • How to do it...
        • How it works...
        • There's more...
      • Trajectory tracing on multiple line rotations
        • Getting ready
        • How to do it...
        • How it works...
        • There's more...
      • A rose for you
        • How it works...
    • 5. The Magic of Color
      • Introduction
      • A limited palette of named colors
        • How to do it...
        • How it works...
        • There's more...
          • To get fine shadings of the primary colors
          • A more compact color list
      • Nine ways of specifying color
        • How to do it...
        • How it works...
        • Converting color tuples to Tkinter Hex compatible specifiers
      • A red beachball of varying hue
        • How to do it...
        • How it works...
        • There's more...
      • A red color wedge of graded hue
        • How to do it...
        • How it works...
        • There's more...
      • Newton's grand wheel of color mixing
        • How to do it...
        • How it works...
        • There's more...
      • The numerical color mixing matching palette
        • How to do it...
        • How it works...
        • There's more...
          • There are other tools to select colors
          • Is there a way to make neater slide controllers?
      • The animated graded color wheel
        • How to do it...
        • How it works...
      • Tkinter's own color picker-mixer
        • How to do it...
        • How it works...
        • There's more...
    • 6. Working with Pictures
      • Opening an image file and discovering its attributes
        • Getting ready
        • How to do it...
        • How it works...
        • There's more...
          • Things we need to know about image formats
          • Images and the numbers game
      • Open, view, and save an image in a different file format
        • Getting ready
        • How to do it...
        • How it works...
        • There's more...
      • Image format conversion for JPEG, PNG, TIFF, GIF, BMP
        • Getting ready
        • How to do it...
        • How it works...
        • There's more...
          • Does size count?
      • Image rotation in the plane of the image
        • Getting ready
        • How to do it...
        • How it works...
        • There's more...
      • Image size alteration
        • Getting ready
        • How to do it...
        • How it works...
        • There's more...
          • How do we preserve the correct height-to-width ratio of an image?
      • Correct proportion image resizing
        • Getting ready
        • How to do it...
        • How it works...
      • Separating one color band in an image
        • Getting ready
        • How to do it...
        • How it works...
        • There's more...
      • Red, green, and blue color alteration in images
        • Getting ready
        • How to do it...
        • How it works...
        • There's more...
      • Slider controlled color manipulation
        • Getting ready
        • How to do it...
        • How it works...
      • Combining images by blending
        • Getting ready
        • How to do it...
        • There's more...
          • More Info Section 1
      • Blending images by varying percentages
        • How to do it...
        • How it works...
        • There's more...
      • Make a composite image using a mask image
        • Getting ready
        • How to do it...
        • How it works...
        • There's more...
        • See also
      • Offset (roll) image horizontally and vertically
        • Getting ready
        • How to do it...
        • How it works...
      • Flip horizontally, vertically, and rotate
        • Getting ready
        • How to do it...
        • How it works...
      • Filter effects: blur, sharpen, contrast, and so on
        • Getting ready
        • How to do it...
        • How it works...
        • Getting ready
        • How to do it...
        • How it works...
        • There's more...
    • 7. Combining Raster and Vector Pictures
      • Simple animation of a GIF beach ball
        • Getting ready
        • How to do it...
        • How it works...
      • The vector walking creature
        • Getting ready
        • How to do it...
        • How it works...
        • There's more...
          • More Info Section 1
      • Bird with shoes walking in the Karroo
        • Getting ready
        • How to do it...
        • How it works...
        • There's more...
      • Making GIF images with transparent backgrounds using GIMP
        • Getting ready
        • How to do it...
        • How it works...
      • Diplomat walking at the palace
        • Getting ready
        • How to do it...
        • How it works...
      • Spider in the forest
        • Getting ready
        • How to do it...
        • How it works...
        • There's more...
      • Moving band of images
        • Getting ready
        • How to do it...
        • How it works...
      • Continuous band of images
        • Getting ready
        • How to do it...
        • How it works...
      • Endless background
        • Getting ready
        • How to do it...
        • How it works...
    • 8. Data In and Data Out
      • Introduction
      • Creation of a new file on a hard drive
        • How to do it...
        • How it works...
        • How to read the newly created file
      • Writing data to a newly-created file
        • How it works...
      • Writing data to multiple files
        • How it works...
      • Adding data to existing files
        • How it works...
        • So remember the difference between write and append
      • Saving a Tkinter-drawing shape to disk
        • Getting ready
        • How to do it...
        • How it works...
        • Storing commands
      • Retrieving Python data from disk storage
        • Getting ready
        • How it works...
      • Simple mouse input
        • How it works...
        • There's more...
      • Storing and retrieving a mouse-drawn shape
        • Getting ready
        • How it works...
        • There's more...
        • We need to edit mistakes
      • A mouse-line editor
        • Getting ready
        • How it works...
        • There's more...
          • Why don't we add more features?
          • Using other tools to acquire and re-work images
          • How to exploit that mouse
          • We can measure the distance along a meandering line
      • All possible mouse actions
        • How to do it...
        • How it works...
        • There's more...
    • 9. Exchanging Inkscape SVG Drawings with Tkinter Shapes
      • Introduction
      • The structure of an SVG drawing
        • Getting ready
        • How to do it...
        • How it works...
        • There's more...
          • SVG code for separate paths
      • Tracing the shape of an image in Inkscape
        • Getting ready
        • How to do it...
        • How often do we need to click the mouse?
        • Another way to get SVG paths from raster images
      • Converting an SVG path into a Tkinter Line
        • Getting ready
        • How to do it...
        • How it works...
        • There's more...
          • How far should we go with image conversion code?
          • Another way to get SVG paths from raster images
    • 10. GUI Construction: Part 1
      • Introduction
      • Widget configuration a label
        • How to do it...
        • How it works...
        • There's more...
      • Button focus
        • How to do it...
        • How it works...
        • There's more...
      • The simplest push button with validation
        • How to do it...
        • How it works...
        • There's more...
          • Buttons behave differently on Windows
      • A data entry box
        • How to do it...
        • How it works...
        • There's more...
          • Did we keep things simple?
          • Single-line versus multi-line entry
          • The Clever Geometry Manager
      • Colored button causing a message pop-up
        • How to do it...
        • How it works...
      • Complex interaction between buttons
        • How to do it...
        • How it works...
      • Images on buttons and button packing
        • How to do it...
        • How it works...
        • There's more...
      • Grid Geometry Manager and button arrays
        • How to do it...
        • How it works...
        • There's more...
      • Drop-down menus to select from a list
        • How to do it...
        • How it works...
      • Listbox variable selection
        • How to do it...
        • How it works...
      • Text in a window
        • How to do it...
        • How it works...
    • 11. GUI Construction: Part 2
      • Introduction
      • The Grid Layout Geometry Manager
        • Getting ready
        • How to do it...
        • How it works...
        • There's more...
      • The Pack Geometry Manager
        • Getting ready
        • How to do it...
        • How it works...
      • Radiobuttons to select one from many
        • How to do it...
        • How it works...
      • Checkbuttons (Tickboxes) to select some of many
        • How to do it...
        • How it works...
      • Key-stroke event handling
        • How to do it...
        • How it works...
      • Scrollbar
        • How to do it...
        • How it works...
        • There's more...
      • Custom DIY controller widgets
        • How to do it...
        • How it works...
        • There's more...
      • Organizing widgets inside frames
        • How to do it...
        • How it works...
        • There's more...
    • A. Quick tips for running Python programs in Microsoft Windows
      • Running Python programs in Microsoft Windows
      • Where will we find the windows installer?
      • Do we have to use Python version 2.7?
      • Why do we get "python is not recognized"?
    • Index
  • Titel: Python 2.6 Graphics Cookbook. Learn how to use Python‚Äôs built-in graphics capabilities to create static and animated graphics for a range of real-world purposes. Over 100 recipes take you from basic shape creation to developing interactive GUIs
  • Autor: Mike Ohlson de Fine, Michael J Ohlson
  • Originaler Titel: Python 2.6 Graphics Cookbook. Learn how to use Python‚Äôs built-in graphics capabilities to create static and animated graphics for a range of real-world purposes. Over 100 recipes take you from basic shape creation to developing interactive GUIs.
  • ISBN: 9781849513852, 9781849513852
  • Veröffentlichungsdatum: 2010-11-24
  • Format: E-book
  • Artikelkennung: e_3cdw
  • Verleger: Packt Publishing