… | |
… | |
99 | its result becomes the argument to the C<scale> function. |
99 | its result becomes the argument to the C<scale> function. |
100 | |
100 | |
101 | Many operators also allow some parameters preceding the input image |
101 | Many operators also allow some parameters preceding the input image |
102 | that modify its behaviour. For example, C<scale> without any additional |
102 | that modify its behaviour. For example, C<scale> without any additional |
103 | arguments scales the image to size of the terminal window. If you specify |
103 | arguments scales the image to size of the terminal window. If you specify |
104 | an additional argument, it uses it as a percentage: |
104 | an additional argument, it uses it as a scale factor (multiply by 100 to |
|
|
105 | get a percentage): |
105 | |
106 | |
106 | scale 200, load "$HOME/mypic.png" |
107 | scale 2, load "$HOME/mypic.png" |
107 | |
108 | |
108 | This enlarges the image by a factor of 2 (200%). As you can see, C<scale> |
109 | This enlarges the image by a factor of 2 (200%). As you can see, C<scale> |
109 | has now two arguments, the C<200> and the C<load> expression, while |
110 | has now two arguments, the C<200> and the C<load> expression, while |
110 | C<load> only has one argument. Arguments are separated from each other by |
111 | C<load> only has one argument. Arguments are separated from each other by |
111 | commas. |
112 | commas. |
112 | |
113 | |
113 | Scale also accepts two arguments, which are then separate factors for both |
114 | Scale also accepts two arguments, which are then separate factors for both |
114 | horizontal and vertical dimensions. For example, this halves the image |
115 | horizontal and vertical dimensions. For example, this halves the image |
115 | width and doubles the image height: |
116 | width and doubles the image height: |
116 | |
117 | |
117 | scale 50, 200, load "$HOME/mypic.png" |
118 | scale 0.5, 2, load "$HOME/mypic.png" |
118 | |
119 | |
119 | Other effects than scalign are also readily available, for exmaple, you can |
120 | Other effects than scalign are also readily available, for exmaple, you can |
120 | tile the image to fill the whole window, instead of resizing it: |
121 | tile the image to fill the whole window, instead of resizing it: |
121 | |
122 | |
122 | tile load "$HOME/mypic.png" |
123 | tile load "$HOME/mypic.png" |
… | |
… | |
201 | # enforce at least this interval between updates |
202 | # enforce at least this interval between updates |
202 | our $MIN_INTERVAL = 1/100; |
203 | our $MIN_INTERVAL = 1/100; |
203 | |
204 | |
204 | { |
205 | { |
205 | package urxvt::bgdsl; # background language |
206 | package urxvt::bgdsl; # background language |
|
|
207 | |
|
|
208 | use List::Util qw(min max sum shuffle); |
206 | |
209 | |
207 | =head2 PROVIDERS/GENERATORS |
210 | =head2 PROVIDERS/GENERATORS |
208 | |
211 | |
209 | These functions provide an image, by loading it from disk, grabbing it |
212 | These functions provide an image, by loading it from disk, grabbing it |
210 | from the root screen or by simply generating it. They are used as starting |
213 | from the root screen or by simply generating it. They are used as starting |
… | |
… | |
479 | $img->sub_rect ($_[0], $_[1], $w, $h) |
482 | $img->sub_rect ($_[0], $_[1], $w, $h) |
480 | } |
483 | } |
481 | |
484 | |
482 | =item scale $img |
485 | =item scale $img |
483 | |
486 | |
484 | =item scale $size_percent, $img |
487 | =item scale $size_factor, $img |
485 | |
488 | |
486 | =item scale $width_percent, $height_percent, $img |
489 | =item scale $width_factor, $height_factor, $img |
487 | |
490 | |
488 | Scales the image by the given percentages in horizontal |
491 | Scales the image by the given factors in horizontal |
489 | (C<$width_percent>) and vertical (C<$height_percent>) direction. |
492 | (C<$width>) and vertical (C<$height>) direction. |
490 | |
493 | |
491 | If only one percentage is give, it is used for both directions. |
494 | If only one factor is give, it is used for both directions. |
492 | |
495 | |
493 | If no percentages are given, scales the image to the window size without |
496 | If no factors are given, scales the image to the window size without |
494 | keeping aspect. |
497 | keeping aspect. |
495 | |
498 | |
496 | =item resize $width, $height, $img |
499 | =item resize $width, $height, $img |
497 | |
500 | |
498 | Resizes the image to exactly C<$width> times C<$height> pixels. |
501 | Resizes the image to exactly C<$width> times C<$height> pixels. |
499 | |
502 | |
500 | =cut |
503 | =item fit $img |
501 | |
504 | |
502 | #TODO: maximise, maximise_fill? |
505 | =item fit $width, $height, $img |
|
|
506 | |
|
|
507 | Fits the image into the given C<$width> and C<$height> without changing |
|
|
508 | aspect, or the terminal size. That means it will be shrunk or grown until |
|
|
509 | the whole image fits into the given area, possibly leaving borders. |
|
|
510 | |
|
|
511 | =item cover $img |
|
|
512 | |
|
|
513 | =item cover $width, $height, $img |
|
|
514 | |
|
|
515 | Similar to C<fit>, but shrinks or grows until all of the area is covered |
|
|
516 | by the image, so instead of potentially leaving borders, it will cut off |
|
|
517 | image data that doesn't fit. |
|
|
518 | |
|
|
519 | =cut |
503 | |
520 | |
504 | sub scale($;$;$) { |
521 | sub scale($;$;$) { |
505 | my $img = pop; |
522 | my $img = pop; |
506 | |
523 | |
507 | @_ == 2 ? $img->scale ($_[0] * $img->w * 0.01, $_[1] * $img->h * 0.01) |
524 | @_ == 2 ? $img->scale ($_[0] * $img->w, $_[1] * $img->h) |
508 | : @_ ? $img->scale ($_[0] * $img->w * 0.01, $_[0] * $img->h * 0.01) |
525 | : @_ ? $img->scale ($_[0] * $img->w, $_[0] * $img->h) |
509 | : $img->scale (TW, TH) |
526 | : $img->scale (TW, TH) |
510 | } |
527 | } |
511 | |
528 | |
512 | sub resize($$$) { |
529 | sub resize($$$) { |
513 | my $img = pop; |
530 | my $img = pop; |
514 | $img->scale ($_[0], $_[1]) |
531 | $img->scale ($_[0], $_[1]) |
|
|
532 | } |
|
|
533 | |
|
|
534 | sub fit($;$$) { |
|
|
535 | my $img = pop; |
|
|
536 | my $w = ($_[0] || TW) / $img->w; |
|
|
537 | my $h = ($_[1] || TH) / $img->h; |
|
|
538 | scale +(min $w, $h), $img |
|
|
539 | } |
|
|
540 | |
|
|
541 | sub cover($;$$) { |
|
|
542 | my $img = pop; |
|
|
543 | my $w = ($_[0] || TW) / $img->w; |
|
|
544 | my $h = ($_[1] || TH) / $img->h; |
|
|
545 | scale +(max $w, $h), $img |
515 | } |
546 | } |
516 | |
547 | |
517 | =item move $dx, $dy, $img |
548 | =item move $dx, $dy, $img |
518 | |
549 | |
519 | Moves the image by C<$dx> pixels in the horizontal, and C<$dy> pixels in |
550 | Moves the image by C<$dx> pixels in the horizontal, and C<$dy> pixels in |
… | |
… | |
615 | } |
646 | } |
616 | |
647 | |
617 | =item rotate $new_width, $new_height, $center_x, $center_y, $degrees |
648 | =item rotate $new_width, $new_height, $center_x, $center_y, $degrees |
618 | |
649 | |
619 | Rotates the image by C<$degrees> degrees, counter-clockwise, around the |
650 | Rotates the image by C<$degrees> degrees, counter-clockwise, around the |
620 | pointer at C<$center_x> and C<$center_y> (specified as percentage of image |
651 | pointer at C<$center_x> and C<$center_y> (specified as factor of image |
621 | width/height), generating a new image with width C<$new_width> and height |
652 | width/height), generating a new image with width C<$new_width> and height |
622 | C<$new_height>. |
653 | C<$new_height>. |
623 | |
654 | |
624 | #TODO# new width, height, maybe more operators? |
655 | #TODO# new width, height, maybe more operators? |
625 | |
656 | |
… | |
… | |
630 | sub rotate($$$$$$) { |
661 | sub rotate($$$$$$) { |
631 | my $img = pop; |
662 | my $img = pop; |
632 | $img->rotate ( |
663 | $img->rotate ( |
633 | $_[0], |
664 | $_[0], |
634 | $_[1], |
665 | $_[1], |
635 | $_[2] * $img->w * .01, |
666 | $_[2] * $img->w, |
636 | $_[3] * $img->h * .01, |
667 | $_[3] * $img->h, |
637 | $_[4] * (3.14159265 / 180), |
668 | $_[4] * (3.14159265 / 180), |
638 | ) |
669 | ) |
639 | } |
670 | } |
640 | |
671 | |
641 | =back |
672 | =back |