PyCairo – Drawing negative arc
In this article we will learn how we can draw a simple negative arc using PyCairo in python. Adds a circular arc of the given radius to the current path. The arc is centered at (xc, yc), begins at angle1 and proceeds in the direction of decreasing angles to end at angle2. If the angle2 is greater than angle1 it will be progressively decreased by 2Ï€ until it is less than angle1.
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 negative arc using arc_negative().
Below is the Implementation :
Python3
import cairo
with cairo.SVGSurface( "geek1.svg" , 700 , 700 ) as surface:
context = cairo.Context(surface)
context.arc( 100 , 60 , 40 , 0 , 1 * 22 / 7 )
context.stroke()
context.arc_negative( 500 , 60 , 40 , 0 , 1 * 22 / 7 )
context.stroke()
print ( "File Saved" )
|
Output:
Last Updated :
12 Nov, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...