Lecture1_Intro_Pycairo_Detailed----.pptx

kamalsmail1 0 views 8 slides Oct 08, 2025
Slide 1
Slide 1 of 8
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8

About This Presentation

Lecture1


Slide Content

Computer Graphics with Pycairo Lecture 1: Introduction to Computer Graphics

Course Overview - Understand fundamentals of 2D computer graphics - Learn vector-based drawing using Pycairo - Explore transformations, colors, paths, and text - Apply knowledge to mini-projects - Export professional graphics for research and publications

What is Computer Graphics? - A branch of computer science focused on creating and manipulating images - Applications include: • Entertainment: movies, video games • User interfaces: desktops, mobile apps • Visualization: scientific data, engineering designs • Education and training simulations

Raster vs. Vector Graphics Raster Graphics: - Image stored as a grid of pixels - Resolution-dependent, quality degrades when zoomed - Formats: PNG, JPEG, BMP Vector Graphics: - Shapes described mathematically using paths and equations - Resolution-independent, scalable without losing quality - Formats: SVG, PDF, EPS Pycairo is a vector graphics library ✅

The Role of Pycairo - Python bindings for the Cairo graphics library - Capabilities: • Drawing lines, curves, shapes • Applying transformations • Rendering text and images • Exporting to PNG, PDF, SVG, PS - Combines power and simplicity for CS students - Useful for technical illustrations, diagrams, and visualization

Pycairo vs Turtle Turtle: - Great for beginners and learning programming basics - Step-by-step cursor-based drawing - Limited to simple educational graphics Pycairo: - Professional-grade vector graphics - High-quality scalable output - Suitable for research projects and publications

First Pycairo Program import cairo WIDTH, HEIGHT = 200, 200 surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT) ctx = cairo.Context(surface) # Draw a circle ctx.arc(100, 100, 80, 0, 2*3.14) ctx.set_source_rgb(0.2, 0.4, 0.6) ctx.fill_preserve() ctx.set_source_rgb(0, 0, 0) ctx.stroke() surface.write_to_png('circle.png')

Example Output - The program generates a circle with blue fill and black outline - The output is saved as 'circle.png' - This demonstrates Pycairo's ability to: • Define shapes mathematically • Apply colors and strokes • Save as high-quality raster images
Tags