Python 2.6 Graphics Cookbook


Python 2.6 Graphics Cookbook
eBook: $26.99
Formats: PDF, PacktLib, ePub and Mobi formats
$16.20
save 40%!
Print + free eBook + free PacktLib access to the book: $71.98    Print cover: $44.99
$61.19
save 15%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Overview
Table of Contents
Author
Support
Sample Chapters
  • Create captivating graphics with ease and bring them to life using Python
  • Apply effects to your graphics using powerful Python methods
  • Develop vector as well as raster graphics and combine them to create wonders in the animation world
  • Create interactive GUIs to make your creation of graphics simpler
  • Part of Packt's Cookbook series: Each recipe is a carefully organized sequence of instructions to accomplish the task of creation and animation of graphics as efficiently as possible

Book Details

Language : English
Paperback : 260 pages [ 235mm x 191mm ]
Release Date : November 2010
ISBN : 1849513848
ISBN 13 : 9781849513845
Author(s) : Mike Ohlson de Fine
Topics and Technologies : All Books, Other, Cookbooks, Open Source, Python, Web Graphics & Video


Table of Contents

Preface
Chapter 1: Start your Engines
Chapter 2: Drawing Fundamental Shapes
Chapter 3: Handling Text
Chapter 4: Animation Principles
Chapter 5: The Magic of Color
Chapter 6: Working with Pictures
Chapter 7: Combining Raster and Vector Pictures
Chapter 8: Data In and Data Out
Chapter 9: Exchanging Inkscape SVG Drawings with Tkinter Shapes
Chapter 10: GUI Construction: Part 1
Chapter 11: GUI Construction: Part 2
Appendix: Quick tips for running Python programs in Microsoft Windows
Index
  • Chapter 1: Start your Engines
    • Introduction
    • Running a shortest Python program
    • Ensuring that the Python modules are present
    • A basic Tkinter program
    • Make a compiled executable under Windows and Linux
  • Chapter 2: Drawing Fundamental Shapes
    • Introduction
    • A straight line and the coordinate system
    • Draw a dashed line
    • Lines of varying styles with arrows and endcaps
    • A two segment line with a sharp bend
    • A line with a curved bend
    • Drawing intricate shapes – the curly vine
    • Draw a rectangle
    • Draw overlapping rectangles
    • Draw concentric squares
    • A circle from an oval
    • A circle from an arc
    • Three arc ellipses
    • Polygons
    • A star polygon
    • Cloning and resizing stars
  • Chapter 3: Handling Text
    • Introduction
    • Simple text
    • Text font type, size, and color
    • Alignment of text – left and right justify
    • All the fonts available on your computer
  • Chapter 4: Animation Principles
    • Introduction
    • Static shifting of a ball
    • Time-controlled shifting of a ball
    • Complete animation using draw-move-pause-erase cycles
    • More than one moving object
    • A ball that bounces
    • Bouncing in a gravity field
    • Precise collisions using floating point numbers
    • Trajectory tracing and ball-to-ball collisions
    • Rotating line
    • Trajectory tracing on multiple line rotations
    • A rose for you
  • Chapter 5: The Magic of Color
    • Introduction
    • A limited palette of named colors
    • Nine ways of specifying color
    • A red beachball of varying hue
    • A red color wedge of graded hue
    • Newton's grand wheel of color mixing
    • The numerical color mixing matching palette
    • The animated graded color wheel
    • Tkinter's own color picker-mixer
  • Chapter 6: Working with Pictures
    • Opening an image file and discovering its attributes
    • Open, view, and save an image in a different file format
    • Image format conversion for JPEG, PNG, TIFF, GIF, BMP
    • Image rotation in the plane of the image
    • Image size alteration
    • Correct proportion image resizing
    • Separating one color band in an image
    • Red, green, and blue color alteration in images
    • Slider controlled color manipulation
    • Combining images by blending
    • Blending images by varying percentages
    • Make a composite image using a mask image
    • Offset (roll) image horizontally and vertically
    • Flip horizontally, vertically, and rotate
    • Filter effects: blur, sharpen, contrast, and so on
  • Chapter 7: Combining Raster and Vector Pictures
    • Simple animation of a GIF beach ball
    • The vector walking creature
    • Bird with shoes walking in the Karroo
    • Making GIF images with transparent backgrounds using GIMP
    • Diplomat walking at the palace
    • Spider in the forest
    • Moving band of images
    • Continuous band of images
    • Endless background
  • Chapter 8: Data In and Data Out
    • Introduction
    • Creation of a new file on a hard drive
    • Writing data to a newly-created file
    • Writing data to multiple files
    • Adding data to existing files
    • Saving a Tkinter-drawing shape to disk
    • Retrieving Python data from disk storage
    • Simple mouse input
    • Storing and retrieving a mouse-drawn shape
    • A mouse-line editor
    • All possible mouse actions
  • Chapter 10: GUI Construction: Part 1
    • Introduction
    • Widget configuration – a label
    • Button focus
    • The simplest push button with validation
    • A data entry box
    • Colored button causing a message pop-up
    • Complex interaction between buttons
    • Images on buttons and button packing
    • Grid Geometry Manager and button arrays
    • Drop-down menus to select from a list
    • Listbox variable selection
    • Text in a window
  • Chapter 11: GUI Construction: Part 2
    • Introduction
    • The Grid Layout Geometry Manager
    • The Pack Geometry Manager
    • Radiobuttons to select one from many
    • Checkbuttons (Tickboxes) to select some of many
    • Key-stroke event handling
    • Scrollbar
    • Custom DIY controller widgets
    • Organizing widgets inside frames

