Код: Выделить всё
/* carbon.c */
#include <cairo.h>
#define WEIGHT 1366 // ширина обоев
#define HEIGHT 768 // высота обоев
#define CELL_SIDE_SIZE 3 // размер стороны ячкйки
static void draw_cell(cairo_t *, int x_pos, int y_pos);
static void draw_shadow(cairo_t *);
int main(void)
{
cairo_surface_t *surface;
cairo_t *cr;
int x = 0;
int y = 0;
int i = 0;
surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, WEIGHT, HEIGHT);
cr = cairo_create(surface);
cairo_set_source_rgb(cr, 0.1, 0.1, 0.1);
cairo_rectangle(cr, 0, 0, WEIGHT, HEIGHT);
cairo_fill (cr);
while (y < HEIGHT) {
while (x < WEIGHT) {
draw_cell(cr, x, y);
x += (CELL_SIDE_SIZE * 2);
}
y += CELL_SIDE_SIZE;
i += 1;
if (( i % 2 )) {
x = CELL_SIDE_SIZE;
} else {
x = 0;
}
}
draw_shadow(cr);
cairo_surface_write_to_png(surface, "carbon.png");
cairo_destroy(cr);
cairo_surface_destroy(surface);
return 0;
}
static void draw_cell(cairo_t *cr, int x_pos, int y_pos)
{
cairo_pattern_t *pat;
pat = cairo_pattern_create_linear(x_pos, y_pos, x_pos, (y_pos + CELL_SIDE_SIZE));
cairo_pattern_add_color_stop_rgb(pat, 0.9, 0.5, 0.5, 0.5);
cairo_pattern_add_color_stop_rgb(pat, 0.1, 0.2, 0.2, 0.2);
cairo_rectangle(cr, x_pos, y_pos, CELL_SIDE_SIZE, CELL_SIDE_SIZE);
cairo_set_source(cr, pat);
cairo_fill(cr);
cairo_pattern_destroy(pat);
}
static void draw_shadow(cairo_t *cr)
{
cairo_pattern_t *pat;
pat = cairo_pattern_create_linear(0, 0, 0, HEIGHT);
cairo_pattern_add_color_stop_rgba(pat, 0.7, 0, 0, 0, 0);
cairo_pattern_add_color_stop_rgba(pat, 0.3, 0, 0, 0, 0.3);
cairo_rectangle(cr, 0, 0, WEIGHT, HEIGHT);
cairo_set_source(cr, pat);
cairo_fill(cr);
cairo_pattern_destroy(pat);
}