Chapter 2. Drawing Fundamental Shapes

In this chapter, we will cover:

  • A straight line and the coordinate system
  • Drawing 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 stored shapes - the curly vine
  • Drawing a rectangle
  • Drawing overlapping rectangles
  • Drawing concentric squares
  • A circle from an oval
  • A circle from an arc
  • Three ellipses
  • The simplest polygon
  • A star polygon
  • The art of cloning stars

Introduction

Graphics are all about pictures and drawings. In computer programs, a line is not drawn by a hand, holding a pencil, but by the manipulation of numbers on a screen. This chapter provides the fine-grained detail or atomic structure for the rest of the book. Here we lay down the most basic graphic building blocks in their simplest form. The most useful options are presented inside self-contained programs. You can if you want, use the code without understanding in detail how it works. You can learn by doing. You can learn by playing and play is the serious work that unskilled animals do in order to learn almost everything they need for survival.

You can cut and paste the code and it should just work without modification. The code is easily modified and you are encouraged to tinker with it and tweak the parameters inside the drawing methods. The more you tinker with it, the more you will understand.

The area of screen where lines and shapes are drawn is the canvas in Python. It is created when the Tkinter method canvas() is executed.

Central to using numbers to describe lines and shapes is a coordinate system that says where a line or shape starts and where it ends. In Tkinter, as in most computer graphic systems, the top-left is the start of the screen or canvas and bottom-right is the end where the largest numbers describe location. This system is shown in the next figure, which is the universal computer screen coordinate system.

Introduction
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.31.165