Skip to content

kuriofoolio/CairoPlayground

Repository files navigation

CairoPlayground: Experimentation with PyCairo

Getting Started with PyCairo

This guide will help you get started with PyCairo, a Python library for creating 2D vector graphics. PyCairo allows you to create beautiful graphics, illustrations, and charts in your Python applications.

Prerequisites

Before you begin, make sure you have the following prerequisites:

  • Python installed on your system.

  • PyCairo library installed. You can install it using pip:

    pip install pycairo
    
    

Using PyCairo

  1. Import PyCairo In your Python script, import the PyCairo library:
import cairo
  1. Create a Cairo Context
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
context = cairo.Context(surface)
  1. Drawing Shapes
context.rectangle(x, y, width, height)
context.set_source_rgb(0.5, 0.5, 1)  # Set the fill color
context.fill()
  1. Saving the Image
surface.write_to_png("output.png")