Mike Ohlson de Fine

Mike is a graduate Electrical Engineer specializing in industrial process measurement and control. He has a Diploma in Electronics and Instrumentation from Technikon Witwatersrand, an Electrical Engineering degree from the University of Cape Town, and a Masters in Automatic Control from Rand Afrikaans University. He has worked for mining and mineral extraction companies for the last 30 years. His first encounter with computers was learning Fortran 4 using punched cards on an IBM 360 as an undergraduate. Since then he has experimented with Pascal, Forth, Intel 8080 Assembler, MS Basic, C, and C++ but was never satisfied with any of these. Always restricted by corporate control of computing activities he encountered Linux in 2006 and Python in 2007 and became free at last.

As a working engineer he needs tools that facilitate the understanding and solution of industrial process control problems using simulations and computer models of real processes. Linux and Python proved to be excellent tools for these challenges. When he retires he would like to be part of setting up a Free and Open Source engineering virtual workshop for his countrymen and people in other poor countries to enable the bright youngsters of these countries to be intellectually free at last.

His hobbies are writing computer simulations, paddling kayaks in wild water, and surf skiing in the sea.

Sorry, we don't have any reviews for this title yet.

Code Downloads

Download the code and support files for this book.


Submit Errata

Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.

Sample chapters

You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

Frequently bought together

Python 2.6 Graphics Cookbook +    OCA Oracle Database 11g: Database Administration I: A Real-World Certification Guide =
50% Off
the second eBook
Price for both: $42.30

Buy both these recommended eBooks together and get 50% off the cheapest eBook.

What you will learn from this book

  • Install Python and create basic programs for making lines and shapes
  • Apply different colors to your graphics using widgets and schemes available with the Tkinter module
  • Work with raster images and animate them by combining vector images with raster images
  • Optimize the storage and retrieval of graphics using hard disks, datastreams, and so on
  • Develop GUIs for different purposes to enhance your interaction with the programs
  • Move graphic objects smoothly around a screen by adding minimum delay and shift
  • Explore alternative ways and means of getting graphic shape data into Tkinter programs
  • Create beautiful patterns by setting any number of pivot points in different directions
  • Use trajectory traces to examine the history of execution required for animating specific behavior of objects

In Detail

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.

A quick reference for creating interesting graphic animations using Python programming

Approach

This book has recipes that show enthusiastic users how easy graphic programming can be. Simple explanations in plain English are used. The recipes are built up, in each chapter, starting as simply as possible and moving to more complex programs with which you can comfortably create 2D vector graphics and animations. You will learn how to combine both vector and photo images seamlessly!

Who this book is for

If you are looking to create animated graphics to represent real-world scenarios then this book is for you. Teachers, scholars, students, and engineers who know it is possible to make fascinating models and demonstrations but have not found a handbook that pulls it all together in one place will find what they need in this recipe bank.

Basic knowledge of Python programming is required and access to the Web and Google will be useful.

Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software