Python informer

Improve your Python coding skills

Bezier curves in Pycairo

This article is part of a series on Pycairo. This article describes how to draw Bezier curves in Pycairo. What is a Bezier curve? A Bezier curve is a versatile mathematical curve that can be used to create a wide variety of different shapes in vector graphics. The curve is controlled by 4 points, A, B, C and D: The curve starts at point A and ends at point D. Read more →

Transforms in Pycairo - rotate

This article is part of a series on Pycairo. We have previously seen how to use translate and scale in Pycairo, to draw items in different positions on the page. In this article we will see how to use rotation to draw items at different angles. Default user space Here is our initial square in default user space, with no transform applied. ctx.rectangle(300, 100, 100, 100) ctx.set_source_rgb(0, 0, 1) ctx. Read more →

Transforms in Pycairo - scale

This article is part of a series on Pycairo. We have previously seen how to use translate in Pycairo, to draw items in different positions on the page. In this article we will see how to use scaling to draw items at different sizes. Default user space We will start once again by drawing a shape in default user space, with no transform applied. ctx.rectangle(0, 0, 100, 100) ctx.set_source_rgb(0, 0, 1) ctx. Read more →

Transforms in Pycairo - translate

This article is part of a series on Pycairo. As we have seen in earlier examples, Pycairo uses a coordinate system to create images. In this section we will look at how we can use transforms to make this system more flexible. We will see how to apply: Translation, to move items around the page (this article). Scaling, to change the size of items. Rotation, to change the orientation of items. Read more →

Basic drawing in Pycairo

This article is part of a series on Pycairo. In this article we will learn how the basics of drawing in Pycairo. We will also look at how to set the scale your drawing. It is assumed that you have already installed Pycairo on your system. Making an image with Pycairo There are 4 basic steps to creating an image: Create a Pycairo surface to hold your drawing Create a Pycairo context that you use to draw with Draw your shapes using the methods of the context object Save the surface to file Here is how we create a surface: Read more →

Displaying text in Pycairo

This article is part of a series on Pycairo. This article describes how to create text in Pycairo. You can find other topics in the main Pycairo article list. Drawing a simple text string Here is the code to create a simple text string in our user coordinates (see the previous article). The full code is here: import cairo WIDTH = 3 HEIGHT = 2 PIXEL_SCALE = 200 surface = cairo. Read more →

Drawing shapes in Pycairo

This article is part of a series on Pycairo. In a previous article we learnt how to draw a rectangle in Pycairo. Here we cover other simple shapes. Paths The way Pycairo draws is to first define a path and then draw it by either filling or outlining the path (or both). In the previous article we just used the rectangle function to create a single rectangle. But in fact paths can be more complex that that. Read more →

Introduction to Pycairo

This article is part of a series on Pycairo. Pycairo is a Python vector graphics library. You can use it to draw basic lines and shapes such as rectangles, circles, bezier curves and so on, and combine them to create more complex drawings, charts and diagrams. It also supports more advanced options such as pattern fills, transparency and clipping. It can output images in bitmap format (PNG) or vector format (SVG). Read more →

Pycairo contents

This Pycairo tutorial includes: Introduction Basic drawing in Pycairo Shapes in Pycairo Text in Pycairo Bezier curves Transforms - translation Transforms - scaling See also If you found this article useful you might be interested in my ebook Computer Graphics in Python. Read more →