PyCairo – Drawing Bezier curve
Last Updated :
23 Jan, 2022
In this article we will learn how we can draw a simple bezier curve using PyCairo in python. A Bezier curve is a versatile mathematical curve that can be used to create a wide variety of different shapes in vector graphics.
PyCairo : Pycairo is a Python module providing bindings for the cairo graphics library.This library is used for creating SVG i.e vector files in python. The easiest and quickest way to open an SVG file to view it (read only) is with a modern web browser like Chrome, Firefox, Edge, or Internet Explorer—nearly all of them should provide some sort of rendering support for the SVG format.
SVG file is a graphics file that uses a two-dimensional vector graphic format created by the World Wide Web Consortium (W3C). It describes images using a text format that is based on XML. SVG files are developed as a standard format for displaying vector graphics on the web.
Steps of Implementation :
- Import the Pycairo module.
- Create a SVG surface object and add context to it.
- Creating curve using curve_to ( )
- Setting context color and width
Below is the Implementation :
Python3
import cairo
with cairo.SVGSurface( "geek95.svg" , 700 , 700 ) as surface:
context = cairo.Context(surface)
context.move_to( 50 , 200 )
context.curve_to( 150 , 75 , 225 , 50 , 350 , 150 )
context.set_source_rgb( 1 , 0 , 0 )
context.set_line_width( 4 )
context.stroke()
print ( "File Saved" )
|
Output :
Share your thoughts in the comments
Please Login to comment...