Python informer

Improve your Python coding skills

Basic drawing in 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 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.ImageSurface(cairo.FORMAT_RGB24, WIDTH*PIXEL_SCALE, HEIGHT*PIXEL_SCALE) ctx = cairo.Context(surface) ctx.scale(PIXEL_SCALE, PIXEL_SCALE) ctx. Read more →

Drawing shapes in 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. A path can consist of connected lines and curves that create a more complex shape. Read more →

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). Basic drawing in pycairo Shapes in pycairo Text in pycairo Read more →