Using C language Cairo graphics Library to draw the example tutorial of Taiji _c language

Source: Internet
Author: User
Tags cairo

Objective

Many people may be directly in the C language drawing still stay in the graphics.h of Turbo C, perhaps there is the reason for the aging of education, after all, the classics have already become the past, rather than try to find their compatible graphics library, as a way to embrace the brilliant tomorrow. Cario (http://cairographics.org/) is a very good 2D graphics library, the famous gtk+3.0 completely adopt Cario as the drawing engine, this shows its strong and attractive.

Cario supports a wide range of output devices such as x window,quartz,win32,image.buffers,postscript,pdf and SVG files, open source and Cross-platform. Some people may feel that such a powerful thing will be very difficult to use, but in fact, it provides an unexpected simple API function, this article is here to illustrate a drawing of the example of the Taiji, for your reference.

The instance code is as follows:

#include <cairo.h> #define SIZE (640)/* Taiji Size * * #define CX (SIZE/2)/* Taiji Round Center Horizontal axis/#define CY (SIZE/2)  * Taiji Circle Center Ordinate/#define R (SIZE/2)/* Taiji Circle RADIUS///* Convert angle to the corresponding Radian/* #define ANGLE (ANG) (ANG * 3.1415926/180.0) int Main (int argc, char *argv[]) {* * Create a 32-bit RGBA color format Cairo mapping environment, rendering directly in memory/cairo_surface_t* surface = Cairo_image_sur 
 Face_create (cairo_format_argb32, size + 1, size + 1); 
 
 cairo_t* cr = Cairo_create (surface); 
 * * Draw Taiji Border/Cairo_set_line_width (CR, 2.0); 
 Cairo_set_source_rgba (CR, 0, 0, 0, 1); 
 Cairo_arc (CR, CX, CY, R, ANGLE (0), ANGLE (360)); 
 
 Cairo_stroke (CR); 
 * * Draw Yin and yang circle * * * * CAIRO_SET_SOURCE_RGBA (CR, 0, 0, 0, 1); 
 Cairo_arc (CR, CX, CY, R, ANGLE (), ANGLE (270)); 
 Cairo_fill (CR); 
 Cairo_set_source_rgba (CR, 1, 1, 1, 1); 
 Cairo_arc (CR, CX, CY, R, ANGLE ( -90), ANGLE (90)); 
 
 Cairo_fill (CR); 
 * * Draw Yin-yang Line * * Cairo_set_source_rgba (CR, 0, 0, 0, 1); 
 Cairo_arc (CR, CX, Cy-r/2, R/2, ANGLE ( -90), ANGLE (90)); 
 Cairo_fill (CR); CairO_set_source_rgba (CR, 1, 1, 1, 1); 
 Cairo_arc (CR, CX, CY + R/2, R/2, ANGLE (), ANGLE (270)); 
 
 Cairo_fill (CR); 
 * * Draw Taiji Eye * * * * CAIRO_SET_SOURCE_RGBA (CR, 1, 1, 1, 1); 
 Cairo_arc (CR, CX, Cy-r/2, R/10, ANGLE (0), ANGLE (360)); 
 Cairo_fill (CR); 
 Cairo_set_source_rgba (CR, 0, 0, 0, 1); 
 Cairo_arc (CR, CX, CY + R/2, R/10, ANGLE (0), ANGLE (360)); 
 
 Cairo_fill (CR); 
 * * To store the memory rendering effect in the picture * * * cairo_surface_write_to_png (surface, "taichi.png"); 
 /* Destroy and Exit Cairo drawing Environment * * Cairo_destroy (CR); 
 
 Cairo_surface_destroy (surface); 
return 0;  }

The code is very simple, to use this, hope that more people will like the Cario graphics library. If GCC compiles, you can refer to the following commands.

 
 

After the operation of the effect is like this, we can try.

Summarize

The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring certain help, if you have questions you can message exchange.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.