diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2011-10-10 12:13:51 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2011-10-10 12:13:51 +0100 |
commit | 6576311be7a961e60303fcafe9a7fc926382fd4b (patch) | |
tree | ec394ae66c52118690b49d23e5920dff44b113fb | |
parent | daa0c1ab17207f56bd662df9e046eb1cc1617bc7 (diff) |
fish: Fix the position of and make the reflection more pronounced
-rw-r--r-- | fish-demo.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/fish-demo.c b/fish-demo.c index 55f5875..358a385 100644 --- a/fish-demo.c +++ b/fish-demo.c @@ -26,7 +26,7 @@ static cairo_pattern_t *create_background(struct device *device, int *x1, int *x height = cairo_image_surface_get_height(image); width = cairo_image_surface_get_width(image); - sf = height/ (double)device->height; + sf = height / (double)device->height; surface = cairo_surface_create_similar(device->scanout, CAIRO_CONTENT_COLOR, @@ -40,12 +40,14 @@ static cairo_pattern_t *create_background(struct device *device, int *x1, int *x pattern = cairo_pattern_create_for_surface(cairo_get_target(cr)); cairo_destroy (cr); + *x1 = (device->width - width / sf) / 2; + *x2 = device->width - *x1; + cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REFLECT); cairo_matrix_init_scale(&m, sf,sf); + cairo_matrix_translate(&m, -*x1, 0); cairo_pattern_set_matrix(pattern, &m); - *x1 = (device->width - width * sf) / 2; - *x2 = device->width - *x1; return pattern; } @@ -95,7 +97,7 @@ static void fish_init(struct device *device, struct fish *f, int x1, int x2) int w = x2 - x1; f->x = random() % (w - fish_width) + x1; - f->y = random() % device->height; + f->y = random() % (device->height - fish_height); f->z = 0; f->dx = random() % 5 + 1; @@ -189,13 +191,15 @@ int main (int argc, char **argv) if (cairo_pattern_status(bg)) return 1; - if (reflection == NULL) { + if (reflection == NULL || x1 < 0) { x1 = 0, x2 = device->width; } else { reflection = cairo_pattern_create_linear(0,0, device->width, 0); cairo_pattern_add_color_stop_rgba(reflection, 0, 0, 0, 0, 0); + cairo_pattern_add_color_stop_rgba(reflection, x1/(double)device->width, 0, 0, 0, .75); cairo_pattern_add_color_stop_rgba(reflection, x1/(double)device->width, 0, 0, 0, 1); cairo_pattern_add_color_stop_rgba(reflection, x2/(double)device->width, 0, 0, 0, 1); + cairo_pattern_add_color_stop_rgba(reflection, x2/(double)device->width, 0, 0, 0, .75); cairo_pattern_add_color_stop_rgba(reflection, 1, 0, 0, 0, 0); } |