I turned this into some freestanding code that can actually be compiled and tested and then noticed that your call to cairo_rectangle() is wrong. The arguments to this functions are:
- x
- y
- width
- height
You are passing in:
- j
- y
- j
- y + 100
So larger values result in larger and larger rectangles being used. I assume you want these arguments instead:
- j
- y
- 1
- 100
For reference, here is my code:
#include <cairo.h>
#include <math.h>
int main(void)
{
int width = 800, height = 800;
int sine[800];
int k;
for (k = 0; k < 800; k++) {
sine[k] = height * sin(k*M_PI/180);
}
/*** Create surface to draw on ***/
cairo_surface_t *cst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
cairo_t *cr = cairo_create(cst);
/*** Draw stuff ***/
static int i = 0;
++i; i = i % 800;
cairo_set_source_rgba (cr, .0, .0, .0, 1);
cairo_paint(cr);
int j = 0;
for (j = 0; j < 799; ++j)
{
double y = (double)(height + sine[j]) / 2;
cairo_pattern_t *pat1;
pat1 = cairo_pattern_create_linear(j, y, j, y + 100);
cairo_pattern_add_color_stop_rgba(pat1, 0.1, 0, 1, 0, 1);
cairo_pattern_add_color_stop_rgba(pat1, 0.9, 0, 1, 0, 0.2);
cairo_rectangle(cr, j, y, 1, 100);
cairo_set_source(cr, pat1);
cairo_fill(cr);
cairo_pattern_destroy(pat1);
}
cairo_destroy(cr);
cairo_surface_write_to_png(cst, "t.png");
cairo_surface_destroy(cst);
return 0;
}